Search in sources :

Example 16 with ConnectionException

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

the class HpackParserImpl method validateHeader.

private void validateHeader(UnmarshalStateImpl state, HasHeaderFragment lowLevelFrame) {
    List<HasHeaderFragment> list = state.getHeadersToCombine();
    HasHeaderFragment first = list.get(0);
    int streamId = first.getStreamId();
    if (first instanceof PushPromiseFrame) {
        PushPromiseFrame f = (PushPromiseFrame) first;
        streamId = f.getPromisedStreamId();
    }
    String logId = state.getLogId();
    if (list.size() == 1) {
        if (!(first instanceof HeadersFrame) && !(first instanceof PushPromiseFrame))
            throw new ConnectionException(CancelReasonCode.HEADERS_MIXED_WITH_FRAMES, logId, lowLevelFrame.getStreamId(), "First has header frame must be HeadersFrame or PushPromiseFrame first frame=" + first);
    } else if (streamId != lowLevelFrame.getStreamId()) {
        throw new ConnectionException(CancelReasonCode.HEADERS_MIXED_WITH_FRAMES, logId, lowLevelFrame.getStreamId(), "Headers/continuations from two different streams per spec cannot be" + " interleaved.  frames=" + list);
    } else if (!(lowLevelFrame instanceof ContinuationFrame)) {
        throw new ConnectionException(CancelReasonCode.HEADERS_MIXED_WITH_FRAMES, logId, lowLevelFrame.getStreamId(), "Must be continuation frame and wasn't.  frames=" + list);
    }
}
Also used : HasHeaderFragment(com.webpieces.http2parser.api.dto.lib.HasHeaderFragment) ContinuationFrame(com.webpieces.http2parser.api.dto.ContinuationFrame) PushPromiseFrame(com.webpieces.http2parser.api.dto.PushPromiseFrame) HeadersFrame(com.webpieces.http2parser.api.dto.HeadersFrame) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 17 with ConnectionException

use of com.webpieces.http2parser.api.dto.error.ConnectionException 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)

Example 18 with ConnectionException

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

the class HeaderDecoding method decodeImpl.

private List<Http2Header> decodeImpl(UnmarshalStateImpl state, DataWrapper data, int streamId, Consumer<Http2Header> knownHeaders) throws IOException {
    List<Http2Header> headers = new ArrayList<>();
    byte[] bytes = data.createByteArray();
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    Decoder decoder = state.getDecoder();
    //TODO(dhiller): make this an async syncrhonized block instead so threads can keep running!!!
    synchronized (decoder) {
        decoder.decode(in, (n, v, s) -> addToHeaders(headers, knownHeaders, n, v, s, state.getLogId(), streamId));
        decoder.endHeaderBlock();
    }
    if (data.getReadableSize() > 0 && headers.size() == 0)
        throw new ConnectionException(CancelReasonCode.COMPRESSION_ERROR, state.getLogId(), streamId, "Header data came in, but no headers came out");
    return headers;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) ArrayList(java.util.ArrayList) Decoder(com.twitter.hpack.Decoder) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 19 with ConnectionException

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

the class DataMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    DataFrame frame = new DataFrame();
    super.unmarshalFrame(state, frame);
    byte flags = state.getFrameHeaderData().getFlagsByte();
    frame.setEndOfStream((flags & 0x1) == 0x1);
    boolean isPadded = (flags & 0x8) == 0x8;
    DataSplit split = PaddingUtil.extractPayloadAndPadding(isPadded, framePayloadData, frame.getStreamId());
    frame.setData(split.getPayload());
    frame.setPadding(split.getPadding());
    if (frame.getStreamId() == 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "headers frame had invalid stream id=" + frame.getStreamId());
    return frame;
}
Also used : DataFrame(com.webpieces.http2parser.api.dto.DataFrame) DataSplit(com.webpieces.http2parser.impl.DataSplit) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 20 with ConnectionException

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

the class DataMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    DataFrame castFrame = (DataFrame) frame;
    int paddingSize = castFrame.getPadding().getReadableSize();
    if (frame.getStreamId() == 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "data frame had invalid stream id=" + frame.getStreamId());
    byte value = (byte) 0x0;
    if (castFrame.isEndOfStream())
        value |= 0x1;
    if (paddingSize > 0)
        value |= 0x8;
    DataWrapper dataPayload = PaddingUtil.padDataIfNeeded(castFrame.getData(), castFrame.getPadding());
    return super.marshalFrame(frame, value, dataPayload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Aggregations

ConnectionException (com.webpieces.http2parser.api.dto.error.ConnectionException)24 ByteBuffer (java.nio.ByteBuffer)8 FrameHeaderData (com.webpieces.http2parser.impl.FrameHeaderData)5 DataWrapper (org.webpieces.data.api.DataWrapper)5 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)4 StreamException (com.webpieces.http2parser.api.dto.error.StreamException)4 HeadersFrame (com.webpieces.http2parser.api.dto.HeadersFrame)3 PriorityDetails (com.webpieces.http2parser.api.dto.lib.PriorityDetails)3 DataSplit (com.webpieces.http2parser.impl.DataSplit)3 DataTry (com.webpieces.http2engine.impl.DataTry)2 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)2 PingFrame (com.webpieces.http2parser.api.dto.PingFrame)2 PriorityFrame (com.webpieces.http2parser.api.dto.PriorityFrame)2 PushPromiseFrame (com.webpieces.http2parser.api.dto.PushPromiseFrame)2 RstStreamFrame (com.webpieces.http2parser.api.dto.RstStreamFrame)2 SettingsFrame (com.webpieces.http2parser.api.dto.SettingsFrame)2 UnknownFrame (com.webpieces.http2parser.api.dto.UnknownFrame)2 WindowUpdateFrame (com.webpieces.http2parser.api.dto.WindowUpdateFrame)2 HasHeaderFragment (com.webpieces.http2parser.api.dto.lib.HasHeaderFragment)2 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)2