Search in sources :

Example 26 with ConnectionException

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

the class PushPromiseMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    PushPromiseFrame frame = new PushPromiseFrame();
    super.unmarshalFrame(state, frame);
    if (frame.getStreamId() == 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "pushpromise frame had invalid stream id=" + frame.getStreamId());
    byte flags = state.getFrameHeaderData().getFlagsByte();
    frame.setEndHeaders((flags & 0x4) == 0x4);
    boolean isPadded = (flags & 0x8) == 0x8;
    List<? extends DataWrapper> split = DATA_GEN.split(framePayloadData, 4);
    ByteBuffer prelude = bufferPool.createWithDataWrapper(split.get(0));
    DataSplit padSplit = PaddingUtil.extractPayloadAndPadding(isPadded, split.get(1), frame.getStreamId());
    frame.setHeaderFragment(padSplit.getPayload());
    frame.setPadding(padSplit.getPadding());
    frame.setPromisedStreamId(prelude.getInt());
    bufferPool.releaseBuffer(prelude);
    return frame;
}
Also used : PushPromiseFrame(com.webpieces.http2.api.dto.lowlevel.PushPromiseFrame) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException) DataSplit(com.webpieces.http2parser.impl.DataSplit)

Example 27 with ConnectionException

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

the class HpackParserImpl method processFrameImpl.

private void processFrameImpl(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.addParsedMessage((Http2Msg) frame);
    } else {
        throw new IllegalStateException("bug forgot support for frame=" + frame);
    }
}
Also used : HasHeaderFragment(com.webpieces.http2.api.dto.lowlevel.lib.HasHeaderFragment) UnknownFrame(com.webpieces.http2.api.dto.lowlevel.UnknownFrame) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 28 with ConnectionException

use of com.webpieces.http2.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.http2.api.dto.lowlevel.lib.HasHeaderFragment) ContinuationFrame(com.webpieces.http2.api.dto.lowlevel.ContinuationFrame) PushPromiseFrame(com.webpieces.http2.api.dto.lowlevel.PushPromiseFrame) HeadersFrame(com.webpieces.http2.api.dto.lowlevel.HeadersFrame) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 29 with ConnectionException

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

the class ResponseListener method failure.

@Override
public void failure(Throwable e) {
    ConnectionCancelled connCancelled = new ConnectionFailure(new ConnectionException(CancelReasonCode.BUG, logId, 0, "Failure from connection", e));
    responseListener.cancel(new ShutdownStream(0, connCancelled));
}
Also used : ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) ConnectionFailure(com.webpieces.http2engine.api.error.ConnectionFailure) ConnectionCancelled(com.webpieces.http2engine.api.error.ConnectionCancelled) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Example 30 with ConnectionException

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

the class SettingsMarshaller method validate.

private void validate(Http2Setting http2Setting) {
    SettingsParameter key = SettingsParameter.lookup(http2Setting.getId());
    long value = http2Setting.getValue();
    if (key == null)
        // unknown setting
        return;
    switch(key) {
        case SETTINGS_ENABLE_PUSH:
            if (value != 0 && value != 1)
                throw new ConnectionException(CancelReasonCode.INVALID_SETTING, 0, "push setting must be 0 or 1 but was=" + value);
            break;
        case SETTINGS_INITIAL_WINDOW_SIZE:
            validateWindowSize(value);
            break;
        case SETTINGS_MAX_FRAME_SIZE:
            validateMaxFrameSize(value);
            break;
        case SETTINGS_HEADER_TABLE_SIZE:
        case SETTINGS_MAX_CONCURRENT_STREAMS:
        case SETTINGS_MAX_HEADER_LIST_SIZE:
            break;
        default:
            throw new IllegalArgumentException("case statement missing new setting=" + key + " with value=" + value);
    }
}
Also used : SettingsParameter(com.webpieces.http2.api.dto.lowlevel.lib.SettingsParameter) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Aggregations

ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)26 DataWrapper (org.webpieces.data.api.DataWrapper)18 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)15 Test (org.junit.Test)13 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)12 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)8 ByteBuffer (java.nio.ByteBuffer)8 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)6 ConnectionClosedException (com.webpieces.http2engine.api.error.ConnectionClosedException)6 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)6 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)5 FrameHeaderData (com.webpieces.http2parser.impl.FrameHeaderData)5 StreamRef (com.webpieces.http2.api.streaming.StreamRef)4 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)4 StreamException (com.webpieces.http2.api.dto.error.StreamException)3 HeadersFrame (com.webpieces.http2.api.dto.lowlevel.HeadersFrame)3 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)3 PriorityDetails (com.webpieces.http2.api.dto.lowlevel.lib.PriorityDetails)3 DataSplit (com.webpieces.http2parser.impl.DataSplit)3 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)2