Search in sources :

Example 1 with TargetAddressCheckConnectionFactoryFilter

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);
}
Also used : BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) TargetAddressCheckConnectionFactoryFilter(io.servicetalk.http.netty.HttpsProxyTest.TargetAddressCheckConnectionFactoryFilter) HttpResponse(io.servicetalk.http.api.HttpResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with TargetAddressCheckConnectionFactoryFilter

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())));
}
Also used : AddressUtils.serverHostAndPort(io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort) HostAndPort(io.servicetalk.transport.api.HostAndPort) ServerContext(io.servicetalk.transport.api.ServerContext) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TargetAddressCheckConnectionFactoryFilter(io.servicetalk.http.netty.HttpsProxyTest.TargetAddressCheckConnectionFactoryFilter) InetSocketAddress(java.net.InetSocketAddress) HttpClient(io.servicetalk.http.api.HttpClient) BlockingHttpClient(io.servicetalk.http.api.BlockingHttpClient) HttpResponse(io.servicetalk.http.api.HttpResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

BlockingHttpClient (io.servicetalk.http.api.BlockingHttpClient)2 HttpResponse (io.servicetalk.http.api.HttpResponse)2 TargetAddressCheckConnectionFactoryFilter (io.servicetalk.http.netty.HttpsProxyTest.TargetAddressCheckConnectionFactoryFilter)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 HttpClient (io.servicetalk.http.api.HttpClient)1 HostAndPort (io.servicetalk.transport.api.HostAndPort)1 ServerContext (io.servicetalk.transport.api.ServerContext)1 AddressUtils.serverHostAndPort (io.servicetalk.transport.netty.internal.AddressUtils.serverHostAndPort)1 InetSocketAddress (java.net.InetSocketAddress)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Test (org.junit.jupiter.api.Test)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1