Search in sources :

Example 1 with DataSplit

use of com.webpieces.http2parser.impl.DataSplit in project webpieces by deanhiller.

the class HeadersMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    HeadersFrame frame = new HeadersFrame();
    super.unmarshalFrame(state, frame);
    byte flagsByte = state.getFrameHeaderData().getFlagsByte();
    frame.setEndOfStream((flagsByte & 0x1) == 0x1);
    frame.setEndHeaders((flagsByte & 0x4) == 0x4);
    boolean isPadded = (flagsByte & 0x8) == 0x8;
    PriorityDetails priorityDetails = null;
    if ((flagsByte & 0x20) == 0x20) {
        priorityDetails = new PriorityDetails();
        frame.setPriorityDetails(priorityDetails);
    }
    DataSplit padSplit = PaddingUtil.extractPayloadAndPadding(isPadded, framePayloadData, frame.getStreamId());
    frame.setPadding(padSplit.getPadding());
    DataWrapper paddingStripped = padSplit.getPayload();
    if (priorityDetails != null) {
        //1 bit Exclusive flag, 31 bits stream dependency, and 8 bits weight = 5 bytes....
        List<? extends DataWrapper> split = dataGen.split(paddingStripped, 5);
        ByteBuffer preludeBytes = bufferPool.createWithDataWrapper(split.get(0));
        int firstInt = preludeBytes.getInt();
        priorityDetails.setStreamDependencyIsExclusive((firstInt >>> 31) == 0x1);
        int streamDependency = firstInt & 0x7FFFFFFF;
        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) (preludeBytes.get() & 0xFF));
        frame.setHeaderFragment(split.get(1));
        bufferPool.releaseBuffer(preludeBytes);
    } else {
        frame.setHeaderFragment(paddingStripped);
    }
    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 : DataWrapper(org.webpieces.data.api.DataWrapper) PriorityDetails(com.webpieces.http2parser.api.dto.lib.PriorityDetails) HeadersFrame(com.webpieces.http2parser.api.dto.HeadersFrame) ByteBuffer(java.nio.ByteBuffer) DataSplit(com.webpieces.http2parser.impl.DataSplit) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 2 with DataSplit

use of com.webpieces.http2parser.impl.DataSplit 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 3 with DataSplit

use of com.webpieces.http2parser.impl.DataSplit 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)

Aggregations

ConnectionException (com.webpieces.http2parser.api.dto.error.ConnectionException)3 DataSplit (com.webpieces.http2parser.impl.DataSplit)3 ByteBuffer (java.nio.ByteBuffer)2 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)1 HeadersFrame (com.webpieces.http2parser.api.dto.HeadersFrame)1 PushPromiseFrame (com.webpieces.http2parser.api.dto.PushPromiseFrame)1 PriorityDetails (com.webpieces.http2parser.api.dto.lib.PriorityDetails)1 DataWrapper (org.webpieces.data.api.DataWrapper)1