Search in sources :

Example 1 with UnknownFrame

use of com.webpieces.http2parser.api.dto.UnknownFrame in project webpieces by deanhiller.

the class Http2ParserImpl method parseBody.

private boolean parseBody(Http2MementoImpl state) {
    DataWrapper allData = state.getLeftOverData();
    FrameHeaderData headerData = state.getFrameHeaderData();
    if (headerData == null)
        throw new IllegalArgumentException("Bug, this should never be null at this point");
    int payloadLen = headerData.getPayloadLength();
    if (allData.getReadableSize() < payloadLen)
        return false;
    List<? extends DataWrapper> split = dataGen.split(allData, payloadLen);
    DataWrapper framePayloadData = split.get(0);
    AbstractHttp2Frame frame;
    Optional<Http2FrameType> optFrameType = Http2FrameType.fromId(headerData.getFrameTypeId());
    if (optFrameType.isPresent()) {
        Http2FrameType frameType = optFrameType.get();
        FrameMarshaller marshaller = dtoToMarshaller.get(frameType);
        if (marshaller == null)
            throw new IllegalArgumentException("bug, our developer forgot to add marshaller and only added the enum=" + frameType);
        frame = marshaller.unmarshal(state, framePayloadData);
    } else {
        frame = new UnknownFrame(headerData.getFlagsByte(), headerData.getFrameTypeId(), headerData.getStreamId(), framePayloadData);
    }
    //reset header data
    state.setFrameHeaderData(null);
    //set leftover data
    state.setLeftOverData(split.get(1));
    state.addParsedFrame(frame);
    return true;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) UnknownFrame(com.webpieces.http2parser.api.dto.UnknownFrame) FrameMarshaller(com.webpieces.http2parser.impl.marshallers.FrameMarshaller) Http2FrameType(com.webpieces.http2parser.api.dto.lib.Http2FrameType) AbstractHttp2Frame(com.webpieces.http2parser.api.dto.lib.AbstractHttp2Frame)

Example 2 with UnknownFrame

use of com.webpieces.http2parser.api.dto.UnknownFrame in project webpieces by deanhiller.

the class HpackParserImpl method processFrame.

private void processFrame(UnmarshalStateImpl state, Http2Frame frame) {
    List<HasHeaderFragment> headerFragList = state.getHeadersToCombine();
    if (frame instanceof HasHeaderFragment) {
        HasHeaderFragment headerFrame = (HasHeaderFragment) frame;
        headerFragList.add(headerFrame);
        validateHeader(state, headerFrame);
        if (headerFrame.isEndHeaders())
            combineAndSendHeadersToClient(state);
        return;
    } else if (headerFragList.size() > 0) {
        throw new ConnectionException(CancelReasonCode.HEADERS_MIXED_WITH_FRAMES, state.getLogId(), frame.getStreamId(), "Parser in the middle of accepting headers(spec " + "doesn't allow frames between header fragments).  frame=" + frame + " list=" + headerFragList);
    }
    if (frame instanceof UnknownFrame && ignoreUnkownFrames) {
    //do nothing
    } else if (frame instanceof Http2Msg) {
        state.getParsedFrames().add((Http2Msg) frame);
    } else {
        throw new IllegalStateException("bug forgot support for frame=" + frame);
    }
}
Also used : HasHeaderFragment(com.webpieces.http2parser.api.dto.lib.HasHeaderFragment) UnknownFrame(com.webpieces.http2parser.api.dto.UnknownFrame) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Aggregations

UnknownFrame (com.webpieces.http2parser.api.dto.UnknownFrame)2 ConnectionException (com.webpieces.http2parser.api.dto.error.ConnectionException)1 AbstractHttp2Frame (com.webpieces.http2parser.api.dto.lib.AbstractHttp2Frame)1 HasHeaderFragment (com.webpieces.http2parser.api.dto.lib.HasHeaderFragment)1 Http2FrameType (com.webpieces.http2parser.api.dto.lib.Http2FrameType)1 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)1 FrameMarshaller (com.webpieces.http2parser.impl.marshallers.FrameMarshaller)1 DataWrapper (org.webpieces.data.api.DataWrapper)1