use of com.webpieces.http2engine.api.StreamHandle in project webpieces by deanhiller.
the class TestC5_1StreamStates 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(CompletableFuture.<StreamWriter>completedFuture(null));
Http2Request request1 = Requests.createRequest();
StreamHandle stream = httpSocket.openStream();
CompletableFuture<StreamWriter> future = stream.process(request1, listener1);
@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);
CompletableFuture<Void> cancel = stream.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());
}
use of com.webpieces.http2engine.api.StreamHandle in project webpieces by deanhiller.
the class Http2SocketImpl method send.
/**
* Can't specifically backpressure with this method(ie. On the other method, if you do not ack, eventually
* with too many bytes, the channelmanager disregisters and stops reading from the socket placing backpressure
* on the socket)
*/
@Override
public CompletableFuture<FullResponse> send(FullRequest request) {
SingleResponseListener responseListener = new SingleResponseListener();
StreamHandle streamHandle = openStream();
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);
return streamHandle.process(request.getHeaders(), responseListener).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);
return streamHandle.process(request.getHeaders(), responseListener).thenCompose(writer -> {
data.setStreamId(req.getStreamId());
return writer.processPiece(data);
}).thenCompose(writer -> {
trailers.setStreamId(req.getStreamId());
return writer.processPiece(trailers);
}).thenCompose(writer -> responseListener.fetchResponseFuture());
}
Aggregations