use of io.servicetalk.transport.api.HostAndPort in project servicetalk by apple.
the class HttpClientBuilderTest method sendRequestAndValidate.
private void sendRequestAndValidate(final Publisher<ServiceDiscovererEvent<InetSocketAddress>> sdPub) throws ExecutionException, InterruptedException {
@SuppressWarnings("unchecked") ServiceDiscoverer<HostAndPort, InetSocketAddress, ServiceDiscovererEvent<InetSocketAddress>> disco = mock(ServiceDiscoverer.class);
when(disco.discover(any())).thenReturn(sdPub.map(Collections::singletonList));
StreamingHttpClient requester = HttpClients.forSingleAddress(serverHostAndPort(serverContext)).serviceDiscoverer(disco).ioExecutor(CTX.ioExecutor()).executionStrategy(offloadNone()).buildStreaming();
makeRequestValidateResponseAndClose(requester);
}
use of io.servicetalk.transport.api.HostAndPort in project servicetalk by apple.
the class MixedFiltersTest method testSingleClient.
@ParameterizedTest(name = "{displayName} [{index}] filters={0}")
@MethodSource("arguments")
void testSingleClient(List<AbstractFactoryFilter> filters) throws Exception {
String expected = filters.stream().map(AbstractFactoryFilter::toString).reduce((first, second) -> first + ',' + second).get();
try (ServerContext serverContext = HttpServers.forAddress(localAddress(0)).listenBlockingAndAwait((ctx, request, responseFactory) -> responseFactory.ok())) {
SingleAddressHttpClientBuilder<HostAndPort, InetSocketAddress> builder = HttpClients.forSingleAddress(serverHostAndPort(serverContext));
filters.forEach(builder::appendConnectionFactoryFilter);
try (BlockingHttpClient client = builder.buildBlocking()) {
AtomicReference<StringBuilder> ref = new AtomicReference<>(new StringBuilder());
AsyncContext.put(KEY, ref);
HttpResponse response = client.request(client.get("/"));
assertThat(response.status(), is(OK));
assertThat(ref.toString(), is(equalTo(expected)));
}
}
}
use of io.servicetalk.transport.api.HostAndPort in project servicetalk by apple.
the class MultiAddressUrlHttpClientTest method beforeClass.
@BeforeAll
static void beforeClass() throws Exception {
afterClassCloseables = newCompositeCloseable();
client = afterClassCloseables.append(HttpClients.forMultiAddressUrl().followRedirects(new RedirectConfigBuilder().allowNonRelativeRedirects(true).build()).initializer((scheme, address, builder) -> builder.serviceDiscoverer(sdThatSupportsInvalidHostname())).buildStreaming());
httpService = (ctx, request, factory) -> {
if (HTTP_1_1.equals(request.version()) && !request.headers().contains(HOST)) {
return succeeded(factory.badRequest().setHeader(CONTENT_LENGTH, ZERO));
}
if (OPTIONS.equals(request.method()) || CONNECT.equals(request.method())) {
return succeeded(factory.ok().setHeader(CONTENT_LENGTH, ZERO));
}
StreamingHttpResponse response;
try {
HttpResponseStatus status = HttpResponseStatus.of(parseInt(request.path().substring(1)), "");
response = factory.newResponse(status);
final CharSequence locationHeader = request.headers().get(X_REQUESTED_LOCATION);
if (locationHeader != null) {
response.headers().set(LOCATION, locationHeader);
}
} catch (Exception e) {
response = factory.badRequest();
}
return succeeded(response.setHeader(CONTENT_LENGTH, ZERO).setHeader(X_RECEIVED_REQUEST_TARGET, request.requestTarget()));
};
final ServerContext serverCtx = startNewLocalServer(httpService, afterClassCloseables);
final HostAndPort serverHostAndPort = serverHostAndPort(serverCtx);
serverHost = serverHostAndPort.hostName();
serverPort = serverHostAndPort.port();
hostHeader = hostHeader(serverHostAndPort);
}
use of io.servicetalk.transport.api.HostAndPort in project servicetalk by apple.
the class SecurityHandshakeObserverTest method withProxyTunnel.
@Test
void withProxyTunnel() throws Exception {
try (ProxyTunnel proxyTunnel = new ProxyTunnel()) {
HostAndPort proxyAddress = proxyTunnel.startProxy();
verifyHandshakeObserved(HttpServers::forAddress, address -> forSingleAddress(address).proxyAddress(proxyAddress));
}
}
use of io.servicetalk.transport.api.HostAndPort in project servicetalk by apple.
the class HttpProvidersTest method testMultiAddressHttpClientBuilderProvider.
@Test
void testMultiAddressHttpClientBuilderProvider() throws Exception {
try (ServerContext serverContext = HttpServers.forAddress(localAddress(0)).listenStreamingAndAwait(new TestServiceStreaming())) {
HostAndPort serverAddress = serverHostAndPort(serverContext);
TestSingleAddressHttpClientBuilderProvider.MODIFY_FOR_ADDRESS.set(serverAddress);
try (BlockingHttpClient client = HttpClients.forMultiAddressUrl().buildBlocking()) {
assertThat(TestMultiAddressHttpClientBuilderProvider.BUILD_COUNTER.get(), is(1));
HttpResponse response = client.request(client.get("http://" + serverAddress + SVC_ECHO));
assertThat(response.status(), is(OK));
assertThat(TestSingleAddressHttpClientBuilderProvider.BUILD_COUNTER.get(), is(1));
assertThat(TestSingleAddressHttpClientBuilderProvider.CONNECTION_COUNTER.get(), is(1));
}
}
}
Aggregations