Search in sources :

Example 1 with Http2Push

use of com.webpieces.hpack.api.dto.Http2Push in project webpieces by deanhiller.

the class AbstractTest method sendPushPromise.

protected void sendPushPromise(MockResponseListener listener1, int streamId, boolean eos) {
    MockPushListener pushListener = new MockPushListener();
    pushListener.setDefaultResponse(CompletableFuture.completedFuture(null));
    listener1.addReturnValuePush(pushListener);
    Http2Push push = Requests.createPush(streamId);
    //endOfStream=false
    mockChannel.write(push);
    Assert.assertEquals(push, listener1.getSinglePush());
    Http2Response preemptiveResponse = Requests.createEosResponse(2);
    mockChannel.write(preemptiveResponse);
    Http2Response frame2 = (Http2Response) pushListener.getSingleParam();
    Assert.assertEquals(preemptiveResponse, frame2);
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Push(com.webpieces.hpack.api.dto.Http2Push) MockPushListener(org.webpieces.http2client.mock.MockPushListener)

Example 2 with Http2Push

use of com.webpieces.hpack.api.dto.Http2Push 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 3 with Http2Push

use of com.webpieces.hpack.api.dto.Http2Push 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);
}
Also used : Http2PayloadType(com.webpieces.http2engine.impl.shared.data.Http2PayloadType) CancelReason(com.webpieces.http2parser.api.dto.CancelReason) Http2Headers(com.webpieces.hpack.api.dto.Http2Headers) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Push(com.webpieces.hpack.api.dto.Http2Push)

Example 4 with Http2Push

use of com.webpieces.hpack.api.dto.Http2Push in project webpieces by deanhiller.

the class Requests method createPush.

public static Http2Push createPush(int streamId) {
    Http2Push push = new Http2Push();
    push.setStreamId(streamId);
    push.setPromisedStreamId(2);
    push.addHeader(new Http2Header(Http2HeaderName.SERVER, "me"));
    return push;
}
Also used : Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) Http2Push(com.webpieces.hpack.api.dto.Http2Push)

Example 5 with Http2Push

use of com.webpieces.hpack.api.dto.Http2Push in project webpieces by deanhiller.

the class HpackParserImpl method combineAndSendHeadersToClient.

private void combineAndSendHeadersToClient(UnmarshalStateImpl state) {
    List<HasHeaderFragment> hasHeaderFragmentList = state.getHeadersToCombine();
    // Now we set the full header list on the first frame and just return that
    HasHeaderFragment firstFrame = hasHeaderFragmentList.get(0);
    DataWrapper allSerializedHeaders = dataGen.emptyWrapper();
    for (HasHeaderFragment iterFrame : hasHeaderFragmentList) {
        allSerializedHeaders = dataGen.chainDataWrappers(allSerializedHeaders, iterFrame.getHeaderFragment());
    }
    Map<Http2HeaderName, Http2Header> knownHeaders = new HashMap<>();
    List<Http2Header> headers = decoding.decode(state, allSerializedHeaders, firstFrame.getStreamId(), header -> knownHeaders.put(header.getKnownName(), header));
    if (firstFrame instanceof HeadersFrame) {
        HeadersFrame f = (HeadersFrame) firstFrame;
        Http2Headers fullHeaders = createCorrectType(knownHeaders, headers, state.getLogId(), f.getStreamId());
        fullHeaders.setStreamId(f.getStreamId());
        fullHeaders.setPriorityDetails(f.getPriorityDetails());
        fullHeaders.setEndOfStream(f.isEndOfStream());
        state.getParsedFrames().add(fullHeaders);
    } else if (firstFrame instanceof PushPromiseFrame) {
        PushPromiseFrame f = (PushPromiseFrame) firstFrame;
        Http2Push fullHeaders = new Http2Push(headers);
        fullHeaders.setStreamId(f.getStreamId());
        fullHeaders.setPromisedStreamId(f.getPromisedStreamId());
        state.getParsedFrames().add(fullHeaders);
    }
    hasHeaderFragmentList.clear();
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HasHeaderFragment(com.webpieces.http2parser.api.dto.lib.HasHeaderFragment) HashMap(java.util.HashMap) Http2Headers(com.webpieces.hpack.api.dto.Http2Headers) Http2HeaderName(com.webpieces.http2parser.api.dto.lib.Http2HeaderName) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) Http2Push(com.webpieces.hpack.api.dto.Http2Push) PushPromiseFrame(com.webpieces.http2parser.api.dto.PushPromiseFrame) HeadersFrame(com.webpieces.http2parser.api.dto.HeadersFrame)

Aggregations

Http2Push (com.webpieces.hpack.api.dto.Http2Push)10 Http2Headers (com.webpieces.hpack.api.dto.Http2Headers)3 Http2Request (com.webpieces.hpack.api.dto.Http2Request)3 Http2Response (com.webpieces.hpack.api.dto.Http2Response)3 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)3 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)3 Test (org.junit.Test)3 DataWrapper (org.webpieces.data.api.DataWrapper)3 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)3 PushPromiseListener (com.webpieces.http2engine.api.PushPromiseListener)2 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)2 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)2 MockPushListener (org.webpieces.http2client.mock.MockPushListener)2 StreamWriter (com.webpieces.http2engine.api.StreamWriter)1 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)1 Http2PayloadType (com.webpieces.http2engine.impl.shared.data.Http2PayloadType)1 CancelReason (com.webpieces.http2parser.api.dto.CancelReason)1 HeadersFrame (com.webpieces.http2parser.api.dto.HeadersFrame)1 PushPromiseFrame (com.webpieces.http2parser.api.dto.PushPromiseFrame)1 HasHeaderFragment (com.webpieces.http2parser.api.dto.lib.HasHeaderFragment)1