use of org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn in project webpieces by deanhiller.
the class TestHttp11Basic method testPostWithChunking.
@Test
public void testPostWithChunking() {
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
req.addHeader(new Header(KnownHeaderName.TRANSFER_ENCODING, "chunked"));
mockChannel.write(req);
PassedIn in1 = mockListener.getSingleRequest();
HttpRequest req1 = Http2Translations.translateRequest(in1.request);
Assert.assertEquals(req, req1);
HttpChunk chunk = new HttpChunk();
String bodyStr = "hi here and there";
DataWrapper data = dataGen.wrapByteArray(bodyStr.getBytes(StandardCharsets.UTF_8));
chunk.setBody(data);
mockChannel.write(chunk);
DataFrame singleFrame = (DataFrame) mockStreamWriter.getSingleFrame();
Assert.assertTrue(!singleFrame.isEndOfStream());
DataWrapper data2 = singleFrame.getData();
String result = data2.createStringFromUtf8(0, data2.getReadableSize());
Assert.assertEquals(bodyStr, result);
HttpLastChunk last = new HttpLastChunk();
mockChannel.write(last);
DataFrame lastEmpty = (DataFrame) mockStreamWriter.getSingleFrame();
Assert.assertTrue(lastEmpty.isEndOfStream());
Assert.assertEquals(0, lastEmpty.getData().getReadableSize());
}
use of org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn in project webpieces by deanhiller.
the class TestS5_1StreamStates 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() {
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);
Cancel info = mockListener.getCancelInfo();
Assert.assertEquals(stream, info.stream);
//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 org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn in project webpieces by deanhiller.
the class TestHttp2Errors method testFarEndClosedSocket.
@Test
public void testFarEndClosedSocket() throws InterruptedException, ExecutionException {
MockStreamWriter mockSw = new MockStreamWriter();
mockListener.addMockStreamToReturn(mockSw);
MockStreamWriter mockSw2 = new MockStreamWriter();
mockListener.addMockStreamToReturn(mockSw2);
Http2Request request1 = Http2Requests.createRequest(1, true);
Http2Request request2 = Http2Requests.createRequest(3, true);
mockChannel.send(request1);
PassedIn in1 = mockListener.getSingleRequest();
mockChannel.send(request2);
PassedIn in2 = mockListener.getSingleRequest();
mockChannel.close();
List<Cancel> cancels = mockListener.getCancels();
Assert.assertEquals(in1.stream, cancels.get(0).stream);
Assert.assertEquals(in2.stream, cancels.get(1).stream);
}
use of org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn in project webpieces by deanhiller.
the class TestHttp11Basic method testSendTwoRequestsStreamSecond.
@Test
public void testSendTwoRequestsStreamSecond() throws InterruptedException, ExecutionException {
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
HttpRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
mockChannel.write(req);
PassedIn in1 = mockListener.getSingleRequest();
req2.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "20"));
mockChannel.write(req2);
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
byte[] buf = new byte[10];
DataWrapper dataWrapper = dataGen.wrapByteArray(buf);
HttpData data1 = new HttpData(dataWrapper, false);
mockChannel.write(data1);
DataWrapper dataWrapper2 = dataGen.wrapByteArray(buf);
HttpData data2 = new HttpData(dataWrapper2, true);
mockChannel.write(data2);
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
//send back request2's response first!!!! BUT verify it does not go to client per http11 pipelining rules
HttpResponse resp1 = Requests.createResponse(1);
resp1.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
Http2Response headers1 = Http2Translations.responseToHeaders(resp1);
in1.stream.sendResponse(headers1);
HttpPayload payload = mockChannel.getFrameAndClear();
Assert.assertEquals(resp1, payload);
PassedIn in2 = mockListener.getSingleRequest();
HttpResponse resp2 = Requests.createResponse(2);
resp2.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
Http2Response headers2 = Http2Translations.responseToHeaders(resp2);
in2.stream.sendResponse(headers2);
HttpPayload payload2 = mockChannel.getFrameAndClear();
Assert.assertEquals(resp2, payload2);
}
use of org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn in project webpieces by deanhiller.
the class TestHttp11Basic method testSendTwoRequests.
@Test
public void testSendTwoRequests() throws InterruptedException, ExecutionException {
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
HttpRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
mockChannel.write(req);
PassedIn in1 = mockListener.getSingleRequest();
mockChannel.write(req2);
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
//send back request2's response first!!!! BUT verify it does not go to client per http11 pipelining rules
HttpResponse resp1 = Requests.createResponse(1);
resp1.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
Http2Response headers1 = Http2Translations.responseToHeaders(resp1);
in1.stream.sendResponse(headers1);
HttpPayload payload = mockChannel.getFrameAndClear();
Assert.assertEquals(resp1, payload);
PassedIn in2 = mockListener.getSingleRequest();
HttpResponse resp2 = Requests.createResponse(2);
resp2.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
Http2Response headers2 = Http2Translations.responseToHeaders(resp2);
in2.stream.sendResponse(headers2);
HttpPayload payload2 = mockChannel.getFrameAndClear();
Assert.assertEquals(resp2, payload2);
}
Aggregations