use of com.webpieces.http2.api.dto.lowlevel.CancelReason in project webpieces by deanhiller.
the class TestCancelStream method testClientCancelWithKeepAlive.
// @Test
// public void testRequestResponseXFutureCancelNoKeepAlive() {
// throw new UnsupportedOperationException("not done yet");
// }
//
// @Test
// public void testRequestResponseXFutureCancelWithKeepAlive() {
// throw new UnsupportedOperationException("not done yet");
// }
@Test
public void testClientCancelWithKeepAlive() {
XFuture<Void> connect = httpSocket.connect(new InetSocketAddress(8555));
MockResponseListener mockListener = new MockResponseListener();
Http2Request req = Requests.createRequest(false);
req.addHeader(new Http2Header(Http2HeaderName.CONNECTION, "keep-alive"));
mockChannel.addWriteResponse(XFuture.completedFuture(null));
RequestStreamHandle requestStream = httpSocket.openStream();
StreamRef ref = requestStream.process(req, mockListener);
CancelReason reason = new RstStreamFrame();
XFuture<Void> cancelDone = ref.cancel(reason);
Assert.assertTrue(cancelDone.isDone());
// Assert the socket is NOT closed
Assert.assertFalse(mockChannel.isClosed());
}
use of com.webpieces.http2.api.dto.lowlevel.CancelReason in project webpieces by deanhiller.
the class TestCancelStream method testClientCancelNoKeepAlive.
@Test
public void testClientCancelNoKeepAlive() {
XFuture<Void> connect = httpSocket.connect(new InetSocketAddress(8555));
MockResponseListener mockListener = new MockResponseListener();
Http2Request req = Requests.createRequest(false);
mockChannel.addWriteResponse(XFuture.completedFuture(null));
RequestStreamHandle requestStream = httpSocket.openStream();
StreamRef ref = requestStream.process(req, mockListener);
CancelReason reason = new RstStreamFrame();
XFuture<Void> cancelDone = ref.cancel(reason);
Assert.assertTrue(cancelDone.isDone());
// Assert the socket is NOT closed
Assert.assertTrue(mockChannel.isClosed());
}
use of com.webpieces.http2.api.dto.lowlevel.CancelReason in project webpieces by deanhiller.
the class Level5AStates method translate.
protected Http2Event translate(Http2SendRecieve sendRecv, Http2Msg payload) {
Http2PayloadType payloadType;
if (payload instanceof Http2Headers) {
Http2Headers head = (Http2Headers) payload;
if (head.isEndOfStream())
payloadType = Http2PayloadType.HEADERS_EOS;
else
payloadType = Http2PayloadType.HEADERS;
} else if (payload instanceof DataFrame) {
DataFrame data = (DataFrame) payload;
if (data.isEndOfStream())
payloadType = Http2PayloadType.DATA_EOS;
else
payloadType = Http2PayloadType.DATA;
} else if (payload instanceof Http2Push) {
payloadType = Http2PayloadType.PUSH_PROMISE;
} else if (payload instanceof CancelReason) {
payloadType = Http2PayloadType.RESET_STREAM;
} else
throw new IllegalArgumentException("unknown payload type for payload=" + payload);
return Http2Event.lookup(sendRecv, payloadType);
}
use of com.webpieces.http2.api.dto.lowlevel.CancelReason in project webpieces by deanhiller.
the class TestS4FrameSizeAndHeaders method testSection4_2FrameTooLarge.
/**
* An endpoint MUST send an error code of FRAME_SIZE_ERROR if a frame
* exceeds the size defined in SETTINGS_MAX_FRAME_SIZE, exceeds any
* limit defined for the frame type, or is too small to contain
* mandatory frame data. A frame size error in a frame that could alter
* the state of the entire connection MUST be treated as a connection
* error (Section 5.4.1); this includes any frame carrying a header
* block (Section 4.3) (that is, HEADERS, PUSH_PROMISE, and
* CONTINUATION), SETTINGS, and any frame with a stream identifier of 0.
* @throws TimeoutException
* @throws ExecutionException
* @throws InterruptedException
*/
@Test
public void testSection4_2FrameTooLarge() throws InterruptedException, ExecutionException, TimeoutException {
MockStreamWriter mockWriter = new MockStreamWriter();
XFuture<StreamWriter> futA = XFuture.completedFuture(mockWriter);
MockStreamRef mockStream = new MockStreamRef(futA);
mockListener.addMockStreamToReturn(mockStream);
int streamId = 1;
PassedIn info = sendRequestToServer(streamId, false);
ResponseStream stream = info.stream;
Http2Request request = info.request;
Assert.assertFalse(mockStream.isCancelled());
// send data that goes with request
DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
byte[] buf = new byte[localSettings.getMaxFrameSize() + 4];
dataFrame.setData(DATA_GEN.wrapByteArray(buf));
// endOfStream=false
mockChannel.send(dataFrame);
// 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:(EXCEEDED_MAX_FRAME_SIZE) Frame size=16389 was greater than max=16385", msg);
Assert.assertTrue(mockChannel.isClosed());
Assert.assertTrue(mockListener.isClosed());
Assert.assertTrue(mockStream.isCancelled());
CancelReason failResp = mockStream.getCancelInfo();
ShutdownStream reset = (ShutdownStream) failResp;
Assert.assertEquals(CancelReasonCode.EXCEEDED_MAX_FRAME_SIZE, reset.getCause().getReasonCode());
// send response with request not complete but failed as well anyways
Http2Response response = Http2Requests.createResponse(request.getStreamId());
XFuture<StreamWriter> future = stream.process(response);
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.http2.api.dto.lowlevel.CancelReason in project webpieces by deanhiller.
the class StreamProxy method openStream.
@Override
public RouterStreamRef openStream(MethodMeta meta, ProxyStreamHandle handle) {
RequestContext requestCtx = meta.getCtx();
LoadedController loadedController = meta.getLoadedController();
Object instance = loadedController.getControllerInstance();
Method controllerMethod = loadedController.getControllerMethod();
Parameter[] parameters = loadedController.getParameters();
if (parameters.length != 1)
throw new IllegalArgumentException("Your method='" + controllerMethod + "' MUST one parameter and does not. It needs to take a RouterStreamHandler");
else if (!ResponseStreamHandle.class.equals(parameters[0].getType()))
throw new IllegalArgumentException("The single parameter must be RouterStreamHandle and was not for this method='" + controllerMethod + "'");
else if (!StreamRef.class.equals(controllerMethod.getReturnType()))
throw new IllegalArgumentException("The return value must be a subclass of StreamRef and was not for this method='" + controllerMethod + "'");
StreamRef streamRef = invokeStream(meta, controllerMethod, instance, requestCtx, handle);
XFuture<StreamWriter> writer = streamRef.getWriter();
XFuture<StreamWriter> newFuture = futureUtil.catchBlockWrap(() -> writer, (t) -> convert(loadedController, t));
Function<CancelReason, XFuture<Void>> cancelFunc = (reason) -> streamRef.cancel(reason);
return new RouterStreamRef("streamProxy", newFuture, cancelFunc);
}
Aggregations