Search in sources :

Example 1 with Http2Msg

use of com.webpieces.http2parser.api.dto.lib.Http2Msg in project webpieces by deanhiller.

the class TestC5_1StreamStates method testSection5_1ReceiveValidFramesAfterSendRstStreamFrame.

/**
	 * If this state is reached as a result of sending a RST_STREAM frame, the 
	 * peer that receives the RST_STREAM might have already sent — or enqueued for 
	 * sending — frames on the stream that cannot be withdrawn. An endpoint MUST ignore 
	 * frames that it receives on closed streams after it has sent a RST_STREAM frame. An 
	 * endpoint MAY choose to limit the period over which it ignores frames and 
	 * treat frames that arrive after this time as being in error.
	 * @throws TimeoutException 
	 * @throws ExecutionException 
	 * @throws InterruptedException 
	 */
@Test
public void testSection5_1ReceiveValidFramesAfterSendRstStreamFrame() throws InterruptedException, ExecutionException, TimeoutException {
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(null));
    Http2Request request1 = Requests.createRequest();
    StreamHandle stream = httpSocket.openStream();
    CompletableFuture<StreamWriter> future = stream.process(request1, listener1);
    @SuppressWarnings("unused") StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    Http2Msg req = mockChannel.getFrameAndClear();
    Assert.assertEquals(request1, req);
    RstStreamFrame rst = new RstStreamFrame(request1.getStreamId(), Http2ErrorCode.CANCEL);
    CompletableFuture<Void> cancel = stream.cancel(rst);
    cancel.get(2, TimeUnit.SECONDS);
    Http2Msg svrRst = mockChannel.getFrameAndClear();
    Assert.assertEquals(rst, svrRst);
    //simulate server responding before receiving the cancel
    Http2Response resp1 = Requests.createEosResponse(request1.getStreamId());
    //endOfStream=true
    mockChannel.write(resp1);
//		Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
//		Assert.assertFalse(mockChannel.isClosed());
//		
//		Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Request(com.webpieces.hpack.api.dto.Http2Request) RstStreamFrame(com.webpieces.http2parser.api.dto.RstStreamFrame) StreamHandle(com.webpieces.http2engine.api.StreamHandle) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) Test(org.junit.Test)

Example 2 with Http2Msg

use of com.webpieces.http2parser.api.dto.lib.Http2Msg in project webpieces by deanhiller.

the class AbstractHttp2Test method simulateClientSendingPrefaceAndSettings.

protected void simulateClientSendingPrefaceAndSettings() {
    //this method is overloaded by one test
    HeaderSettings settings = Http2Requests.createSomeSettings();
    mockChannel.sendPrefaceAndSettings(HeaderSettings.createSettingsFrame(settings));
    List<Http2Msg> frames = mockChannel.getFramesAndClear();
    Assert.assertEquals(2, frames.size());
}
Also used : HeaderSettings(com.webpieces.http2engine.impl.shared.data.HeaderSettings) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg)

Example 3 with Http2Msg

use of com.webpieces.http2parser.api.dto.lib.Http2Msg 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 4 with Http2Msg

use of com.webpieces.http2parser.api.dto.lib.Http2Msg in project webpieces by deanhiller.

the class HpackParserImpl method processFrame.

private void processFrame(UnmarshalStateImpl state, Http2Frame frame) {
    List<HasHeaderFragment> headerFragList = state.getHeadersToCombine();
    if (frame instanceof HasHeaderFragment) {
        HasHeaderFragment headerFrame = (HasHeaderFragment) frame;
        headerFragList.add(headerFrame);
        validateHeader(state, headerFrame);
        if (headerFrame.isEndHeaders())
            combineAndSendHeadersToClient(state);
        return;
    } else if (headerFragList.size() > 0) {
        throw new ConnectionException(CancelReasonCode.HEADERS_MIXED_WITH_FRAMES, state.getLogId(), frame.getStreamId(), "Parser in the middle of accepting headers(spec " + "doesn't allow frames between header fragments).  frame=" + frame + " list=" + headerFragList);
    }
    if (frame instanceof UnknownFrame && ignoreUnkownFrames) {
    //do nothing
    } else if (frame instanceof Http2Msg) {
        state.getParsedFrames().add((Http2Msg) frame);
    } else {
        throw new IllegalStateException("bug forgot support for frame=" + frame);
    }
}
Also used : HasHeaderFragment(com.webpieces.http2parser.api.dto.lib.HasHeaderFragment) UnknownFrame(com.webpieces.http2parser.api.dto.UnknownFrame) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Aggregations

Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)4 Http2Request (com.webpieces.hpack.api.dto.Http2Request)2 Test (org.junit.Test)2 Http2Push (com.webpieces.hpack.api.dto.Http2Push)1 Http2Response (com.webpieces.hpack.api.dto.Http2Response)1 StreamHandle (com.webpieces.http2engine.api.StreamHandle)1 StreamWriter (com.webpieces.http2engine.api.StreamWriter)1 HeaderSettings (com.webpieces.http2engine.impl.shared.data.HeaderSettings)1 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)1 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)1 RstStreamFrame (com.webpieces.http2parser.api.dto.RstStreamFrame)1 UnknownFrame (com.webpieces.http2parser.api.dto.UnknownFrame)1 ConnectionException (com.webpieces.http2parser.api.dto.error.ConnectionException)1 HasHeaderFragment (com.webpieces.http2parser.api.dto.lib.HasHeaderFragment)1 DataWrapper (org.webpieces.data.api.DataWrapper)1 ResponseStream (org.webpieces.frontend2.api.ResponseStream)1 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)1 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)1 Cancel (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.Cancel)1 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)1