use of org.webpieces.http2client.api.dto.FullResponse in project webpieces by deanhiller.
the class SingleResponseListener method incomingEndHeaders.
public void incomingEndHeaders(Http2Trailers trailingHeaders) {
if (!trailingHeaders.isEndOfStream()) {
responseFuture.completeExceptionally(new IllegalArgumentException("An assumption we made was wrong. isComplete should be true here"));
throw new IllegalArgumentException("An assumption we made was wrong. isComplete should be true here");
}
FullResponse response = new FullResponse(resp, fullData, trailingHeaders);
responseFuture.complete(response);
}
use of org.webpieces.http2client.api.dto.FullResponse 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());
}
use of org.webpieces.http2client.api.dto.FullResponse in project webpieces by deanhiller.
the class Http2SocketImpl method send.
/**
* Can't specifically backpressure with this method(ie. On the other method, if you do not ack, eventually
* with too many bytes, the channelmanager disregisters and stops reading from the socket placing backpressure
* on the socket)
*/
@Override
public CompletableFuture<FullResponse> send(FullRequest request) {
SingleResponseListener responseListener = new SingleResponseListener();
StreamHandle streamHandle = openStream();
Http2Request req = request.getHeaders();
if (request.getPayload() == null) {
request.getHeaders().setEndOfStream(true);
streamHandle.process(req, responseListener);
return responseListener.fetchResponseFuture();
} else if (request.getTrailingHeaders() == null) {
request.getHeaders().setEndOfStream(false);
DataFrame data = createData(request, true);
return streamHandle.process(request.getHeaders(), responseListener).thenCompose(writer -> {
data.setStreamId(req.getStreamId());
return writer.processPiece(data);
}).thenCompose(writer -> responseListener.fetchResponseFuture());
}
request.getHeaders().setEndOfStream(false);
DataFrame data = createData(request, false);
Http2Trailers trailers = request.getTrailingHeaders();
trailers.setEndOfStream(true);
return streamHandle.process(request.getHeaders(), responseListener).thenCompose(writer -> {
data.setStreamId(req.getStreamId());
return writer.processPiece(data);
}).thenCompose(writer -> {
trailers.setStreamId(req.getStreamId());
return writer.processPiece(trailers);
}).thenCompose(writer -> responseListener.fetchResponseFuture());
}
use of org.webpieces.http2client.api.dto.FullResponse 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 org.webpieces.http2client.api.dto.FullResponse 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());
}
Aggregations