Search in sources :

Example 1 with PriorityFrame

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

the class TestS4FrameSizeAndHeaders method testBadSizePriorityFrame.

/**
 *  A decoding error in a header block MUST be treated as a connection error (Section 5.4.1) of type COMPRESSION_ERROR.
 */
@Test
public void testBadSizePriorityFrame() {
    String priorityFrame = // length
    "00 00 06" + // type
    "02" + // flags
    "00" + // R + streamid
    "00 00 00 01" + // stream dependency
    "80 00 00 04" + // weight
    "05 00";
    // endOfStream=false
    mockChannel.sendHexBack(priorityFrame);
    // no request comes in
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    Assert.assertTrue(mockListener.isClosed());
    // 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:(FRAME_SIZE_INCORRECT) priority size not 5 and instead is=6", msg);
    Assert.assertTrue(mockChannel.isClosed());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) GoAwayFrame(com.webpieces.http2.api.dto.lowlevel.GoAwayFrame) Test(org.junit.Test)

Example 2 with PriorityFrame

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

the class TestHttp2Priority method testParsePriorityFrame.

@Test
public void testParsePriorityFrame() {
    DataWrapper data = Util.hexToBytes(priorityFrame());
    parser.parse(memento, data);
    PriorityFrame frame = (PriorityFrame) assertGood();
    Assert.assertEquals(1, frame.getStreamId());
    PriorityDetails details = frame.getPriorityDetails();
    Assert.assertTrue(details.isStreamDependencyIsExclusive());
    Assert.assertEquals(5, details.getWeight());
    Assert.assertEquals(4, details.getStreamDependency());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PriorityDetails(com.webpieces.http2.api.dto.lowlevel.lib.PriorityDetails) PriorityFrame(com.webpieces.http2.api.dto.lowlevel.PriorityFrame) Test(org.junit.Test)

Example 3 with PriorityFrame

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

the class TestHttp2Priority method testMarshalPriorityFrameMSB.

@Test
public void testMarshalPriorityFrameMSB() {
    PriorityFrame frame = new PriorityFrame();
    frame.setStreamId(1);
    PriorityDetails details = frame.getPriorityDetails();
    details.setStreamDependency(4);
    details.setStreamDependencyIsExclusive(true);
    details.setWeight((short) 0xFF);
    Assert.assertEquals(details.getWeight(), 255);
    byte[] data = parser.marshal(frame).createByteArray();
    String hexFrame = Util.toHexString(data);
    Assert.assertEquals(priorityFrameMSB(), hexFrame);
}
Also used : PriorityDetails(com.webpieces.http2.api.dto.lowlevel.lib.PriorityDetails) PriorityFrame(com.webpieces.http2.api.dto.lowlevel.PriorityFrame) Test(org.junit.Test)

Example 4 with PriorityFrame

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

the class PriorityMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    PriorityFrame castFrame = (PriorityFrame) frame;
    PriorityDetails priorityDetails = castFrame.getPriorityDetails();
    DataWrapper payload = marshalPriorityDetails(bufferPool, priorityDetails, frame);
    return super.marshalFrame(frame, (byte) 0, payload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PriorityDetails(com.webpieces.http2.api.dto.lowlevel.lib.PriorityDetails) PriorityFrame(com.webpieces.http2.api.dto.lowlevel.PriorityFrame)

Example 5 with PriorityFrame

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

the class PriorityMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    FrameHeaderData frameHeaderData = state.getFrameHeaderData();
    int streamId = frameHeaderData.getStreamId();
    if (state.getFrameHeaderData().getPayloadLength() != 5)
        throw new ConnectionException(CancelReasonCode.FRAME_SIZE_INCORRECT, streamId, "priority size not 5 and instead is=" + state.getFrameHeaderData().getPayloadLength());
    PriorityFrame frame = new PriorityFrame();
    PriorityDetails priorityDetails = frame.getPriorityDetails();
    super.unmarshalFrame(state, frame);
    ByteBuffer payloadByteBuffer = bufferPool.createWithDataWrapper(framePayloadData);
    int firstInt = payloadByteBuffer.getInt();
    priorityDetails.setStreamDependencyIsExclusive((firstInt >>> 31) == 0x1);
    int streamDependency = firstInt & 0x7FFFFFFF;
    if (frame.getStreamId() == 0) {
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "priority cannot be streamid 0 and was=" + frame.getStreamId());
    } else if (streamDependency == frame.getStreamId()) {
        // Can't depend on self
        throw new ConnectionException(CancelReasonCode.BAD_STREAM_DEPENDENCY, streamDependency, "stream id=" + streamDependency + " depends on itself");
    }
    priorityDetails.setStreamDependency(streamDependency);
    priorityDetails.setWeight((short) (payloadByteBuffer.get() & 0xFF));
    bufferPool.releaseBuffer(payloadByteBuffer);
    return frame;
}
Also used : FrameHeaderData(com.webpieces.http2parser.impl.FrameHeaderData) PriorityDetails(com.webpieces.http2.api.dto.lowlevel.lib.PriorityDetails) PriorityFrame(com.webpieces.http2.api.dto.lowlevel.PriorityFrame) ByteBuffer(java.nio.ByteBuffer) ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Aggregations

PriorityFrame (com.webpieces.http2.api.dto.lowlevel.PriorityFrame)7 PriorityDetails (com.webpieces.http2.api.dto.lowlevel.lib.PriorityDetails)7 Test (org.junit.Test)6 DataWrapper (org.webpieces.data.api.DataWrapper)4 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)1 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)1 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)1 FrameHeaderData (com.webpieces.http2parser.impl.FrameHeaderData)1 ByteBuffer (java.nio.ByteBuffer)1 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)1