Search in sources :

Example 1 with StreamHandle

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());
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Request(com.webpieces.hpack.api.dto.Http2Request) RstStreamFrame(com.webpieces.http2parser.api.dto.RstStreamFrame) StreamHandle(com.webpieces.http2engine.api.StreamHandle) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) Test(org.junit.Test)

Example 2 with StreamHandle

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());
}
Also used : Logger(org.webpieces.util.logging.Logger) Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers) CompletableFuture(java.util.concurrent.CompletableFuture) InetSocketAddress(java.net.InetSocketAddress) FullRequest(org.webpieces.http2client.api.dto.FullRequest) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Http2ClientEngineFactory(com.webpieces.http2engine.api.client.Http2ClientEngineFactory) DataWrapper(org.webpieces.data.api.DataWrapper) FullResponse(org.webpieces.http2client.api.dto.FullResponse) LoggerFactory(org.webpieces.util.logging.LoggerFactory) StreamHandle(com.webpieces.http2engine.api.StreamHandle) Http2ClientEngine(com.webpieces.http2engine.api.client.Http2ClientEngine) Http2Socket(org.webpieces.http2client.api.Http2Socket) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Request(com.webpieces.hpack.api.dto.Http2Request) StreamHandle(com.webpieces.http2engine.api.StreamHandle) Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers) DataFrame(com.webpieces.http2parser.api.dto.DataFrame)

Aggregations

Http2Request (com.webpieces.hpack.api.dto.Http2Request)2 StreamHandle (com.webpieces.http2engine.api.StreamHandle)2 Http2Response (com.webpieces.hpack.api.dto.Http2Response)1 Http2Trailers (com.webpieces.hpack.api.dto.Http2Trailers)1 StreamWriter (com.webpieces.http2engine.api.StreamWriter)1 Http2ClientEngine (com.webpieces.http2engine.api.client.Http2ClientEngine)1 Http2ClientEngineFactory (com.webpieces.http2engine.api.client.Http2ClientEngineFactory)1 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)1 RstStreamFrame (com.webpieces.http2parser.api.dto.RstStreamFrame)1 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)1 InetSocketAddress (java.net.InetSocketAddress)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 Test (org.junit.Test)1 DataWrapper (org.webpieces.data.api.DataWrapper)1 Http2Socket (org.webpieces.http2client.api.Http2Socket)1 FullRequest (org.webpieces.http2client.api.dto.FullRequest)1 FullResponse (org.webpieces.http2client.api.dto.FullResponse)1 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)1 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)1 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)1