use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class HeadersMarshaller method marshal.
@Override
public DataWrapper marshal(Http2Frame frame) {
HeadersFrame castFrame = (HeadersFrame) frame;
if (frame.getStreamId() == 0)
throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "Headers frame cannot be streamId 0");
int paddingSize = castFrame.getPadding().getReadableSize();
byte value = 0x0;
if (castFrame.isEndOfStream())
value |= 0x1;
if (castFrame.isEndHeaders())
value |= 0x4;
if (paddingSize > 0)
value |= 0x8;
if (castFrame.isPriority())
value |= 0x20;
DataWrapper preludeDW;
PriorityDetails priorityDetails = castFrame.getPriorityDetails();
if (priorityDetails != null) {
preludeDW = PriorityMarshaller.marshalPriorityDetails(bufferPool, priorityDetails, frame);
} else {
preludeDW = DATA_GEN.emptyWrapper();
}
DataWrapper unpadded = DATA_GEN.chainDataWrappers(preludeDW, castFrame.getHeaderFragment());
DataWrapper payload = PaddingUtil.padDataIfNeeded(unpadded, castFrame.getPadding());
return super.marshalFrame(frame, value, payload);
}
use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class SettingsMarshaller method validateMaxFrameSize.
private void validateMaxFrameSize(long value) {
// frame size must be between 16384 and 2^24 - 1
int min = 16384;
int max = 1677215;
if (value < min || value > max)
throw new ConnectionException(CancelReasonCode.INVALID_SETTING, 0, "window size must be between " + min + " and " + max + " but was=" + value);
}
use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class SettingsMarshaller method validateWindowSize.
private void validateWindowSize(long value) {
// 2^31 - 1 - max flow control window
int min = 0;
int max = 2147483647;
if (value < min || value > max)
throw new ConnectionException(CancelReasonCode.SETTINGS_WINDOW_SIZE_INVALID, 0, "window size must be between " + min + " and " + max + " but was=" + value);
}
use of com.webpieces.http2.api.dto.error.ConnectionException 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());
}
use of com.webpieces.http2.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class TestS5x1StreamStates method testSection5_1BadFrameReceivedInReservedRemoteState.
/**
* reserved local
*
* A PRIORITY or WINDOW_UPDATE frame MAY be received in this state. Receiving any
* type of frame other than RST_STREAM, PRIORITY, or WINDOW_UPDATE 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_1BadFrameReceivedInReservedRemoteState() {
MockStreamWriter mockWriter = new MockStreamWriter();
XFuture<StreamWriter> futA = XFuture.completedFuture(mockWriter);
MockStreamRef mockStream = new MockStreamRef(futA);
mockListener.addMockStreamToReturn(mockStream);
Http2Request request = Http2Requests.createRequest(1, true);
mockChannel.send(request);
PassedIn in = mockListener.getSingleRequest();
ResponseStream stream = in.stream;
Http2Push push = Http2Requests.createPush(request.getStreamId());
stream.openPushStream().process(push);
Http2Msg pushMsg = mockChannel.getFrameAndClear();
Assert.assertEquals(push, pushMsg);
// send bad frame in this state
DataFrame data = Http2Requests.createData1(push.getPromisedStreamId(), false);
mockChannel.send(data);
Assert.assertTrue(mockStream.isCancelled());
// 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]:stream2:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "No transition defined on statemachine for event=RECV_DATA when in state=Reserved(local)", msg);
Assert.assertTrue(mockChannel.isClosed());
}
Aggregations