Search in sources :

Example 6 with Http2Push

use of com.webpieces.http2.api.dto.highlevel.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());
    XFuture<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());
    XFuture<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);
    XFuture<StreamWriter> fut1 = pushWriter1.processPushResponse(resp1);
    StreamWriter writer1 = fut1.get(2, TimeUnit.SECONDS);
    Http2Response resp2 = Http2Requests.createResponse(push2.getPromisedStreamId(), false);
    XFuture<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.http2.api.dto.highlevel.Http2Response) PushPromiseListener(com.webpieces.http2.api.streaming.PushPromiseListener) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)

Example 7 with Http2Push

use of com.webpieces.http2.api.dto.highlevel.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.http2.api.dto.lowlevel.CancelReason) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push)

Example 8 with Http2Push

use of com.webpieces.http2.api.dto.highlevel.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(XFuture.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.http2.api.dto.highlevel.Http2Response) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) MockPushListener(org.webpieces.http2client.mock.MockPushListener)

Example 9 with Http2Push

use of com.webpieces.http2.api.dto.highlevel.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(), f.isEndOfStream());
        fullHeaders.setStreamId(f.getStreamId());
        fullHeaders.setPriorityDetails(f.getPriorityDetails());
        fullHeaders.setEndOfStream(f.isEndOfStream());
        state.addParsedMessage(fullHeaders);
    } else if (firstFrame instanceof PushPromiseFrame) {
        PushPromiseFrame f = (PushPromiseFrame) firstFrame;
        Http2Push fullHeaders = new Http2Push(headers);
        fullHeaders.setStreamId(f.getStreamId());
        fullHeaders.setPromisedStreamId(f.getPromisedStreamId());
        state.addParsedMessage(fullHeaders);
    }
    hasHeaderFragmentList.clear();
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HasHeaderFragment(com.webpieces.http2.api.dto.lowlevel.lib.HasHeaderFragment) HashMap(java.util.HashMap) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) Http2HeaderName(com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) Http2Push(com.webpieces.http2.api.dto.highlevel.Http2Push) PushPromiseFrame(com.webpieces.http2.api.dto.lowlevel.PushPromiseFrame) HeadersFrame(com.webpieces.http2.api.dto.lowlevel.HeadersFrame)

Example 10 with Http2Push

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

the class Level5ClientStateMachine method sendPushToApp.

public XFuture<Void> sendPushToApp(Http2Push fullPromise) {
    int newStreamId = fullPromise.getPromisedStreamId();
    if (newStreamId % 2 == 1)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, logId, newStreamId, "Server sent bad push promise=" + fullPromise + " as new stream id is incorrect and is an odd number");
    ClientStream causalStream = (ClientStream) streamState.getStream(fullPromise, true);
    ClientPushStream stream = createPushStream(newStreamId, causalStream.getResponseListener());
    return firePushToClient(stream, fullPromise);
}
Also used : ConnectionException(com.webpieces.http2.api.dto.error.ConnectionException)

Aggregations

Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)10 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)4 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)3 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)3 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)3 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)3 Test (org.junit.Test)3 DataWrapper (org.webpieces.data.api.DataWrapper)3 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)3 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)2 PushPromiseFrame (com.webpieces.http2.api.dto.lowlevel.PushPromiseFrame)2 Http2Frame (com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)2 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)2 PushPromiseListener (com.webpieces.http2.api.streaming.PushPromiseListener)2 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)2 MockPushListener (org.webpieces.http2client.mock.MockPushListener)2 Encoder (com.twitter.hpack.Encoder)1 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)1 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)1 HeadersFrame (com.webpieces.http2.api.dto.lowlevel.HeadersFrame)1