use of io.servicetalk.http.netty.HttpsProxyTest.TargetAddressCheckConnectionFactoryFilter in project servicetalk by apple.
the class HttpProxyTest method testRequest.
@ParameterizedTest(name = "[{index}] client = {0}")
@EnumSource
void testRequest(ClientSource clientSource) throws Exception {
assert serverAddress != null && proxyAddress != null;
final BlockingHttpClient client = clientSource.clientBuilderFactory.apply(serverAddress).proxyAddress(proxyAddress).appendConnectionFactoryFilter(new TargetAddressCheckConnectionFactoryFilter(targetAddress, false)).buildBlocking();
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())));
safeClose(client);
}
use of io.servicetalk.http.netty.HttpsProxyTest.TargetAddressCheckConnectionFactoryFilter 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())));
}
Aggregations