Search in sources :

Example 1 with PushPromiseListener

use of com.webpieces.http2engine.api.PushPromiseListener in project webpieces by deanhiller.

the class TestSMaxConcurrentSetting method sendTwoRequests.

private WriterHolder sendTwoRequests() throws InterruptedException, ExecutionException, TimeoutException {
    PassedIn in1 = sendRequestToServer(1, true);
    PassedIn in2 = sendRequestToServer(3, true);
    Assert.assertTrue(in1.stream != in2.stream);
    Http2Push push1 = Http2Requests.createPush(in1.request.getStreamId());
    CompletableFuture<PushPromiseListener> future1 = in1.stream.openPushStream().process(push1);
    Http2Msg push1Recv = mockChannel.getFrameAndClear();
    Assert.assertEquals(push1, push1Recv);
    PushPromiseListener pushWriter1 = future1.get(2, TimeUnit.SECONDS);
    Http2Push push2 = Http2Requests.createPush(in2.request.getStreamId());
    CompletableFuture<PushPromiseListener> future2 = in2.stream.openPushStream().process(push2);
    Http2Msg push2Recv = mockChannel.getFrameAndClear();
    Assert.assertEquals(push2, push2Recv);
    Assert.assertEquals(push1, push1Recv);
    PushPromiseListener writer2 = future2.get(2, TimeUnit.SECONDS);
    //send the two responses following the pushes
    Http2Response resp1 = Http2Requests.createResponse(push1.getPromisedStreamId(), false);
    CompletableFuture<StreamWriter> fut1 = pushWriter1.processPushResponse(resp1);
    StreamWriter writer1 = fut1.get(2, TimeUnit.SECONDS);
    Http2Response resp2 = Http2Requests.createResponse(push2.getPromisedStreamId(), false);
    CompletableFuture<StreamWriter> fut2 = writer2.processPushResponse(resp2);
    Assert.assertTrue(!fut2.isDone());
    Http2Response clientRecvResp = (Http2Response) mockChannel.getFrameAndClear();
    Assert.assertEquals(resp1, clientRecvResp);
    return new WriterHolder(writer1, fut2, resp1, resp2);
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) PushPromiseListener(com.webpieces.http2engine.api.PushPromiseListener) StreamWriter(com.webpieces.http2engine.api.StreamWriter) Http2Push(com.webpieces.hpack.api.dto.Http2Push) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)

Example 2 with PushPromiseListener

use of com.webpieces.http2engine.api.PushPromiseListener in project webpieces by deanhiller.

the class Level8NotifyClntListeners method sendResponseToApp.

public CompletableFuture<Void> sendResponseToApp(Stream stream, Http2Response response) {
    if (stream instanceof ClientStream) {
        ClientStream str = (ClientStream) stream;
        ResponseHandler listener = str.getResponseListener();
        return listener.process(response).thenApply(w -> {
            str.setResponseWriter(w);
            return null;
        });
    }
    ClientPushStream str = (ClientPushStream) stream;
    PushPromiseListener pushListener = str.getPushPromiseListener();
    return pushListener.processPushResponse(response).thenApply(w -> {
        str.setPushResponseWriter(w);
        return null;
    });
}
Also used : PushPromiseListener(com.webpieces.http2engine.api.PushPromiseListener) ResponseHandler(com.webpieces.http2engine.api.ResponseHandler)

Example 3 with PushPromiseListener

use of com.webpieces.http2engine.api.PushPromiseListener in project webpieces by deanhiller.

the class TestSBasicRequestResponse method testPushPromise.

@Test
public void testPushPromise() throws InterruptedException, ExecutionException, TimeoutException {
    Http2Request request1 = Http2Requests.createRequest(1, true);
    mockChannel.send(request1);
    PassedIn incoming = mockListener.getSingleRequest();
    Assert.assertEquals(request1, incoming.request);
    Http2Push push = Http2Requests.createPush(request1.getStreamId());
    CompletableFuture<PushPromiseListener> future = incoming.stream.openPushStream().process(push);
    PushPromiseListener pushWriter = future.get(2, TimeUnit.SECONDS);
    Http2Push pushRecv = (Http2Push) mockChannel.getFrameAndClear();
    Assert.assertEquals(push, pushRecv);
    Http2Response preEmptive = Http2Requests.createResponse(push.getPromisedStreamId());
    pushWriter.processPushResponse(preEmptive);
    Http2Headers preEmptRecv = (Http2Headers) mockChannel.getFrameAndClear();
    Assert.assertEquals(preEmptive, preEmptRecv);
    Http2Response response = Http2Requests.createResponse(request1.getStreamId());
    incoming.stream.sendResponse(response);
    Http2Headers responseRecv = (Http2Headers) mockChannel.getFrameAndClear();
    Assert.assertEquals(response, responseRecv);
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) PushPromiseListener(com.webpieces.http2engine.api.PushPromiseListener) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Http2Headers(com.webpieces.hpack.api.dto.Http2Headers) Http2Push(com.webpieces.hpack.api.dto.Http2Push) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Aggregations

PushPromiseListener (com.webpieces.http2engine.api.PushPromiseListener)3 Http2Push (com.webpieces.hpack.api.dto.Http2Push)2 Http2Response (com.webpieces.hpack.api.dto.Http2Response)2 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)2 Http2Headers (com.webpieces.hpack.api.dto.Http2Headers)1 Http2Request (com.webpieces.hpack.api.dto.Http2Request)1 ResponseHandler (com.webpieces.http2engine.api.ResponseHandler)1 StreamWriter (com.webpieces.http2engine.api.StreamWriter)1 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)1 Test (org.junit.Test)1