Search in sources :

Example 1 with Http2Headers

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

the class TestCBasicRequestResponse method testWithNoData.

@Test
public void testWithNoData() throws InterruptedException, ExecutionException, TimeoutException {
    FullRequest request1 = new FullRequest();
    request1.setHeaders(Requests.createRequest());
    CompletableFuture<FullResponse> future = httpSocket.send(request1);
    Assert.assertFalse(future.isDone());
    Http2Headers frame = (Http2Headers) mockChannel.getFrameAndClear();
    Assert.assertEquals(1, frame.getStreamId());
    Http2Response resp = Requests.createResponse(request1.getHeaders().getStreamId());
    resp.setEndOfStream(true);
    mockChannel.write(resp);
    FullResponse response = future.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(0, response.getPayload().getReadableSize());
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) FullResponse(org.webpieces.http2client.api.dto.FullResponse) Http2Headers(com.webpieces.hpack.api.dto.Http2Headers) FullRequest(org.webpieces.http2client.api.dto.FullRequest) Test(org.junit.Test)

Example 2 with Http2Headers

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

the class TestSBasicRequestResponse method testWithDataAndTrailingHeaders.

@Test
public void testWithDataAndTrailingHeaders() throws InterruptedException, ExecutionException, TimeoutException {
    MockStreamWriter mockSw = new MockStreamWriter();
    mockSw.setDefaultRetValToThis();
    mockListener.addMockStreamToReturn(mockSw);
    Http2Request request1 = Http2Requests.createRequest(1, false);
    DataFrame data1 = Http2Requests.createData1(request1.getStreamId(), false);
    Http2Trailers trailing = Http2Requests.createTrailers(request1.getStreamId());
    mockChannel.send(request1);
    PassedIn incoming1 = mockListener.getSingleRequest();
    Assert.assertEquals(request1, incoming1.request);
    mockChannel.send(data1);
    DataFrame incoming2 = (DataFrame) mockSw.getSingleFrame();
    Assert.assertEquals(3, incoming2.getData().getReadableSize());
    //clear window update frames
    Assert.assertEquals(2, mockChannel.getFramesAndClear().size());
    mockChannel.send(trailing);
    Http2Headers incoming = (Http2Headers) mockSw.getSingleFrame();
    Assert.assertEquals(trailing, incoming);
    Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), false);
    CompletableFuture<StreamWriter> future = incoming1.stream.sendResponse(resp);
    Http2Msg response = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp, response);
    StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    DataFrame data2 = Http2Requests.createData2(request1.getStreamId(), false);
    writer.processPiece(data2);
    DataFrame dataResp = (DataFrame) mockChannel.getFrameAndClear();
    Assert.assertEquals(1, dataResp.getData().getReadableSize());
    Http2Trailers trailingResp = Http2Requests.createTrailers(request1.getStreamId());
    writer.processPiece(trailingResp);
    Http2Headers trailers = (Http2Headers) mockChannel.getFrameAndClear();
    Assert.assertEquals(trailingResp, trailers);
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Http2Headers(com.webpieces.hpack.api.dto.Http2Headers) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2engine.api.StreamWriter) Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 3 with Http2Headers

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

use of com.webpieces.hpack.api.dto.Http2Headers 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)

Example 5 with Http2Headers

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

Http2Headers (com.webpieces.hpack.api.dto.Http2Headers)7 Test (org.junit.Test)4 Http2Push (com.webpieces.hpack.api.dto.Http2Push)3 Http2Response (com.webpieces.hpack.api.dto.Http2Response)3 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)3 Http2Request (com.webpieces.hpack.api.dto.Http2Request)2 StreamWriter (com.webpieces.http2engine.api.StreamWriter)2 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)2 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)2 Http2Trailers (com.webpieces.hpack.api.dto.Http2Trailers)1 PushPromiseListener (com.webpieces.http2engine.api.PushPromiseListener)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 Http2HeaderName (com.webpieces.http2parser.api.dto.lib.Http2HeaderName)1 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)1 StreamMsg (com.webpieces.http2parser.api.dto.lib.StreamMsg)1 HashMap (java.util.HashMap)1