Search in sources :

Example 11 with DataFrame

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

the class TestHttp2Data method testParseEndOfStreamTrue.

@Test
public void testParseEndOfStreamTrue() {
    DataWrapper data = Util.hexToBytes(endStreamDataFrame());
    parser.parse(memento, data);
    DataFrame frame = (DataFrame) assertGood();
    Assert.assertEquals(1, frame.getStreamId());
    Assert.assertEquals(8, frame.getData().getReadableSize());
    Assert.assertEquals(0, frame.getPadding().getReadableSize());
    Assert.assertTrue(frame.isEndOfStream());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Test(org.junit.Test)

Example 12 with DataFrame

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

the class TestHttp2Data method testMarshalDataFrameUnpadded.

@Test
public void testMarshalDataFrameUnpadded() {
    DataFrame frame = new DataFrame();
    frame.setData(Util.hexToBytes("FF FF FF FF FF FF FF FF"));
    frame.setStreamId(1);
    byte[] data = parser.marshal(frame).createByteArray();
    String hexFrame = Util.toHexString(data);
    Assert.assertEquals(unpaddedDataFrame(), hexFrame);
}
Also used : DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Test(org.junit.Test)

Example 13 with DataFrame

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

the class TestHttp2Data method testMarshalDataFramePaddedEndStream.

@Test
public void testMarshalDataFramePaddedEndStream() {
    DataFrame frame = new DataFrame();
    frame.setData(Util.hexToBytes("FF FF FF FF FF FF FF FF"));
    frame.setStreamId(1);
    frame.setEndOfStream(true);
    frame.setPadding(Util.hexToBytes("00 00"));
    byte[] data = parser.marshal(frame).createByteArray();
    String hexFrame = Util.toHexString(data);
    Assert.assertEquals(paddedEndStreamDataFrame(), hexFrame);
}
Also used : DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Test(org.junit.Test)

Example 14 with DataFrame

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

the class ChunkedStream method writeDataOut.

private void writeDataOut() {
    byte[] data = str.toByteArray();
    str = new ByteArrayOutputStream();
    DataWrapper body = wrapperFactory.wrapByteArray(data);
    DataFrame frame = new DataFrame();
    frame.setEndOfStream(false);
    frame.setData(body);
    cache.add(frame);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame)

Example 15 with DataFrame

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

the class TestS5x1StreamStates 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());
    Assert.assertTrue(mockListener.isClosed());
    // 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.http2.api.dto.lowlevel.DataFrame) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Aggregations

DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)52 Test (org.junit.Test)31 DataWrapper (org.webpieces.data.api.DataWrapper)28 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)19 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)13 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)11 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)9 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)9 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)8 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)8 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)7 StreamRef (com.webpieces.http2.api.streaming.StreamRef)6 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)6 ConnectionClosedException (com.webpieces.http2engine.api.error.ConnectionClosedException)5 Header (org.webpieces.httpparser.api.common.Header)5 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)4 HttpData (org.webpieces.httpparser.api.dto.HttpData)4 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)4 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)3 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)3