Search in sources :

Example 21 with ConnectionException

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

the class GoAwayMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    GoAwayFrame frame = new GoAwayFrame();
    super.unmarshalFrame(state, frame);
    int streamId = state.getFrameHeaderData().getStreamId();
    if (streamId != 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, streamId, "goaway frame had stream id=" + streamId);
    List<? extends DataWrapper> split = dataGen.split(framePayloadData, 8);
    ByteBuffer preludeBytes = bufferPool.createWithDataWrapper(split.get(0));
    long lastStreamId = UnsignedData.getUnsignedInt(preludeBytes);
    long errorCode = UnsignedData.getUnsignedInt(preludeBytes);
    frame.setLastStreamId(lastStreamId);
    frame.setErrorCode(errorCode);
    frame.setDebugData(split.get(1));
    bufferPool.releaseBuffer(preludeBytes);
    if (frame.getStreamId() != 0)
        throw new IllegalArgumentException("GoAwayFrame can never be any other stream id except 0 which is already set");
    return frame;
}
Also used : ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame)

Example 22 with ConnectionException

use of com.webpieces.http2parser.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 = dataGen.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.http2parser.api.dto.PushPromiseFrame) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException) DataSplit(com.webpieces.http2parser.impl.DataSplit)

Example 23 with ConnectionException

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

the class PriorityMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    FrameHeaderData frameHeaderData = state.getFrameHeaderData();
    int streamId = frameHeaderData.getStreamId();
    if (state.getFrameHeaderData().getPayloadLength() != 5)
        throw new StreamException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "priority size not 5 and instead is=" + state.getFrameHeaderData().getPayloadLength());
    PriorityFrame frame = new PriorityFrame();
    PriorityDetails priorityDetails = frame.getPriorityDetails();
    super.unmarshalFrame(state, frame);
    ByteBuffer payloadByteBuffer = bufferPool.createWithDataWrapper(framePayloadData);
    int firstInt = payloadByteBuffer.getInt();
    priorityDetails.setStreamDependencyIsExclusive((firstInt >>> 31) == 0x1);
    int streamDependency = firstInt & 0x7FFFFFFF;
    if (frame.getStreamId() == 0) {
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "priority cannot be streamid 0 and was=" + frame.getStreamId());
    } else if (streamDependency == frame.getStreamId()) {
        // Can't depend on self
        throw new ConnectionException(CancelReasonCode.BAD_STREAM_DEPENDENCY, streamDependency, "stream id=" + streamDependency + " depends on itself");
    }
    priorityDetails.setStreamDependency(streamDependency);
    priorityDetails.setWeight((short) (payloadByteBuffer.get() & 0xFF));
    bufferPool.releaseBuffer(payloadByteBuffer);
    return frame;
}
Also used : FrameHeaderData(com.webpieces.http2parser.impl.FrameHeaderData) PriorityDetails(com.webpieces.http2parser.api.dto.lib.PriorityDetails) PriorityFrame(com.webpieces.http2parser.api.dto.PriorityFrame) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException) StreamException(com.webpieces.http2parser.api.dto.error.StreamException)

Example 24 with ConnectionException

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