Search in sources :

Example 1 with Http2Headers

use of com.webpieces.http2.api.dto.highlevel.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());
    XFuture<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.http2.api.dto.highlevel.Http2Response) FullResponse(org.webpieces.http2client.api.dto.FullResponse) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) FullRequest(org.webpieces.http2client.api.dto.FullRequest) Test(org.junit.Test)

Example 2 with Http2Headers

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

the class HeaderEncoding method translateToFrames.

public List<Http2Frame> translateToFrames(long maxFrameSize, Encoder encoder, Http2Headers headers) {
    HeadersFrame frame = new HeadersFrame();
    frame.setStreamId(headers.getStreamId());
    frame.setEndOfStream(headers.isEndOfStream());
    frame.setPriorityDetails(headers.getPriorityDetails());
    List<Http2Header> headerList = headers.getHeaders();
    List<Http2Frame> headerFrames = toHeaderFrames(maxFrameSize, encoder, frame, headerList);
    return headerFrames;
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) HeadersFrame(com.webpieces.http2.api.dto.lowlevel.HeadersFrame) Http2Frame(com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)

Example 3 with Http2Headers

use of com.webpieces.http2.api.dto.highlevel.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);
    XFuture<StreamWriter> future = incoming1.stream.process(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.http2.api.dto.highlevel.Http2Response) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) Http2Trailers(com.webpieces.http2.api.dto.highlevel.Http2Trailers) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) Http2Msg(com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg) MockStreamWriter(org.webpieces.httpfrontend2.api.mock2.MockStreamWriter) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 4 with Http2Headers

use of com.webpieces.http2.api.dto.highlevel.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.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 5 with Http2Headers

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

the class HpackParserImpl method createHeadersData.

private DataWrapper createHeadersData(MarshalStateImpl state, Http2Headers headers) {
    long maxFrameSize = state.getMaxRemoteFrameSize();
    Encoder encoder = state.getEncoder();
    List<Http2Frame> headerFrames = encoding.translateToFrames(maxFrameSize, encoder, headers);
    return translate(headerFrames);
}
Also used : Encoder(com.twitter.hpack.Encoder) Http2Frame(com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)

Aggregations

Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)8 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)4 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)4 Test (org.junit.Test)4 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)3 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)3 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)2 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)2 HeadersFrame (com.webpieces.http2.api.dto.lowlevel.HeadersFrame)2 Http2Frame (com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)2 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)2 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)2 Encoder (com.twitter.hpack.Encoder)1 Http2HeaderStruct (com.webpieces.http2.api.dto.highlevel.Http2HeaderStruct)1 Http2Trailers (com.webpieces.http2.api.dto.highlevel.Http2Trailers)1 PushPromiseFrame (com.webpieces.http2.api.dto.lowlevel.PushPromiseFrame)1 HasHeaderFragment (com.webpieces.http2.api.dto.lowlevel.lib.HasHeaderFragment)1 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)1 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)1 StreamMsg (com.webpieces.http2.api.dto.lowlevel.lib.StreamMsg)1