Search in sources :

Example 31 with Http2Response

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

the class TestCBasicRequestResponse method testWithDataAndTrailingHeaders.

@Test
public void testWithDataAndTrailingHeaders() throws InterruptedException, ExecutionException, TimeoutException {
    FullRequest request1 = Requests.createHttp2Request();
    Http2Trailers trailing = Requests.createTrailers();
    request1.setTrailingHeaders(trailing);
    CompletableFuture<FullResponse> future = httpSocket.send(request1);
    Assert.assertFalse(future.isDone());
    List<Http2Msg> frames = mockChannel.getFramesAndClear();
    Assert.assertEquals(3, frames.size());
    Http2Response resp = Requests.createResponse(request1.getHeaders().getStreamId());
    mockChannel.write(resp);
    Assert.assertFalse(future.isDone());
    DataFrame data = Requests.createData(request1.getHeaders().getStreamId());
    data.setEndOfStream(false);
    mockChannel.write(data);
    Assert.assertFalse(future.isDone());
    mockChannel.write(trailing);
    FullResponse response = future.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(2, response.getPayload().getReadableSize());
    Assert.assertNotNull(response.getTrailingHeaders());
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) FullResponse(org.webpieces.http2client.api.dto.FullResponse) Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) FullRequest(org.webpieces.http2client.api.dto.FullRequest) Test(org.junit.Test)

Example 32 with Http2Response

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

the class TestCBasicRequestResponse method testWithData.

@Test
public void testWithData() throws InterruptedException, ExecutionException, TimeoutException {
    FullRequest request1 = Requests.createHttp2Request();
    CompletableFuture<FullResponse> future = httpSocket.send(request1);
    Assert.assertFalse(future.isDone());
    List<Http2Msg> frames = mockChannel.getFramesAndClear();
    Assert.assertEquals(2, frames.size());
    Http2Response resp = Requests.createResponse(request1.getHeaders().getStreamId());
    mockChannel.write(resp);
    Assert.assertFalse(future.isDone());
    DataFrame data = Requests.createData(request1.getHeaders().getStreamId());
    mockChannel.write(data);
    FullResponse response = future.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(2, response.getPayload().getReadableSize());
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) FullResponse(org.webpieces.http2client.api.dto.FullResponse) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) FullRequest(org.webpieces.http2client.api.dto.FullRequest) Test(org.junit.Test)

Example 33 with Http2Response

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

the class Requests method createResponse.

public static Http2Response createResponse(int streamId) {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.STATUS, StatusCode.HTTP_200_OK.getCodeString()));
    headers.add(new Http2Header(Http2HeaderName.SERVER, "me"));
    Http2Response response = new Http2Response(headers);
    response.setEndOfStream(false);
    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 34 with Http2Response

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

the class Requests method createEosResponse.

public static Http2Response createEosResponse(int streamId) {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.STATUS, StatusCode.HTTP_200_OK.getCodeString()));
    headers.add(new Http2Header(Http2HeaderName.SERVER, "me"));
    Http2Response response = new Http2Response(headers);
    response.setEndOfStream(true);
    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 35 with Http2Response

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

the class ProxyResponse method maybeCompressAndSend.

private CompletableFuture<Void> maybeCompressAndSend(String extension, ResponseEncodingTuple tuple, byte[] bytes) {
    Compression compression = compressionLookup.createCompressionStream(routerRequest.encodings, extension, tuple.mimeType);
    Http2Response resp = tuple.response;
    if (bytes.length == 0) {
        resp.setEndOfStream(true);
        return stream.sendResponse(resp).thenApply(w -> null);
    }
    return sendChunkedResponse(resp, bytes, compression);
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Compression(org.webpieces.router.impl.compression.Compression)

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