use of com.webpieces.http2parser.api.dto.GoAwayFrame in project webpieces by deanhiller.
the class TestC5_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);
//endOfStream=false
mockChannel.write(dataFrame);
//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: MockHttp2Channel1: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());
//send new request on closed connection
MockResponseListener listener1 = new MockResponseListener();
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());
}
use of com.webpieces.http2parser.api.dto.GoAwayFrame in project webpieces by deanhiller.
the class TestC6_5SettingsFrameErrors method testSection6_5AckNonEmptyPayload.
@Test
public void testSection6_5AckNonEmptyPayload() {
//server's settings frame is finally coming in as well with maxConcurrent=1
HeaderSettings settings = new HeaderSettings();
settings.setMaxConcurrentStreams(1L);
mockChannel.write(HeaderSettings.createSettingsFrame(settings));
//clear the ack frame
mockChannel.getFrameAndClear();
String badAckFrame = // length
"00 00 01" + // type
"04" + // flags (ack)
"01" + // R + streamid
"00 00 00 00" + //payload
"00";
//ack client frame
mockChannel.writeHexBack(badAckFrame);
//remote receives goAway
GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
DataWrapper debugData = goAway.getDebugData();
String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
Assert.assertEquals("ConnectionException: stream0:(FRAME_SIZE_INCORRECT) size of payload of a settings frame ack must be 0 but was=1", msg);
Assert.assertTrue(mockChannel.isClosed());
}
use of com.webpieces.http2parser.api.dto.GoAwayFrame in project webpieces by deanhiller.
the class TestC6_5SettingsFrameErrors method testSection6_5_2InitialWindowSizeTooLarge.
@Test
public void testSection6_5_2InitialWindowSizeTooLarge() {
//server's settings frame is finally coming in as well with maxConcurrent=1
String badStreamIdSettings = // length
"00 00 0C" + // type
"04" + //flags
"00" + //R + streamid
"00 00 00 00" + //setting 1 (enable push)
"00 02 00 00 00 01" + //setting 2 (initial window size)
"00 04 FF FF FF FF";
mockChannel.writeHexBack(badStreamIdSettings);
//remote receives goAway
GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(Http2ErrorCode.FLOW_CONTROL_ERROR, goAway.getKnownErrorCode());
Assert.assertTrue(mockChannel.isClosed());
}
use of com.webpieces.http2parser.api.dto.GoAwayFrame in project webpieces by deanhiller.
the class Level7MarshalAndPing method goAway.
public CompletableFuture<Void> goAway(ShutdownConnection shutdown) {
CancelReasonCode reason = shutdown.getReasonCode();
byte[] bytes = shutdown.getReason().getBytes(StandardCharsets.UTF_8);
DataWrapper debug = dataGen.wrapByteArray(bytes);
GoAwayFrame frame = new GoAwayFrame();
frame.setDebugData(debug);
frame.setKnownErrorCode(reason.getErrorCode());
CompletableFuture<Void> future1 = sendControlDataToSocket(frame);
finalLayer.closeSocket(shutdown);
return future1;
}
use of com.webpieces.http2parser.api.dto.GoAwayFrame in project webpieces by deanhiller.
the class GoAwayMarshaller method unmarshal.
@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
GoAwayFrame frame = new GoAwayFrame();
super.unmarshalFrame(state, frame);
int streamId = state.getFrameHeaderData().getStreamId();
if (streamId != 0)
throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, streamId, "goaway frame had stream id=" + streamId);
List<? extends DataWrapper> split = dataGen.split(framePayloadData, 8);
ByteBuffer preludeBytes = bufferPool.createWithDataWrapper(split.get(0));
long lastStreamId = UnsignedData.getUnsignedInt(preludeBytes);
long errorCode = UnsignedData.getUnsignedInt(preludeBytes);
frame.setLastStreamId(lastStreamId);
frame.setErrorCode(errorCode);
frame.setDebugData(split.get(1));
bufferPool.releaseBuffer(preludeBytes);
if (frame.getStreamId() != 0)
throw new IllegalArgumentException("GoAwayFrame can never be any other stream id except 0 which is already set");
return frame;
}
Aggregations