Search in sources :

Example 16 with Http2Request

use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.

the class TestS4FrameSizeAndHeaders 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.
	 * @throws TimeoutException 
	 * @throws ExecutionException 
	 * @throws InterruptedException 
	 */
@Test
public void testSection4_2FrameTooLarge() throws InterruptedException, ExecutionException, TimeoutException {
    int streamId = 1;
    PassedIn info = sendRequestToServer(streamId, false);
    ResponseStream stream = info.stream;
    Http2Request request = info.request;
    //send data that goes with request
    DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
    byte[] buf = new byte[localSettings.getMaxFrameSize() + 4];
    dataFrame.setData(dataGen.wrapByteArray(buf));
    //endOfStream=false
    mockChannel.send(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());
    Cancel failResp = mockListener.getCancelInfo();
    ShutdownStream reset = (ShutdownStream) failResp.reset;
    Assert.assertEquals(CancelReasonCode.EXCEEDED_MAX_FRAME_SIZE, reset.getCause().getReasonCode());
    //send response with request not complete but failed as well anyways
    Http2Response response = Http2Requests.createResponse(request.getStreamId());
    CompletableFuture<StreamWriter> future = stream.sendResponse(response);
    ConnectionClosedException intercept = (ConnectionClosedException) TestAssert.intercept(future);
    Assert.assertTrue(intercept.getMessage().contains("Connection closed or closing"));
    Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Cancel(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.Cancel) StreamWriter(com.webpieces.http2engine.api.StreamWriter) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) ResponseStream(org.webpieces.frontend2.api.ResponseStream) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) DataWrapper(org.webpieces.data.api.DataWrapper) ShutdownStream(com.webpieces.http2engine.api.error.ShutdownStream) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Test(org.junit.Test)

Example 17 with Http2Request

use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.

the class TestS5_1StreamStates method testSection5_1_1TooLowStreamIdAfterHighStreamId.

/**
	 * The identifier of a newly established stream MUST be numerically 
	 * greater than all streams that the initiating endpoint has opened 
	 * or reserved. This governs streams that are opened using a HEADERS 
	 * frame and streams that are reserved using PUSH_PROMISE. An endpoint 
	 * that receives an unexpected stream identifier MUST respond with 
	 * a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
	 * 
	 * This is in conflict with another part of the spec!!!!! and so we pretend
	 * the stream is closed(as in all likely hood, the stream was closed)!!!
	 * and do not shutdown the whole connection for a case like this.
	 * 
	 * The part it is in conflict with is closed state and receiving messages
	 * in closed state.  The only way to resolve conflict would be to KEEP around
	 * state that a connection is closed.  SORRY, the connection is closed so we
	 * clean up all memory!!!
	 */
@Test
public void testSection5_1_1TooLowStreamIdAfterHighStreamId() {
    Http2Request request1 = Http2Requests.createRequest(5, true);
    mockChannel.send(request1);
    mockListener.getSingleRequest();
    Http2Request request = Http2Requests.createRequest(3, true);
    mockChannel.send(request);
    //WE DO NOT DO THIS which spec wants(or another test we have starts failing)
    //we leave this here in case you want to comment back in and debug that.
    //		//no request comes in
    //		Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    //		//cancel the first stream since whole connection is going down.
    //		Assert.assertEquals(1, 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("Bad stream id.  Event stream ids not allowed in requests to a server frame="));
    //		Assert.assertTrue(mockChannel.isClosed());
    //no request comes in
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    //no cancels(since we already cancelled it)
    Assert.assertEquals(0, mockListener.getNumCancelsThatCameIn());
    //remote receives goAway
    RstStreamFrame frame = (RstStreamFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.STREAM_CLOSED, frame.getKnownErrorCode());
    Assert.assertTrue(!mockChannel.isClosed());
}
Also used : Http2Request(com.webpieces.hpack.api.dto.Http2Request) RstStreamFrame(com.webpieces.http2parser.api.dto.RstStreamFrame) Test(org.junit.Test)

Example 18 with Http2Request

use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.

the class AbstractHttp2Test method sendRequestToServer.

protected PassedIn sendRequestToServer(int streamId, boolean eos) {
    Http2Request request1 = Http2Requests.createRequest(streamId, eos);
    mockChannel.send(request1);
    PassedIn req = mockListener.getSingleRequest();
    Assert.assertEquals(request1, req.request);
    return req;
}
Also used : Http2Request(com.webpieces.hpack.api.dto.Http2Request) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)

Example 19 with Http2Request

use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.

the class TestSBasicRequestResponse method testPushPromise.

@Test
public void testPushPromise() throws InterruptedException, ExecutionException, TimeoutException {
    Http2Request request1 = Http2Requests.createRequest(1, true);
    mockChannel.send(request1);
    PassedIn incoming = mockListener.getSingleRequest();
    Assert.assertEquals(request1, incoming.request);
    Http2Push push = Http2Requests.createPush(request1.getStreamId());
    CompletableFuture<PushPromiseListener> future = incoming.stream.openPushStream().process(push);
    PushPromiseListener pushWriter = future.get(2, TimeUnit.SECONDS);
    Http2Push pushRecv = (Http2Push) mockChannel.getFrameAndClear();
    Assert.assertEquals(push, pushRecv);
    Http2Response preEmptive = Http2Requests.createResponse(push.getPromisedStreamId());
    pushWriter.processPushResponse(preEmptive);
    Http2Headers preEmptRecv = (Http2Headers) mockChannel.getFrameAndClear();
    Assert.assertEquals(preEmptive, preEmptRecv);
    Http2Response response = Http2Requests.createResponse(request1.getStreamId());
    incoming.stream.sendResponse(response);
    Http2Headers responseRecv = (Http2Headers) mockChannel.getFrameAndClear();
    Assert.assertEquals(response, responseRecv);
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) PushPromiseListener(com.webpieces.http2engine.api.PushPromiseListener) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Http2Headers(com.webpieces.hpack.api.dto.Http2Headers) Http2Push(com.webpieces.hpack.api.dto.Http2Push) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 20 with Http2Request

use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.

the class TestSBasicRequestResponse method testWithNoData.

@Test
public void testWithNoData() throws InterruptedException, ExecutionException, TimeoutException {
    Http2Request request1 = Http2Requests.createRequest(1, true);
    mockChannel.send(request1);
    PassedIn incoming = mockListener.getSingleRequest();
    Assert.assertEquals(request1, incoming.request);
    Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), true);
    incoming.stream.sendResponse(resp);
    Http2Msg response = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp, response);
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Aggregations

Http2Request (com.webpieces.hpack.api.dto.Http2Request)31 Test (org.junit.Test)22 StreamWriter (com.webpieces.http2engine.api.StreamWriter)13 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)13 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)12 DataWrapper (org.webpieces.data.api.DataWrapper)11 Http2Response (com.webpieces.hpack.api.dto.Http2Response)10 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)10 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)9 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)9 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)7 Http2Push (com.webpieces.hpack.api.dto.Http2Push)5 ConnectionClosedException (com.webpieces.http2engine.api.ConnectionClosedException)5 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)5 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)4 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)4 PushPromiseListener (com.webpieces.http2engine.api.PushPromiseListener)3 CancelReason (com.webpieces.http2parser.api.dto.CancelReason)3 InetSocketAddress (java.net.InetSocketAddress)3 ArrayList (java.util.ArrayList)3