Search in sources :

Example 1 with ContinuationFrame

use of com.webpieces.http2.api.dto.lowlevel.ContinuationFrame 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 2 with ContinuationFrame

use of com.webpieces.http2.api.dto.lowlevel.ContinuationFrame in project webpieces by deanhiller.

the class ContinuationMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    ContinuationFrame frame = new ContinuationFrame();
    super.unmarshalFrame(state, frame);
    byte flags = state.getFrameHeaderData().getFlagsByte();
    frame.setEndHeaders((flags & 0x4) == 0x4);
    frame.setHeaderFragment(framePayloadData);
    return frame;
}
Also used : ContinuationFrame(com.webpieces.http2.api.dto.lowlevel.ContinuationFrame)

Example 3 with ContinuationFrame

use of com.webpieces.http2.api.dto.lowlevel.ContinuationFrame in project webpieces by deanhiller.

the class ContinuationMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    ContinuationFrame castFrame = (ContinuationFrame) frame;
    byte value = 0x0;
    if (castFrame.isEndHeaders())
        value |= 0x4;
    DataWrapper dataPayload = castFrame.getHeaderFragment();
    return super.marshalFrame(frame, value, dataPayload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ContinuationFrame(com.webpieces.http2.api.dto.lowlevel.ContinuationFrame)

Example 4 with ContinuationFrame

use of com.webpieces.http2.api.dto.lowlevel.ContinuationFrame in project webpieces by deanhiller.

the class HeaderEncoding method createHeaderFrames.

private List<Http2Frame> createHeaderFrames(HasHeaderFragment initialFrame, List<Http2Header> headers, Encoder encoder, long maxFrameSize) {
    int maxSize = (int) maxFrameSize;
    if (maxFrameSize > Integer.MAX_VALUE)
        throw new IllegalStateException("max frame size too large for this hpack library");
    List<Http2Frame> headerFrames = new LinkedList<>();
    DataWrapper serializedHeaders = serializeHeaders(encoder, headers);
    HasHeaderFragment currentFrame = initialFrame;
    HasHeaderFragment lastFrame = currentFrame;
    DataWrapper dataLeftOver = serializedHeaders;
    while (dataLeftOver.getReadableSize() > 0) {
        lastFrame = currentFrame;
        int splitSize = Math.min(dataLeftOver.getReadableSize(), maxSize);
        List<? extends DataWrapper> split = dataGen.split(dataLeftOver, splitSize);
        DataWrapper fragment = split.get(0);
        currentFrame.setHeaderFragment(fragment);
        headerFrames.add(currentFrame);
        currentFrame = new ContinuationFrame();
        currentFrame.setStreamId(initialFrame.getStreamId());
        dataLeftOver = split.get(1);
    }
    // last frame is currentFrame so set end header
    lastFrame.setEndHeaders(true);
    return headerFrames;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HasHeaderFragment(com.webpieces.http2.api.dto.lowlevel.lib.HasHeaderFragment) ContinuationFrame(com.webpieces.http2.api.dto.lowlevel.ContinuationFrame) Http2Frame(com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame) LinkedList(java.util.LinkedList)

Aggregations

ContinuationFrame (com.webpieces.http2.api.dto.lowlevel.ContinuationFrame)4 HasHeaderFragment (com.webpieces.http2.api.dto.lowlevel.lib.HasHeaderFragment)2 DataWrapper (org.webpieces.data.api.DataWrapper)2 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)1 HeadersFrame (com.webpieces.http2.api.dto.lowlevel.HeadersFrame)1 PushPromiseFrame (com.webpieces.http2.api.dto.lowlevel.PushPromiseFrame)1 Http2Frame (com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)1 LinkedList (java.util.LinkedList)1