Search in sources :

Example 6 with Http2Frame

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

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

the class HpackParserImpl method unmarshal.

@Override
public UnmarshalState unmarshal(UnmarshalState memento, DataWrapper newData) {
    UnmarshalStateImpl state = (UnmarshalStateImpl) memento;
    //reset any parsed frames
    state.clearParsedFrames();
    Http2Memento result = parser.parse(state.getLowLevelState(), newData);
    List<Http2Frame> parsedFrames = result.getParsedFrames();
    for (Http2Frame frame : parsedFrames) {
        processFrame(state, frame);
    }
    return state;
}
Also used : Http2Memento(com.webpieces.http2parser.api.Http2Memento) Http2Frame(com.webpieces.http2parser.api.dto.lib.Http2Frame)

Example 8 with Http2Frame

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

the class TestS4FrameSizeAndHeaders method testSection4_3InterleavedFrames.

/**
	 * Each header block is processed as a discrete unit. Header blocks 
	 * MUST be transmitted as a contiguous sequence of frames, with no interleaved 
	 * frames of any other type or from any other stream. The last frame in a 
	 * sequence of HEADERS or CONTINUATION frames has the END_HEADERS flag set. The 
	 * last frame in a sequence of PUSH_PROMISE or CONTINUATION frames has the 
	 * END_HEADERS flag set. This allows a header block to be logically equivalent to a single frame.
	 * 
	 * Header block fragments can only be sent as the payload of HEADERS, PUSH_PROMISE, or 
	 * CONTINUATION frames because these frames carry data that can modify the 
	 * compression context maintained by a receiver. An endpoint receiving 
	 * HEADERS, PUSH_PROMISE, or CONTINUATION frames needs to reassemble header 
	 * blocks and perform decompression even if the frames are to be discarded. A receiver 
	 * MUST terminate the connection with a connection error (Section 5.4.1) of 
	 * type COMPRESSION_ERROR if it does not decompress a header block.
	 */
@Test
public void testSection4_3InterleavedFrames() {
    List<Http2Frame> frames = createInterleavedFrames();
    //for this test, need interleaved
    Assert.assertTrue(frames.size() >= 3);
    mockChannel.sendFrame(frames.get(0));
    mockChannel.sendFrame(frames.get(1));
    //no request comes in
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    //no cancels
    Assert.assertEquals(0, mockListener.getNumCancelsThatCameIn());
    //remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.PROTOCOL_ERROR, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertTrue(msg.contains("Headers/continuations from two different streams per spec cannot be interleaved. "));
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Http2Frame(com.webpieces.http2parser.api.dto.lib.Http2Frame) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 9 with Http2Frame

use of com.webpieces.http2parser.api.dto.lib.Http2Frame 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.http2parser.api.dto.lib.HasHeaderFragment) ContinuationFrame(com.webpieces.http2parser.api.dto.ContinuationFrame) Http2Frame(com.webpieces.http2parser.api.dto.lib.Http2Frame) LinkedList(java.util.LinkedList)

Example 10 with Http2Frame

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

the class HpackParserImpl method translate.

private DataWrapper translate(List<Http2Frame> headerFrames) {
    DataWrapper allData = DataWrapperGeneratorFactory.EMPTY;
    for (Http2Frame f : headerFrames) {
        DataWrapper frameData = parser.marshal(f);
        allData = dataGen.chainDataWrappers(allData, frameData);
    }
    return allData;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Http2Frame(com.webpieces.http2parser.api.dto.lib.Http2Frame)

Aggregations

Http2Frame (com.webpieces.http2parser.api.dto.lib.Http2Frame)11 Encoder (com.twitter.hpack.Encoder)4 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)4 DataWrapper (org.webpieces.data.api.DataWrapper)4 Http2Response (com.webpieces.hpack.api.dto.Http2Response)2 HeaderEncoding (com.webpieces.hpack.impl.HeaderEncoding)2 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Http2Request (com.webpieces.hpack.api.dto.Http2Request)1 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)1 Http2Memento (com.webpieces.http2parser.api.Http2Memento)1 ContinuationFrame (com.webpieces.http2parser.api.dto.ContinuationFrame)1 HeadersFrame (com.webpieces.http2parser.api.dto.HeadersFrame)1 PushPromiseFrame (com.webpieces.http2parser.api.dto.PushPromiseFrame)1 HasHeaderFragment (com.webpieces.http2parser.api.dto.lib.HasHeaderFragment)1 LinkedList (java.util.LinkedList)1 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)1 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)1