Search in sources :

Example 6 with DataFrame

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

the class TestS5_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);
    mockChannel.send(dataFrame);
    //no request comes in
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    //no cancels
    Assert.assertEquals(0, 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.assertEquals("ConnectionException: HttpSocket[Http2ChannelCache1]: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());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) Test(org.junit.Test)

Example 7 with DataFrame

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

the class Http2Translations method translateData.

public static DataFrame translateData(HttpData payload) {
    DataFrame frame = new DataFrame();
    frame.setEndOfStream(payload.isEndOfData());
    frame.setData(payload.getBodyNonNull());
    return frame;
}
Also used : DataFrame(com.webpieces.http2parser.api.dto.DataFrame)

Example 8 with DataFrame

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

the class Http2Translations method translateBody.

public static DataFrame translateBody(DataWrapper body) {
    DataFrame data = new DataFrame();
    data.setData(body);
    data.setEndOfStream(true);
    return data;
}
Also used : DataFrame(com.webpieces.http2parser.api.dto.DataFrame)

Example 9 with DataFrame

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

the class Http2Translations method translateChunk.

private static Http2Msg translateChunk(HttpChunk payload, boolean eos) {
    DataFrame frame = new DataFrame();
    frame.setData(payload.getBodyNonNull());
    frame.setEndOfStream(eos);
    return frame;
}
Also used : DataFrame(com.webpieces.http2parser.api.dto.DataFrame)

Example 10 with DataFrame

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

the class TestC5_1StreamStates method testSection5_1ReceiveBadFrameAfterReceiveEndStream.

/**
	 * An endpoint MUST NOT send frames other than PRIORITY on a closed stream. An endpoint 
	 * that receives any frame other than PRIORITY after receiving a RST_STREAM MUST 
	 * treat that as a stream error (Section 5.4.2) of type STREAM_CLOSED. Similarly, an 
	 * endpoint that receives any frames after receiving a frame with the 
	 * -----END_STREAM flag---- set MUST treat that as a connection error (Section 5.4.1) of 
	 * type STREAM_CLOSED, unless the frame is permitted as described below.
	 * 
	 */
@Test
public void testSection5_1ReceiveBadFrameAfterReceiveEndStream() {
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(null));
    Http2Request request = sendRequestToServer(listener1);
    sendEosResponseFromServer(listener1, request);
    DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
    mockChannel.write(dataFrame);
    //remote receives goAway
    GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(Http2ErrorCode.STREAM_CLOSED, goAway.getKnownErrorCode());
    DataWrapper debugData = goAway.getDebugData();
    String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
    Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream1:" + "(CLOSED_STREAM) Stream must have been closed as it no longer exists.  " + "high mark=1  your frame=DataFrame{streamId=1, endStream=false, data.len=0, padding=0}", msg);
    Assert.assertTrue(mockChannel.isClosed());
    Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
    //send new request on closed connection
    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)

Aggregations

DataFrame (com.webpieces.http2parser.api.dto.DataFrame)16 DataWrapper (org.webpieces.data.api.DataWrapper)11 Http2Request (com.webpieces.hpack.api.dto.Http2Request)7 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)6 Test (org.junit.Test)6 StreamWriter (com.webpieces.http2engine.api.StreamWriter)4 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)4 ConnectionClosedException (com.webpieces.http2engine.api.ConnectionClosedException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)3 Http2Push (com.webpieces.hpack.api.dto.Http2Push)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ResponseStream (org.webpieces.frontend2.api.ResponseStream)2 Http2Response (com.webpieces.hpack.api.dto.Http2Response)1 Http2Trailers (com.webpieces.hpack.api.dto.Http2Trailers)1 StreamHandle (com.webpieces.http2engine.api.StreamHandle)1 Http2ClientEngine (com.webpieces.http2engine.api.client.Http2ClientEngine)1 Http2ClientEngineFactory (com.webpieces.http2engine.api.client.Http2ClientEngineFactory)1