Search in sources :

Example 1 with PushPromiseFrame

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

the class PushPromiseMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    PushPromiseFrame castFrame = (PushPromiseFrame) frame;
    int originalStreamId = castFrame.getPromisedStreamId();
    int streamId = originalStreamId & 0x7FFFFFFF;
    if (streamId != originalStreamId)
        throw new RuntimeException("your promisedStreamId is too large per spec. frame=" + frame);
    int paddingSize = castFrame.getPadding().getReadableSize();
    byte value = 0x0;
    if (castFrame.isEndHeaders())
        value |= 0x4;
    if (paddingSize > 0)
        value |= 0x8;
    ByteBuffer prelude = bufferPool.nextBuffer(4);
    prelude.putInt(castFrame.getPromisedStreamId());
    prelude.flip();
    DataWrapper headersDW = castFrame.getHeaderFragment();
    DataWrapper finalDW = dataGen.chainDataWrappers(dataGen.wrapByteBuffer(prelude), headersDW);
    DataWrapper payload = PaddingUtil.padDataIfNeeded(finalDW, castFrame.getPadding());
    return super.marshalFrame(frame, value, payload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PushPromiseFrame(com.webpieces.http2parser.api.dto.PushPromiseFrame) ByteBuffer(java.nio.ByteBuffer)

Example 2 with PushPromiseFrame

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

the class HpackParserImpl method combineAndSendHeadersToClient.

private void combineAndSendHeadersToClient(UnmarshalStateImpl state) {
    List<HasHeaderFragment> hasHeaderFragmentList = state.getHeadersToCombine();
    // Now we set the full header list on the first frame and just return that
    HasHeaderFragment firstFrame = hasHeaderFragmentList.get(0);
    DataWrapper allSerializedHeaders = dataGen.emptyWrapper();
    for (HasHeaderFragment iterFrame : hasHeaderFragmentList) {
        allSerializedHeaders = dataGen.chainDataWrappers(allSerializedHeaders, iterFrame.getHeaderFragment());
    }
    Map<Http2HeaderName, Http2Header> knownHeaders = new HashMap<>();
    List<Http2Header> headers = decoding.decode(state, allSerializedHeaders, firstFrame.getStreamId(), header -> knownHeaders.put(header.getKnownName(), header));
    if (firstFrame instanceof HeadersFrame) {
        HeadersFrame f = (HeadersFrame) firstFrame;
        Http2Headers fullHeaders = createCorrectType(knownHeaders, headers, state.getLogId(), f.getStreamId());
        fullHeaders.setStreamId(f.getStreamId());
        fullHeaders.setPriorityDetails(f.getPriorityDetails());
        fullHeaders.setEndOfStream(f.isEndOfStream());
        state.getParsedFrames().add(fullHeaders);
    } else if (firstFrame instanceof PushPromiseFrame) {
        PushPromiseFrame f = (PushPromiseFrame) firstFrame;
        Http2Push fullHeaders = new Http2Push(headers);
        fullHeaders.setStreamId(f.getStreamId());
        fullHeaders.setPromisedStreamId(f.getPromisedStreamId());
        state.getParsedFrames().add(fullHeaders);
    }
    hasHeaderFragmentList.clear();
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HasHeaderFragment(com.webpieces.http2parser.api.dto.lib.HasHeaderFragment) HashMap(java.util.HashMap) Http2Headers(com.webpieces.hpack.api.dto.Http2Headers) Http2HeaderName(com.webpieces.http2parser.api.dto.lib.Http2HeaderName) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) Http2Push(com.webpieces.hpack.api.dto.Http2Push) PushPromiseFrame(com.webpieces.http2parser.api.dto.PushPromiseFrame) HeadersFrame(com.webpieces.http2parser.api.dto.HeadersFrame)

Example 3 with PushPromiseFrame

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

the class HeaderEncoding method translateToFrames.

public List<Http2Frame> translateToFrames(long maxFrameSize, Encoder encoder, Http2Push p) {
    PushPromiseFrame frame = new PushPromiseFrame();
    frame.setStreamId(p.getStreamId());
    frame.setPromisedStreamId(p.getPromisedStreamId());
    List<Http2Header> headerList = p.getHeaders();
    List<Http2Frame> headerFrames = toHeaderFrames(maxFrameSize, encoder, frame, headerList);
    return headerFrames;
}
Also used : Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) PushPromiseFrame(com.webpieces.http2parser.api.dto.PushPromiseFrame) Http2Frame(com.webpieces.http2parser.api.dto.lib.Http2Frame)

Example 4 with PushPromiseFrame

use of com.webpieces.http2parser.api.dto.PushPromiseFrame 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 5 with PushPromiseFrame

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

PushPromiseFrame (com.webpieces.http2parser.api.dto.PushPromiseFrame)5 HeadersFrame (com.webpieces.http2parser.api.dto.HeadersFrame)2 ConnectionException (com.webpieces.http2parser.api.dto.error.ConnectionException)2 HasHeaderFragment (com.webpieces.http2parser.api.dto.lib.HasHeaderFragment)2 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)2 ByteBuffer (java.nio.ByteBuffer)2 DataWrapper (org.webpieces.data.api.DataWrapper)2 Http2Headers (com.webpieces.hpack.api.dto.Http2Headers)1 Http2Push (com.webpieces.hpack.api.dto.Http2Push)1 ContinuationFrame (com.webpieces.http2parser.api.dto.ContinuationFrame)1 Http2Frame (com.webpieces.http2parser.api.dto.lib.Http2Frame)1 Http2HeaderName (com.webpieces.http2parser.api.dto.lib.Http2HeaderName)1 DataSplit (com.webpieces.http2parser.impl.DataSplit)1 HashMap (java.util.HashMap)1