use of com.webpieces.http2parser.api.dto.lib.Http2Frame in project webpieces by deanhiller.
the class TestC4FrameSizeAndHeaders 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() {
MockStreamWriter mockStreamWriter = new MockStreamWriter();
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(mockStreamWriter));
Http2Request request = sendRequestToServer(listener1);
//has to be 1 since we use 1 in the response
Assert.assertEquals(1, request.getStreamId());
List<Http2Frame> frames = createInterleavedFrames();
//for this test, need interleaved
Assert.assertTrue(frames.size() >= 3);
mockChannel.writeFrame(frames.get(0));
Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
mockChannel.writeFrame(frames.get(1));
ShutdownStream reset = (ShutdownStream) listener1.getSingleRstStream();
Assert.assertEquals(CancelReasonCode.HEADERS_MIXED_WITH_FRAMES, reset.getCause().getReasonCode());
//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());
}
use of com.webpieces.http2parser.api.dto.lib.Http2Frame in project webpieces by deanhiller.
the class TestC4FrameSizeAndHeaders method createInterleavedFrames.
private List<Http2Frame> createInterleavedFrames() {
Http2Response response1 = new Http2Response();
response1.setStreamId(1);
response1.setEndOfStream(true);
fillHeaders(response1);
HeaderEncoding encoding = new HeaderEncoding();
List<Http2Frame> frames1 = encoding.translateToFrames(localSettings.getMaxFrameSize(), new Encoder(localSettings.getHeaderTableSize()), response1);
Http2Response response2 = new Http2Response();
response2.setStreamId(3);
response1.setEndOfStream(true);
response2.addHeader(new Http2Header(Http2HeaderName.ACCEPT, "value"));
List<Http2Frame> frames2 = encoding.translateToFrames(localSettings.getMaxFrameSize(), new Encoder(localSettings.getHeaderTableSize()), response2);
List<Http2Frame> frames = new ArrayList<>();
frames.addAll(frames1);
frames.add(1, frames2.get(0));
return frames;
}
use of com.webpieces.http2parser.api.dto.lib.Http2Frame in project webpieces by deanhiller.
the class HpackParserImpl method createHeadersData.
private DataWrapper createHeadersData(MarshalStateImpl state, Http2Headers headers) {
long maxFrameSize = state.getMaxRemoteFrameSize();
Encoder encoder = state.getEncoder();
List<Http2Frame> headerFrames = encoding.translateToFrames(maxFrameSize, encoder, headers);
return translate(headerFrames);
}
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, Http2Headers headers) {
HeadersFrame frame = new HeadersFrame();
frame.setStreamId(headers.getStreamId());
frame.setEndOfStream(headers.isEndOfStream());
frame.setPriorityDetails(headers.getPriorityDetails());
List<Http2Header> headerList = headers.getHeaders();
List<Http2Frame> headerFrames = toHeaderFrames(maxFrameSize, encoder, frame, headerList);
return headerFrames;
}
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;
}
Aggregations