Search in sources :

Example 21 with GoAwayFrame

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

the class TestC5_1StreamStates method testSection5_1BadFrameReceivedInIdleState.

/**
	 * Receiving any frame other than HEADERS or PRIORITY 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_1BadFrameReceivedInIdleState() {
    DataFrame dataFrame = new DataFrame(1, false);
    //endOfStream=false
    mockChannel.write(dataFrame);
    //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: MockHttp2Channel1:stream1:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "Stream in idle state and received this frame which should not happen in " + "idle state.  frame=DataFrame{streamId=1, endStream=false, data.len=0, padding=0}", msg);
    Assert.assertTrue(mockChannel.isClosed());
    //send new request on closed connection
    MockResponseListener listener1 = new MockResponseListener();
    Http2Request request1 = Requests.createRequest();
    CompletableFuture<StreamWriter> future = httpSocket.openStream().process(request1, listener1);
    ConnectionClosedException intercept = (ConnectionClosedException) TestAssert.intercept(future);
    Assert.assertTrue(intercept.getMessage().contains("Connection closed or closing"));
    Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Http2Request(com.webpieces.hpack.api.dto.Http2Request) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 22 with GoAwayFrame

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

the class TestC6_5SettingsFrameErrors method testSection6_5AckNonEmptyPayload.

@Test
public void testSection6_5AckNonEmptyPayload() {
    //server's settings frame is finally coming in as well with maxConcurrent=1
    HeaderSettings settings = new HeaderSettings();
    settings.setMaxConcurrentStreams(1L);
    mockChannel.write(HeaderSettings.createSettingsFrame(settings));
    //clear the ack frame 
    mockChannel.getFrameAndClear();
    String badAckFrame = // length
    "00 00 01" + // type
    "04" + // flags (ack)
    "01" + // R + streamid
    "00 00 00 00" + //payload 
    "00";
    //ack client frame
    mockChannel.writeHexBack(badAckFrame);
    //remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: stream0:(FRAME_SIZE_INCORRECT) size of payload of a settings frame ack must be 0 but was=1", msg);
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HeaderSettings(com.webpieces.http2engine.impl.shared.data.HeaderSettings) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 23 with GoAwayFrame

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

the class TestC6_5SettingsFrameErrors method testSection6_5_2InitialWindowSizeTooLarge.

@Test
public void testSection6_5_2InitialWindowSizeTooLarge() {
    //server's settings frame is finally coming in as well with maxConcurrent=1
    String badStreamIdSettings = // length
    "00 00 0C" + // type
    "04" + //flags
    "00" + //R + streamid
    "00 00 00 00" + //setting 1 (enable push)
    "00 02 00 00 00 01" + //setting 2 (initial window size)
    "00 04 FF FF FF FF";
    mockChannel.writeHexBack(badStreamIdSettings);
    //remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.FLOW_CONTROL_ERROR, goAway.getKnownErrorCode());
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 24 with GoAwayFrame

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

the class Level7MarshalAndPing method goAway.

public CompletableFuture<Void> goAway(ShutdownConnection shutdown) {
    CancelReasonCode reason = shutdown.getReasonCode();
    byte[] bytes = shutdown.getReason().getBytes(StandardCharsets.UTF_8);
    DataWrapper debug = dataGen.wrapByteArray(bytes);
    GoAwayFrame frame = new GoAwayFrame();
    frame.setDebugData(debug);
    frame.setKnownErrorCode(reason.getErrorCode());
    CompletableFuture<Void> future1 = sendControlDataToSocket(frame);
    finalLayer.closeSocket(shutdown);
    return future1;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) CancelReasonCode(com.webpieces.http2parser.api.dto.error.CancelReasonCode) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame)

Example 25 with GoAwayFrame

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

the class GoAwayMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    GoAwayFrame frame = new GoAwayFrame();
    super.unmarshalFrame(state, frame);
    int streamId = state.getFrameHeaderData().getStreamId();
    if (streamId != 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, streamId, "goaway frame had stream id=" + streamId);
    List<? extends DataWrapper> split = dataGen.split(framePayloadData, 8);
    ByteBuffer preludeBytes = bufferPool.createWithDataWrapper(split.get(0));
    long lastStreamId = UnsignedData.getUnsignedInt(preludeBytes);
    long errorCode = UnsignedData.getUnsignedInt(preludeBytes);
    frame.setLastStreamId(lastStreamId);
    frame.setErrorCode(errorCode);
    frame.setDebugData(split.get(1));
    bufferPool.releaseBuffer(preludeBytes);
    if (frame.getStreamId() != 0)
        throw new IllegalArgumentException("GoAwayFrame can never be any other stream id except 0 which is already set");
    return frame;
}
Also used : ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame)

Aggregations

GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)26 Test (org.junit.Test)23 DataWrapper (org.webpieces.data.api.DataWrapper)17 Http2Request (com.webpieces.hpack.api.dto.Http2Request)10 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)8 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)7 ConnectionClosedException (com.webpieces.http2engine.api.ConnectionClosedException)5 StreamWriter (com.webpieces.http2engine.api.StreamWriter)5 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)5 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)5 Http2Push (com.webpieces.hpack.api.dto.Http2Push)2 Http2Frame (com.webpieces.http2parser.api.dto.lib.Http2Frame)2 ByteBuffer (java.nio.ByteBuffer)2 ResponseStream (org.webpieces.frontend2.api.ResponseStream)2 Cancel (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.Cancel)2 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)2 Http2Response (com.webpieces.hpack.api.dto.Http2Response)1 HeaderSettings (com.webpieces.http2engine.impl.shared.data.HeaderSettings)1 CancelReason (com.webpieces.http2parser.api.dto.CancelReason)1 CancelReasonCode (com.webpieces.http2parser.api.dto.error.CancelReasonCode)1