use of com.webpieces.http2.api.dto.lowlevel.RstStreamFrame in project webpieces by deanhiller.
the class TestHttp2RstStream method testMarshalRstStream.
@Test
public void testMarshalRstStream() {
RstStreamFrame frame = new RstStreamFrame();
frame.setStreamId(0x4);
frame.setKnownErrorCode(Http2ErrorCode.CONNECT_ERROR);
byte[] data = parser.marshal(frame).createByteArray();
String hexFrame = Util.toHexString(data);
Assert.assertEquals(connectError(), hexFrame);
}
use of com.webpieces.http2.api.dto.lowlevel.RstStreamFrame in project webpieces by deanhiller.
the class TestS5x1StreamStates method testSection5_1_1TooLowStreamIdAfterHighStreamId.
/**
* The identifier of a newly established stream MUST be numerically
* greater than all streams that the initiating endpoint has opened
* or reserved. This governs streams that are opened using a HEADERS
* frame and streams that are reserved using PUSH_PROMISE. An endpoint
* that receives an unexpected stream identifier MUST respond with
* a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
*
* This is in conflict with another part of the spec!!!!! and so we pretend
* the stream is closed(as in all likely hood, the stream was closed)!!!
* and do not shutdown the whole connection for a case like this.
*
* The part it is in conflict with is closed state and receiving messages
* in closed state. The only way to resolve conflict would be to KEEP around
* state that a connection is closed. SORRY, the connection is closed so we
* clean up all memory!!!
*/
@Test
public void testSection5_1_1TooLowStreamIdAfterHighStreamId() {
MockStreamWriter mockWriter = new MockStreamWriter();
XFuture<StreamWriter> futA = XFuture.completedFuture(mockWriter);
MockStreamRef mockStream = new MockStreamRef(futA);
mockListener.addMockStreamToReturn(mockStream);
Http2Request request1 = Http2Requests.createRequest(5, true);
mockChannel.send(request1);
mockListener.getSingleRequest();
Http2Request request = Http2Requests.createRequest(3, true);
mockChannel.send(request);
// WE DO NOT DO THIS which spec wants(or another test we have starts failing)
// we leave this here in case you want to comment back in and debug that.
// //no request comes in
// Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
// //cancel the first stream since whole connection is going down.
// Assert.assertEquals(1, mockListener.getNumCancelsThatCameIn());
//
// //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.assertTrue(msg.contains("Bad stream id. Event stream ids not allowed in requests to a server frame="));
// Assert.assertTrue(mockChannel.isClosed());
// no request comes in
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
// we do not close the channel
Assert.assertFalse(mockListener.isClosed());
// our existing streams stays valid and open
Assert.assertFalse(mockStream.isCancelled());
// remote receives goAway
RstStreamFrame frame = (RstStreamFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(Http2ErrorCode.STREAM_CLOSED, frame.getKnownErrorCode());
Assert.assertTrue(!mockChannel.isClosed());
}
use of com.webpieces.http2.api.dto.lowlevel.RstStreamFrame in project webpieces by deanhiller.
the class DScopedRouter method tryRenderWebAppErrorControllerResult.
private XFuture<StreamWriter> tryRenderWebAppErrorControllerResult(RequestContext ctx, ProxyStreamHandle handler, Throwable t) {
if (ExceptionWrap.isChannelClosed(t)) {
// if the socket was closed before we responded, do not log a failure
if (log.isTraceEnabled())
log.trace("async exception due to socket being closed", t);
return XFuture.<StreamWriter>completedFuture(new NullStreamWriter());
}
String failedRoute = "<Unknown Route>";
if (t instanceof SpecificRouterInvokeException)
failedRoute = ((SpecificRouterInvokeException) t).getMatchInfo() + "";
if (!(t instanceof SimulateInternalError)) {
log.error("There is three parts to this error message... request, route found, and the exception " + "message. You should\nread the exception message below as well as the RouterRequest and RouteMeta.\n\n" + ctx.getRequest() + "\n\n" + failedRoute + ". \n\nNext, server will try to render apps 5xx page\n\n", t);
SupressedExceptionLog.log(log, t);
}
// page so in that case, fail, and cancel the stream
if (handler.hasSentResponseAlready()) {
RstStreamFrame frame = new RstStreamFrame();
frame.setKnownErrorCode(Http2ErrorCode.CANCEL);
handler.cancel(frame);
return XFuture.completedFuture(new NullStreamWriter());
}
return invokeWebAppErrorController(t, ctx, handler, failedRoute);
}
use of com.webpieces.http2.api.dto.lowlevel.RstStreamFrame in project webpieces by deanhiller.
the class Level5BResets method sendRstToServerAndApp.
public XFuture<Void> sendRstToServerAndApp(StreamException e) {
RstStreamFrame frame = new RstStreamFrame();
frame.setKnownErrorCode(e.getReason().getErrorCode());
frame.setStreamId(e.getStreamId());
boolean streamExist = streamState.isStreamExist(frame);
if (streamExist) {
Stream stream = streamState.getStream(frame, true);
return fireRstToSocket(stream, frame).thenCompose(v -> {
XFuture<Void> future = fireRstToClient(stream, frame);
return future;
});
} else {
// no stream means idle or closed...
return remoteFlowControl.fireResetToSocket(frame);
}
}
use of com.webpieces.http2.api.dto.lowlevel.RstStreamFrame in project webpieces by deanhiller.
the class TestC5x1StreamStates method testSection5_1ReceiveValidFramesAfterSendRstStreamFrame.
/**
* If this state is reached as a result of sending a RST_STREAM frame, the
* peer that receives the RST_STREAM might have already sent — or enqueued for
* sending — frames on the stream that cannot be withdrawn. An endpoint MUST ignore
* frames that it receives on closed streams after it has sent a RST_STREAM frame. An
* endpoint MAY choose to limit the period over which it ignores frames and
* treat frames that arrive after this time as being in error.
* @throws TimeoutException
* @throws ExecutionException
* @throws InterruptedException
*/
@Test
public void testSection5_1ReceiveValidFramesAfterSendRstStreamFrame() throws InterruptedException, ExecutionException, TimeoutException {
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(null));
Http2Request request1 = Requests.createRequest();
RequestStreamHandle stream = httpSocket.openStream();
StreamRef streamRef = httpSocket.openStream().process(request1, listener1);
XFuture<StreamWriter> future = streamRef.getWriter();
@SuppressWarnings("unused") StreamWriter writer = future.get(2, TimeUnit.SECONDS);
Http2Msg req = mockChannel.getFrameAndClear();
Assert.assertEquals(request1, req);
RstStreamFrame rst = new RstStreamFrame(request1.getStreamId(), Http2ErrorCode.CANCEL);
XFuture<Void> cancel = streamRef.cancel(rst);
cancel.get(2, TimeUnit.SECONDS);
Http2Msg svrRst = mockChannel.getFrameAndClear();
Assert.assertEquals(rst, svrRst);
// simulate server responding before receiving the cancel
Http2Response resp1 = Requests.createEosResponse(request1.getStreamId());
// endOfStream=true
mockChannel.write(resp1);
// Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
// Assert.assertFalse(mockChannel.isClosed());
//
// Assert.assertEquals(0, listener1.getReturnValuesIncomingResponse().size());
}
Aggregations