use of io.servicetalk.http.api.StreamingHttpClient in project servicetalk by apple.
the class H2PriorKnowledgeFeatureParityTest method clientAllowDropTrailers.
private void clientAllowDropTrailers(boolean allowDrop, boolean serverAddTrailerHeader) throws Exception {
String trailerName = "t1";
String trailerValue = "v1";
InetSocketAddress serverAddress = serverAddTrailerHeader ? bindHttpEchoServerWithTrailer(trailerName) : bindHttpEchoServer();
try (StreamingHttpClient client = forSingleAddress(HostAndPort.of(serverAddress)).protocols(h2PriorKnowledge ? h2Default() : h1Default()).allowDropResponseTrailers(allowDrop).executionStrategy(clientExecutionStrategy).buildStreaming()) {
StreamingHttpResponse response = client.request(client.get("/").transform(new StatelessTrailersTransformer<Buffer>() {
@Override
protected HttpHeaders payloadComplete(final HttpHeaders trailers) {
trailers.add(trailerName, trailerValue);
return trailers;
}
})).toFuture().get();
SingleSource.Processor<HttpHeaders, HttpHeaders> trailersProcessor = Processors.newSingleProcessor();
// intermediate Buffer transform may drop trailers
response.transformPayloadBody(buf -> buf).transform(new StatelessTrailersTransformer<Buffer>() {
@Override
protected HttpHeaders payloadComplete(final HttpHeaders trailers) {
trailersProcessor.onSuccess(trailers);
return trailers;
}
}).messageBody().ignoreElements().toFuture().get();
HttpHeaders responseTrailers = fromSource(trailersProcessor).toFuture().get();
if (allowDrop && !serverAddTrailerHeader) {
assertFalse(responseTrailers.contains(trailerName));
} else {
assertHeaderValue(responseTrailers, trailerName, trailerValue);
}
}
}
use of io.servicetalk.http.api.StreamingHttpClient in project servicetalk by apple.
the class H2PriorKnowledgeFeatureParityTest method clientGracefulClose.
@ParameterizedTest(name = "{displayName} [{index}] client={0}, h2PriorKnowledge={1}")
@MethodSource("clientExecutors")
void clientGracefulClose(HttpTestExecutionStrategy strategy, boolean h2PriorKnowledge) throws Exception {
setUp(strategy, h2PriorKnowledge);
InetSocketAddress serverAddress = bindHttpEchoServer();
StreamingHttpClient client = forSingleAddress(HostAndPort.of(serverAddress)).protocols(h2PriorKnowledge ? h2Default() : h1Default()).executionStrategy(clientExecutionStrategy).buildStreaming();
CountDownLatch onCloseLatch = new CountDownLatch(1);
Processor<Buffer, Buffer> requestBody = newProcessor();
client.onClose().subscribe(onCloseLatch::countDown);
// We want to make a request, and intentionally not complete it. While the request is in process we invoke
// closeAsyncGracefully and verify that we wait until the request has completed before the underlying
// transport is closed.
StreamingHttpRequest request = client.post("/").payloadBody(fromSource(requestBody));
StreamingHttpResponse response = client.request(request).toFuture().get();
client.closeAsyncGracefully().subscribe();
// We expect this to timeout, because we have not completed the outstanding request.
assertFalse(onCloseLatch.await(300, MILLISECONDS));
requestBody.onComplete();
response.payloadBody().ignoreElements().toFuture();
onCloseLatch.await();
}
use of io.servicetalk.http.api.StreamingHttpClient in project servicetalk by apple.
the class H2PriorKnowledgeFeatureParityTest method continue100.
private void continue100(boolean failExpectation) throws Exception {
InetSocketAddress serverAddress = bindHttpEchoServer();
try (StreamingHttpClient client = forSingleAddress(HostAndPort.of(serverAddress)).protocols(h2PriorKnowledge ? h2Default() : h1Default()).executionStrategy(clientExecutionStrategy).buildStreaming()) {
Processor<Buffer, Buffer> requestBody1 = newProcessor();
StreamingHttpRequest request = client.post("/").payloadBody(fromSource(requestBody1));
request.addHeader(EXPECT, CONTINUE);
if (failExpectation) {
request.addHeader(EXPECT_FAIL_HEADER, "notused");
}
StreamingHttpResponse response = client.request(request).toFuture().get();
if (failExpectation) {
assertEquals(EXPECTATION_FAILED, response.status());
assertFalse(response.payloadBody().toIterable().iterator().hasNext());
} else {
assertEquals(HttpResponseStatus.CONTINUE, response.status());
String payloadBody = "foo";
requestBody1.onNext(client.executionContext().bufferAllocator().fromAscii(payloadBody));
requestBody1.onComplete();
Iterator<Buffer> responseBody = response.payloadBody().toIterable().iterator();
assertTrue(responseBody.hasNext());
Buffer next = responseBody.next();
assertNotNull(next);
assertEquals(payloadBody, next.toString(UTF_8));
assertFalse(responseBody.hasNext());
}
}
}
use of io.servicetalk.http.api.StreamingHttpClient in project servicetalk by apple.
the class H2PriorKnowledgeFeatureParityTest method fullDuplexMode.
@ParameterizedTest(name = "{displayName} [{index}] client={0}, h2PriorKnowledge={1}")
@MethodSource("clientExecutors")
void fullDuplexMode(HttpTestExecutionStrategy strategy, boolean h2PriorKnowledge) throws Exception {
setUp(strategy, h2PriorKnowledge);
InetSocketAddress serverAddress = bindHttpEchoServer();
try (StreamingHttpClient client = forSingleAddress(HostAndPort.of(serverAddress)).protocols(h2PriorKnowledge ? h2Default() : h1Default()).executionStrategy(clientExecutionStrategy).buildStreaming()) {
Processor<Buffer, Buffer> requestBody1 = newProcessor();
StreamingHttpResponse response1 = client.request(client.post("/0").payloadBody(fromSource(requestBody1))).toFuture().get();
Processor<Buffer, Buffer> requestBody2 = newProcessor();
StreamingHttpResponse response2 = client.request(client.post("/1").payloadBody(fromSource(requestBody2))).toFuture().get();
Iterator<Buffer> response1Payload = response1.payloadBody().toIterable().iterator();
Iterator<Buffer> response2Payload = response2.payloadBody().toIterable().iterator();
fullDuplexModeWrite(client, requestBody1, "foo1", requestBody2, "bar1", response1Payload, response2Payload);
fullDuplexModeWrite(client, requestBody1, "foo2", requestBody2, "bar2", response1Payload, response2Payload);
requestBody1.onComplete();
requestBody2.onComplete();
assertFalse(response1Payload.hasNext());
assertFalse(response2Payload.hasNext());
}
}
use of io.servicetalk.http.api.StreamingHttpClient in project servicetalk by apple.
the class HttpClientAsyncContextTest method makeClientRequestWithId.
private static void makeClientRequestWithId(StreamingHttpClient client, String requestId) throws ExecutionException, InterruptedException {
StreamingHttpRequest request = client.get("/");
request.headers().set(REQUEST_ID_HEADER, requestId);
client.request(request).whenOnSuccess(response -> assertEquals(OK, response.status())).flatMapCompletable(response -> response.messageBody().ignoreElements()).toFuture().get();
}
Aggregations