use of io.servicetalk.http.api.HttpResponse in project servicetalk by apple.
the class HttpProxyTest method testBuilderReuseEachClientUsesOwnProxy.
@Test
void testBuilderReuseEachClientUsesOwnProxy() throws Exception {
final SingleAddressHttpClientBuilder<HostAndPort, InetSocketAddress> builder = HttpClients.forSingleAddress(serverAddress);
final BlockingHttpClient client = builder.proxyAddress(proxyAddress).buildBlocking();
final HttpClient otherProxyClient = HttpClients.forMultiAddressUrl().build();
final AtomicInteger otherProxyRequestCount = new AtomicInteger();
try (ServerContext otherProxyContext = HttpServers.forAddress(localAddress(0)).listenAndAwait((ctx, request, responseFactory) -> {
otherProxyRequestCount.incrementAndGet();
return otherProxyClient.request(request);
});
BlockingHttpClient otherClient = builder.proxyAddress(serverHostAndPort(otherProxyContext)).appendConnectionFactoryFilter(new TargetAddressCheckConnectionFactoryFilter(targetAddress, false)).buildBlocking()) {
final HttpResponse httpResponse = otherClient.request(client.get("/path"));
assertThat(httpResponse.status(), is(OK));
assertThat(otherProxyRequestCount.get(), is(1));
assertThat(httpResponse.payloadBody().toString(US_ASCII), is("host: " + serverAddress));
}
final HttpResponse httpResponse = client.request(client.get("/path"));
assertThat(httpResponse.status(), is(OK));
assertThat(proxyRequestCount.get(), is(1));
assertThat(httpResponse.payloadBody().toString(US_ASCII), is("host: " + serverAddress));
assertThat(targetAddress.get(), is(equalTo(serverAddress.toString())));
}
use of io.servicetalk.http.api.HttpResponse in project servicetalk by apple.
the class HttpRawDataSerializationTest method runTest.
private static <T> void runTest(T[] content, String contentType, int expectedContentLength, HttpStreamingSerializer<T> streamingSerializer) throws Exception {
try (ServerContext srv = HttpServers.forAddress(localAddress(0)).listenStreamingAndAwait((ctx, request, responseFactory) -> succeeded(responseFactory.ok().payloadBody(from(content), streamingSerializer)));
BlockingHttpClient clt = HttpClients.forSingleAddress(serverHostAndPort(srv)).buildBlocking()) {
HttpResponse resp = clt.request(clt.get("/hello"));
assertThat(Objects.toString(resp.headers().get(CONTENT_TYPE)), is(contentType));
assertThat(resp.payloadBody().readableBytes(), is(expectedContentLength));
}
}
use of io.servicetalk.http.api.HttpResponse in project servicetalk by apple.
the class HttpServerFilterOrderTest method nonOffloadOrder.
@Test
void nonOffloadOrder() throws Exception {
StreamingHttpService filter1 = newMockService();
StreamingHttpService filter2 = newMockService();
ServerContext serverContext = HttpServers.forAddress(localAddress(0)).appendNonOffloadingServiceFilter(addFilter(filter1)).appendNonOffloadingServiceFilter(addFilter(filter2)).listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok());
BlockingHttpClient client = forSingleAddress(serverHostAndPort(serverContext)).buildBlocking();
HttpResponse resp = client.request(client.get("/"));
assertThat("Unexpected response.", resp.status(), is(OK));
InOrder verifier = inOrder(filter1, filter2);
verifier.verify(filter1).handle(any(), any(), any());
verifier.verify(filter2).handle(any(), any(), any());
}
use of io.servicetalk.http.api.HttpResponse in project servicetalk by apple.
the class HttpServerFilterOrderTest method mixedFiltersOrder.
@Test
void mixedFiltersOrder() throws Exception {
StreamingHttpService filter1 = newMockService();
StreamingHttpService filter2 = newMockService();
ServerContext serverContext = HttpServers.forAddress(localAddress(0)).appendServiceFilter(addFilter(filter2)).appendNonOffloadingServiceFilter(addFilter(filter1)).listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok());
BlockingHttpClient client = forSingleAddress(serverHostAndPort(serverContext)).buildBlocking();
HttpResponse resp = client.request(client.get("/"));
assertThat("Unexpected response.", resp.status(), is(OK));
InOrder verifier = inOrder(filter1, filter2);
verifier.verify(filter1).handle(any(), any(), any());
verifier.verify(filter2).handle(any(), any(), any());
}
use of io.servicetalk.http.api.HttpResponse in project servicetalk by apple.
the class HttpServerFilterOrderTest method prependOrder.
@Test
void prependOrder() throws Exception {
StreamingHttpService filter1 = newMockService();
StreamingHttpService filter2 = newMockService();
ServerContext serverContext = HttpServers.forAddress(localAddress(0)).appendServiceFilter(addFilter(filter1)).appendServiceFilter(addFilter(filter2)).listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok());
BlockingHttpClient client = forSingleAddress(serverHostAndPort(serverContext)).buildBlocking();
HttpResponse resp = client.request(client.get("/"));
assertThat("Unexpected response.", resp.status(), is(OK));
InOrder verifier = inOrder(filter1, filter2);
verifier.verify(filter1).handle(any(), any(), any());
verifier.verify(filter2).handle(any(), any(), any());
}
Aggregations