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());
}
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());
}
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;
}
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;
}
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);
}
Aggregations