use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class BlockingUdsClient method main.
public static void main(String[] args) throws Exception {
try (BlockingHttpClient client = HttpClients.forResolvedAddress(udsAddress()).buildBlocking()) {
HttpResponse response = client.request(client.get("/sayHello"));
System.out.println(response.toString((name, value) -> value));
System.out.println(response.payloadBody(textSerializerUtf8()));
}
}
use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class H2PriorKnowledgeFeatureParityTest method serverWriteTrailers.
@ParameterizedTest(name = "{displayName} [{index}] client={0}, h2PriorKnowledge={1}")
@MethodSource("clientExecutors")
void serverWriteTrailers(HttpTestExecutionStrategy strategy, boolean h2PriorKnowledge) throws Exception {
setUp(strategy, h2PriorKnowledge);
String payloadBody = "foo";
String myTrailerName = "mytrailer";
h1ServerContext = HttpServers.forAddress(localAddress(0)).protocols(h2PriorKnowledge ? h2Default() : h1Default()).listenStreaming((ctx, request, responseFactory) -> request.payloadBody().map(Buffer::readableBytes).collect(AtomicInteger::new, (contentSize, bufferSize) -> {
contentSize.addAndGet(bufferSize);
return contentSize;
}).flatMap(contentSize -> succeeded(responseFactory.ok().transform(new ContentSizeTrailersTransformer(myTrailerName, contentSize))))).toFuture().get();
InetSocketAddress serverAddress = (InetSocketAddress) h1ServerContext.listenAddress();
try (BlockingHttpClient client = forSingleAddress(HostAndPort.of(serverAddress)).protocols(h2PriorKnowledge ? h2Default() : h1Default()).executionStrategy(clientExecutionStrategy).buildBlocking()) {
HttpRequest request = client.post("/").payloadBody(payloadBody, textSerializerUtf8());
HttpResponse response = client.request(request);
assertEquals(0, response.payloadBody().readableBytes());
CharSequence responseTrailer = response.trailers().get(myTrailerName);
assertNotNull(responseTrailer);
assertEquals(payloadBody.length(), Integer.parseInt(responseTrailer.toString()));
}
}
use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class H2PriorKnowledgeFeatureParityTest method serverHeaderCookieRemovalAndIteration.
@ParameterizedTest(name = "{displayName} [{index}] client={0}, h2PriorKnowledge={1}")
@MethodSource("clientExecutors")
void serverHeaderCookieRemovalAndIteration(HttpTestExecutionStrategy strategy, boolean h2PriorKnowledge) throws Exception {
setUp(strategy, h2PriorKnowledge);
InetSocketAddress serverAddress = bindHttpSynchronousResponseServer(request -> headerCookieRemovalAndIteration(request.headers()));
try (BlockingHttpClient client = forSingleAddress(HostAndPort.of(serverAddress)).protocols(h2PriorKnowledge ? h2Default() : h1Default()).executionStrategy(clientExecutionStrategy).buildBlocking()) {
assertThat(client.request(client.get("/").payloadBody("", textSerializerUtf8())).payloadBody(textSerializerUtf8()), is(emptyString()));
}
}
use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class H2PriorKnowledgeFeatureParityTest method serverAllowDropTrailers.
private void serverAllowDropTrailers(boolean allowDrop, boolean clientAddTrailerHeader) throws Exception {
String trailerName = "t1";
String trailerValue = "v1";
SingleSource.Processor<HttpHeaders, HttpHeaders> trailersProcessor = Processors.newSingleProcessor();
h1ServerContext = HttpServers.forAddress(localAddress(0)).protocols(h2PriorKnowledge ? h2Default() : h1Default()).allowDropRequestTrailers(allowDrop).listenStreamingAndAwait((ctx, request, responseFactory) -> succeeded(responseFactory.ok().payloadBody(// intermediate Buffer transform may drop trailers
request.transformPayloadBody(buf -> buf).transform(new StatelessTrailersTransformer<Buffer>() {
@Override
protected HttpHeaders payloadComplete(final HttpHeaders trailers) {
trailersProcessor.onSuccess(trailers);
return trailers;
}
}).payloadBody())));
InetSocketAddress serverAddress = (InetSocketAddress) h1ServerContext.listenAddress();
try (BlockingHttpClient client = forSingleAddress(HostAndPort.of(serverAddress)).protocols(h2PriorKnowledge ? h2Default() : h1Default()).allowDropResponseTrailers(allowDrop).executionStrategy(clientExecutionStrategy).buildBlocking()) {
HttpRequest request = client.get("/");
if (clientAddTrailerHeader) {
request.headers().add(TRAILER, trailerName);
}
request.trailers().add(trailerName, trailerValue);
client.request(request);
HttpHeaders requestTrailers = fromSource(trailersProcessor).toFuture().get();
if (allowDrop && !clientAddTrailerHeader) {
assertFalse(requestTrailers.contains(trailerName));
} else {
assertHeaderValue(requestTrailers, trailerName, trailerValue);
}
}
}
use of io.servicetalk.http.api.BlockingHttpClient in project servicetalk by apple.
the class H2PriorKnowledgeFeatureParityTest method serverHeaderSetCookieRemovalAndIteration.
@ParameterizedTest(name = "{displayName} [{index}] client={0}, h2PriorKnowledge={1}")
@MethodSource("clientExecutors")
void serverHeaderSetCookieRemovalAndIteration(HttpTestExecutionStrategy strategy, boolean h2PriorKnowledge) throws Exception {
setUp(strategy, h2PriorKnowledge);
InetSocketAddress serverAddress = bindHttpSynchronousResponseServer(request -> headerSetCookieRemovalAndIteration(request.headers()));
try (BlockingHttpClient client = forSingleAddress(HostAndPort.of(serverAddress)).protocols(h2PriorKnowledge ? h2Default() : h1Default()).executionStrategy(clientExecutionStrategy).buildBlocking()) {
assertThat(client.request(client.get("/").payloadBody("", textSerializerUtf8())).payloadBody(textSerializerUtf8()), is(emptyString()));
}
}
Aggregations