use of com.webpieces.http2.api.streaming.RequestStreamHandle in project webpieces by deanhiller.
the class ResponseCacher method run.
public XFuture<FullResponse> run(FullRequest request) {
SingleResponseListener responseListener = new SingleResponseListener();
RequestStreamHandle streamHandle = openStreamFunc.get();
Http2Request req = request.getHeaders();
if (request.getPayload() == null) {
request.getHeaders().setEndOfStream(true);
streamHandle.process(req, responseListener);
return responseListener.fetchResponseFuture();
} else if (request.getTrailingHeaders() == null) {
request.getHeaders().setEndOfStream(false);
DataFrame data = createData(request, true);
StreamRef streamRef = streamHandle.process(request.getHeaders(), responseListener);
return streamRef.getWriter().thenCompose(writer -> {
data.setStreamId(req.getStreamId());
return writer.processPiece(data);
}).thenCompose(writer -> responseListener.fetchResponseFuture());
}
request.getHeaders().setEndOfStream(false);
DataFrame data = createData(request, false);
Http2Trailers trailers = request.getTrailingHeaders();
trailers.setEndOfStream(true);
StreamRef streamRef = streamHandle.process(request.getHeaders(), responseListener);
return streamRef.getWriter().thenCompose(writer -> writeStuff(writer, req, data, trailers, responseListener));
}
use of com.webpieces.http2.api.streaming.RequestStreamHandle in project webpieces by deanhiller.
the class TestStreaming method testAsyncJsonGet.
@Test
public void testAsyncJsonGet() {
String bodyStr = "asdlfkjsldfkjlsfkjdlksjfffffflsdkjfffffldksjflkdjsfldsjf";
byte[] bytes = bodyStr.getBytes();
DataWrapper body = gen.wrapByteArray(bytes);
Http2Request request = Requests.createRequest("/json/streaming", body);
RequestStreamHandle stream = http2Socket.openStream();
StreamRef ref = stream.process(request, mockResponseListener);
XFuture<StreamWriter> writer = ref.getWriter();
}
use of com.webpieces.http2.api.streaming.RequestStreamHandle 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.streaming.RequestStreamHandle in project webpieces by deanhiller.
the class TestCancelStream method testServerCloseSocket.
@Test
public void testServerCloseSocket() {
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);
Assert.assertFalse(mockListener.isCancelled());
mockChannel.simulateClose();
Assert.assertTrue(mockListener.isCancelled());
}
use of com.webpieces.http2.api.streaming.RequestStreamHandle 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());
}
Aggregations