Search in sources :

Example 26 with Http2Response

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

the class Http2Translations method responseToHeaders.

public static Http2Response responseToHeaders(HttpResponse response) {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.STATUS, response.getStatusLine().getStatus().getCode().toString()));
    for (Header header : response.getHeaders()) {
        if (header.getKnownName() == KnownHeaderName.TRANSFER_ENCODING) {
            if ("chunked".equals(header.getValue())) {
                //skip as http2 does not allow this header
                continue;
            }
        }
        headers.add(new Http2Header(header.getName(), header.getValue()));
    }
    Http2Response resp = new Http2Response(headers);
    Header header = response.getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_LENGTH);
    if (header != null) {
        int len = Integer.parseInt(header.getValue());
        if (len == 0) {
            resp.setEndOfStream(true);
        } else {
            resp.setEndOfStream(false);
        }
    } else {
        resp.setEndOfStream(false);
    }
    return resp;
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Header(org.webpieces.httpparser.api.common.Header) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) ArrayList(java.util.ArrayList)

Example 27 with Http2Response

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

the class Http2Requests method createResponse.

public static Http2Response createResponse(int streamId, boolean eos) {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.SERVER, "id"));
    headers.add(new Http2Header(Http2HeaderName.STATUS, "200"));
    Http2Response response = new Http2Response(headers);
    response.setEndOfStream(eos);
    response.setStreamId(streamId);
    return response;
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) ArrayList(java.util.ArrayList)

Example 28 with Http2Response

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

Example 29 with Http2Response

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

the class TestSBasicRequestResponse method testWithNoData.

@Test
public void testWithNoData() throws InterruptedException, ExecutionException, TimeoutException {
    Http2Request request1 = Http2Requests.createRequest(1, true);
    mockChannel.send(request1);
    PassedIn incoming = mockListener.getSingleRequest();
    Assert.assertEquals(request1, incoming.request);
    Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), true);
    incoming.stream.sendResponse(resp);
    Http2Msg response = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp, response);
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 30 with Http2Response

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

the class TestC5_1StreamStates method sendEosResponseFromServer.

private void sendEosResponseFromServer(MockResponseListener listener1, Http2Request request) {
    Http2Response resp1 = Requests.createEosResponse(request.getStreamId());
    //endOfStream=true
    mockChannel.write(resp1);
    Http2Response response1 = (Http2Response) listener1.getSingleReturnValueIncomingResponse();
    Assert.assertEquals(resp1, response1);
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response)

Aggregations

Http2Response (com.webpieces.hpack.api.dto.Http2Response)36 Test (org.junit.Test)17 StreamWriter (com.webpieces.http2engine.api.StreamWriter)13 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)13 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)12 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)12 Http2Request (com.webpieces.hpack.api.dto.Http2Request)9 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)8 Header (org.webpieces.httpparser.api.common.Header)8 ArrayList (java.util.ArrayList)7 DataWrapper (org.webpieces.data.api.DataWrapper)7 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)7 HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)6 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)6 HttpData (org.webpieces.httpparser.api.dto.HttpData)5 Http2Headers (com.webpieces.hpack.api.dto.Http2Headers)3 Http2Push (com.webpieces.hpack.api.dto.Http2Push)3 Http2HeaderName (com.webpieces.http2parser.api.dto.lib.Http2HeaderName)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ResponseStream (org.webpieces.frontend2.api.ResponseStream)3