use of com.webpieces.http2parser.api.dto.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);
}
use of com.webpieces.http2parser.api.dto.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());
}
use of com.webpieces.http2parser.api.dto.PriorityFrame in project webpieces by deanhiller.
the class TestC5_1StreamStates method testSection5_1ReceivePriorityAfterReceiveRstStreamFrame.
/**
* 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_1ReceivePriorityAfterReceiveRstStreamFrame() {
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(null));
Http2Request request = sendRequestToServer(listener1);
sendResetFromServer(listener1, request);
PriorityDetails details = new PriorityDetails();
details.setStreamDependency(3);
PriorityFrame dataFrame = new PriorityFrame(request.getStreamId(), details);
mockChannel.write(dataFrame);
//priority is ignored
Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
Assert.assertFalse(mockChannel.isClosed());
Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
}
use of com.webpieces.http2parser.api.dto.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);
}
use of com.webpieces.http2parser.api.dto.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 StreamException(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;
}
Aggregations