use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.
the class TestS5x1StreamStates method testSection5_1BadFrameReceivedInReservedRemoteState.
/**
* reserved local
*
* A PRIORITY or WINDOW_UPDATE frame MAY be received in this state. Receiving any
* type of frame other than RST_STREAM, PRIORITY, or WINDOW_UPDATE on a stream
* in this state MUST be treated as a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
*/
@Test
public void testSection5_1BadFrameReceivedInReservedRemoteState() {
MockStreamWriter mockWriter = new MockStreamWriter();
XFuture<StreamWriter> futA = XFuture.completedFuture(mockWriter);
MockStreamRef mockStream = new MockStreamRef(futA);
mockListener.addMockStreamToReturn(mockStream);
Http2Request request = Http2Requests.createRequest(1, true);
mockChannel.send(request);
PassedIn in = mockListener.getSingleRequest();
ResponseStream stream = in.stream;
Http2Push push = Http2Requests.createPush(request.getStreamId());
stream.openPushStream().process(push);
Http2Msg pushMsg = mockChannel.getFrameAndClear();
Assert.assertEquals(push, pushMsg);
// send bad frame in this state
DataFrame data = Http2Requests.createData1(push.getPromisedStreamId(), false);
mockChannel.send(data);
Assert.assertTrue(mockStream.isCancelled());
// 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.assertEquals("ConnectionException: HttpSocket[Http2ChannelCache1]:stream2:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "No transition defined on statemachine for event=RECV_DATA when in state=Reserved(local)", msg);
Assert.assertTrue(mockChannel.isClosed());
}
use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.
the class TestSBasicRequestResponse method testWithDataAndTrailingHeaders.
@Test
public void testWithDataAndTrailingHeaders() throws InterruptedException, ExecutionException, TimeoutException {
MockStreamWriter mockSw = new MockStreamWriter();
mockSw.setDefaultRetValToThis();
mockListener.addMockStreamToReturn(mockSw);
Http2Request request1 = Http2Requests.createRequest(1, false);
DataFrame data1 = Http2Requests.createData1(request1.getStreamId(), false);
Http2Trailers trailing = Http2Requests.createTrailers(request1.getStreamId());
mockChannel.send(request1);
PassedIn incoming1 = mockListener.getSingleRequest();
Assert.assertEquals(request1, incoming1.request);
mockChannel.send(data1);
DataFrame incoming2 = (DataFrame) mockSw.getSingleFrame();
Assert.assertEquals(3, incoming2.getData().getReadableSize());
// clear window update frames
Assert.assertEquals(2, mockChannel.getFramesAndClear().size());
mockChannel.send(trailing);
Http2Headers incoming = (Http2Headers) mockSw.getSingleFrame();
Assert.assertEquals(trailing, incoming);
Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), false);
XFuture<StreamWriter> future = incoming1.stream.process(resp);
Http2Msg response = mockChannel.getFrameAndClear();
Assert.assertEquals(resp, response);
StreamWriter writer = future.get(2, TimeUnit.SECONDS);
DataFrame data2 = Http2Requests.createData2(request1.getStreamId(), false);
writer.processPiece(data2);
DataFrame dataResp = (DataFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(1, dataResp.getData().getReadableSize());
Http2Trailers trailingResp = Http2Requests.createTrailers(request1.getStreamId());
writer.processPiece(trailingResp);
Http2Headers trailers = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(trailingResp, trailers);
}
use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.
the class TestSBasicRequestResponse method testWithData.
@Test
public void testWithData() throws InterruptedException, ExecutionException, TimeoutException {
MockStreamWriter mockSw = new MockStreamWriter();
mockSw.setDefaultRetValToThis();
mockListener.addMockStreamToReturn(mockSw);
Http2Request request1 = Http2Requests.createRequest(1, false);
DataFrame data = Http2Requests.createData1(request1.getStreamId(), true);
mockChannel.send(request1);
PassedIn incoming1 = mockListener.getSingleRequest();
Assert.assertEquals(request1, incoming1.request);
mockChannel.send(data);
DataFrame incoming = (DataFrame) mockSw.getSingleFrame();
Assert.assertEquals(3, incoming.getData().getReadableSize());
// clear window update frames
Assert.assertEquals(2, mockChannel.getFramesAndClear().size());
Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), false);
XFuture<StreamWriter> future = incoming1.stream.process(resp);
Http2Msg response = mockChannel.getFrameAndClear();
Assert.assertEquals(resp, response);
StreamWriter writer = future.get(2, TimeUnit.SECONDS);
DataFrame data2 = Http2Requests.createData2(request1.getStreamId(), true);
writer.processPiece(data2);
DataFrame dataResp = (DataFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(1, dataResp.getData().getReadableSize());
}
use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.
the class Level5AStates method translate.
protected Http2Event translate(Http2SendRecieve sendRecv, Http2Msg payload) {
Http2PayloadType payloadType;
if (payload instanceof Http2Headers) {
Http2Headers head = (Http2Headers) payload;
if (head.isEndOfStream())
payloadType = Http2PayloadType.HEADERS_EOS;
else
payloadType = Http2PayloadType.HEADERS;
} else if (payload instanceof DataFrame) {
DataFrame data = (DataFrame) payload;
if (data.isEndOfStream())
payloadType = Http2PayloadType.DATA_EOS;
else
payloadType = Http2PayloadType.DATA;
} else if (payload instanceof Http2Push) {
payloadType = Http2PayloadType.PUSH_PROMISE;
} else if (payload instanceof CancelReason) {
payloadType = Http2PayloadType.RESET_STREAM;
} else
throw new IllegalArgumentException("unknown payload type for payload=" + payload);
return Http2Event.lookup(sendRecv, payloadType);
}
use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.
the class TestC4FrameSizeAndHeaders method testSection4_2FrameTooLarge.
/**
* An endpoint MUST send an error code of FRAME_SIZE_ERROR if a frame
* exceeds the size defined in SETTINGS_MAX_FRAME_SIZE, exceeds any
* limit defined for the frame type, or is too small to contain
* mandatory frame data. A frame size error in a frame that could alter
* the state of the entire connection MUST be treated as a connection
* error (Section 5.4.1); this includes any frame carrying a header
* block (Section 4.3) (that is, HEADERS, PUSH_PROMISE, and
* CONTINUATION), SETTINGS, and any frame with a stream identifier of 0.
*/
@Test
public void testSection4_2FrameTooLarge() {
MockStreamWriter mockStreamWriter = new MockStreamWriter();
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(mockStreamWriter));
Http2Request request = sendRequestToServer(listener1);
sendResponseFromServer(listener1, request);
DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
byte[] buf = new byte[localSettings.getMaxFrameSize() + 4];
dataFrame.setData(DATA_GEN.wrapByteArray(buf));
// endOfStream=false
mockChannel.write(dataFrame);
// remote receives goAway
GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(Http2ErrorCode.FRAME_SIZE_ERROR, goAway.getKnownErrorCode());
DataWrapper debugData = goAway.getDebugData();
String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
Assert.assertEquals("ConnectionException: stream1:(EXCEEDED_MAX_FRAME_SIZE) Frame size=16389 was greater than max=16385", msg);
Assert.assertTrue(mockChannel.isClosed());
ShutdownStream failResp = (ShutdownStream) listener1.getSingleRstStream();
Assert.assertEquals(CancelReasonCode.EXCEEDED_MAX_FRAME_SIZE, failResp.getCause().getReasonCode());
// send new request on closed connection
Http2Request request1 = Requests.createRequest();
StreamRef streamRef = httpSocket.openStream().process(request1, listener1);
XFuture<StreamWriter> future = streamRef.getWriter();
ConnectionClosedException intercept = (ConnectionClosedException) TestAssert.intercept(future);
Assert.assertTrue(intercept.getMessage().contains("Connection closed or closing"));
Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
}
Aggregations