Search in sources :

Example 1 with PassedIn

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());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Cancel(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.Cancel) Http2Push(com.webpieces.hpack.api.dto.Http2Push) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) ResponseStream(org.webpieces.frontend2.api.ResponseStream) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 2 with PassedIn

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.sendToSvr(req);
    PassedIn in1 = mockListener.getSingleRequest();
    HttpRequest req1 = Http2ToHttp11.translateRequest(in1.request);
    Assert.assertEquals(req, req1);
    HttpChunk chunk = new HttpChunk();
    String bodyStr = "hi here and there";
    DataWrapper data = DATA_GEN.wrapByteArray(bodyStr.getBytes(StandardCharsets.UTF_8));
    chunk.setBody(data);
    mockChannel.sendToSvr(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.sendToSvr(last);
    DataFrame lastEmpty = (DataFrame) mockStreamWriter.getSingleFrame();
    Assert.assertTrue(lastEmpty.isEndOfStream());
    Assert.assertEquals(0, lastEmpty.getData().getReadableSize());
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataWrapper(org.webpieces.data.api.DataWrapper) HttpLastChunk(org.webpieces.httpparser.api.dto.HttpLastChunk) Header(org.webpieces.httpparser.api.common.Header) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) HttpChunk(org.webpieces.httpparser.api.dto.HttpChunk) Test(org.junit.Test)

Example 3 with PassedIn

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, TimeoutException {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    HttpRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    mockChannel.sendToSvr(req);
    PassedIn in1 = mockListener.getSingleRequest();
    req2.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "20"));
    XFuture<Void> fut = mockChannel.sendToSvrAsync(req2);
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    Assert.assertFalse(fut.isDone());
    byte[] buf = new byte[10];
    DataWrapper dataWrapper = DATA_GEN.wrapByteArray(buf);
    HttpData data1 = new HttpData(dataWrapper, false);
    XFuture<Void> fut2 = mockChannel.sendToSvrAsync(data1);
    Assert.assertFalse(fut.isDone());
    Assert.assertFalse(fut2.isDone());
    DataWrapper dataWrapper2 = DATA_GEN.wrapByteArray(buf);
    HttpData data2 = new HttpData(dataWrapper2, true);
    XFuture<Void> fut3 = mockChannel.sendToSvrAsync(data2);
    Assert.assertFalse(fut.isDone());
    Assert.assertFalse(fut2.isDone());
    Assert.assertFalse(fut3.isDone());
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    HttpResponse resp1 = Requests.createResponse(1);
    resp1.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
    Http2Response headers1 = Http11ToHttp2.responseToHeaders(resp1);
    in1.stream.process(headers1);
    HttpPayload payload = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp1, payload);
    fut.get(2, TimeUnit.SECONDS);
    fut2.get(2, TimeUnit.SECONDS);
    fut3.get(2, TimeUnit.SECONDS);
    PassedIn in2 = mockListener.getSingleRequest();
    HttpResponse resp2 = Requests.createResponse(2);
    resp2.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
    Http2Response headers2 = Http11ToHttp2.responseToHeaders(resp2);
    in2.stream.process(headers2);
    HttpPayload payload2 = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp2, payload2);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataWrapper(org.webpieces.data.api.DataWrapper) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Header(org.webpieces.httpparser.api.common.Header) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) HttpData(org.webpieces.httpparser.api.dto.HttpData) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 4 with PassedIn

use of org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn in project webpieces by deanhiller.

the class TestHttp11Basic method testFileDownloadWithChunking.

@Test
public void testFileDownloadWithChunking() throws InterruptedException, ExecutionException, TimeoutException {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    mockChannel.sendToSvr(req);
    PassedIn in1 = mockListener.getSingleRequest();
    HttpRequest req1 = Http2ToHttp11.translateRequest(in1.request);
    Assert.assertEquals(req, req1);
    HttpResponse resp = Requests.createResponse();
    resp.addHeader(new Header(KnownHeaderName.TRANSFER_ENCODING, "chunked"));
    Http2Response headers = Http11ToHttp2.responseToHeaders(resp);
    XFuture<StreamWriter> future = in1.stream.process(headers);
    HttpResponse respToClient = (HttpResponse) mockChannel.getFrameAndClear();
    Assert.assertEquals(resp, respToClient);
    StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    DataFrame dataFrame = new DataFrame();
    dataFrame.setEndOfStream(true);
    String bodyStr = "hi here and there";
    DataWrapper data = DATA_GEN.wrapByteArray(bodyStr.getBytes(StandardCharsets.UTF_8));
    dataFrame.setData(data);
    writer.processPiece(dataFrame);
    List<HttpPayload> frames = mockChannel.getFramesAndClear();
    Assert.assertEquals(2, frames.size());
    HttpData chunk = (HttpData) frames.get(0);
    DataWrapper body = chunk.getBodyNonNull();
    String result = body.createStringFromUtf8(0, body.getReadableSize());
    Assert.assertEquals(bodyStr, result);
    HttpLastData last = (HttpLastData) frames.get(1);
    Assert.assertEquals(0, last.getBodyNonNull().getReadableSize());
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) HttpLastData(org.webpieces.httpparser.api.dto.HttpLastData) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) DataWrapper(org.webpieces.data.api.DataWrapper) Header(org.webpieces.httpparser.api.common.Header) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) HttpData(org.webpieces.httpparser.api.dto.HttpData) Test(org.junit.Test)

Example 5 with PassedIn

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, TimeoutException {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    HttpRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    mockChannel.sendToSvr(req);
    PassedIn in1 = mockListener.getSingleRequest();
    XFuture<Void> future = mockChannel.sendToSvrAsync(req2);
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    Assert.assertFalse(future.isDone());
    // 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 = Http11ToHttp2.responseToHeaders(resp1);
    in1.stream.process(headers1);
    HttpPayload payload = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp1, payload);
    future.get(2, TimeUnit.SECONDS);
    PassedIn in2 = mockListener.getSingleRequest();
    HttpResponse resp2 = Requests.createResponse(2);
    resp2.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
    Http2Response headers2 = Http11ToHttp2.responseToHeaders(resp2);
    in2.stream.process(headers2);
    HttpPayload payload2 = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp2, payload2);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Header(org.webpieces.httpparser.api.common.Header) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Aggregations

PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)24 Test (org.junit.Test)20 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)16 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)13 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)12 Header (org.webpieces.httpparser.api.common.Header)11 DataWrapper (org.webpieces.data.api.DataWrapper)10 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)9 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)9 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)9 HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)8 MockStreamRef (org.webpieces.httpfrontend2.api.mock2.MockStreamRef)6 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)6 HttpData (org.webpieces.httpparser.api.dto.HttpData)6 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)5 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)3 ResponseStream (org.webpieces.frontend2.api.ResponseStream)3 Http2Request (com.webpieces.hpack.api.dto.Http2Request)2 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)2 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)2