HttpClientDelegate implements HttpClient { @VisibleForTesting static String extractHost(ClientRequestContext ctx, HttpRequest req, Endpoint endpoint) { String host = extractHost(ctx.additionalRequestHeaders().get(HttpHeaderNames.AUTHORITY)); if (host != null) { return host; } host = extractHost(req.authority()); if (host != null) { return host; } return endpoint.host(); } HttpClientDelegate(HttpClientFactory factory,
                       AddressResolverGroup<InetSocketAddress> addressResolverGroup); @Override HttpResponse execute(ClientRequestContext ctx, HttpRequest req);  }
@Test public void testExtractHost() { assertThat(extractHost(context(HttpHeaders.of(HttpHeaderNames.AUTHORITY, "foo")), HttpRequest.of(RequestHeaders.of(HttpMethod.GET, "/", HttpHeaderNames.AUTHORITY, "bar:8080")), Endpoint.of("baz", 8080))).isEqualTo("foo"); assertThat(extractHost(context(HttpHeaders.of()), HttpRequest.of(RequestHeaders.of(HttpMethod.GET, "/", HttpHeaderNames.AUTHORITY, "bar:8080")), Endpoint.of("baz", 8080))).isEqualTo("bar"); assertThat(extractHost(context(HttpHeaders.of()), HttpRequest.of(HttpMethod.GET, "/"), Endpoint.of("baz", 8080))).isEqualTo("baz"); assertThat(extractHost(context(HttpHeaders.of(HttpHeaderNames.AUTHORITY, "[::1]:8443")), HttpRequest.of(HttpMethod.GET, "/"), Endpoint.of("baz", 8080))).isEqualTo("::1"); assertThat(extractHost(context(HttpHeaders.of(HttpHeaderNames.AUTHORITY, "[::1")), HttpRequest.of(HttpMethod.GET, "/"), Endpoint.of("baz", 8080))).isEqualTo("baz"); assertThat(extractHost(context(HttpHeaders.of(HttpHeaderNames.AUTHORITY, ":8080")), HttpRequest.of(HttpMethod.GET, "/"), Endpoint.of("baz", 8080))).isEqualTo("baz"); assertThat(extractHost(context(HttpHeaders.of(HttpHeaderNames.AUTHORITY, "[::1")), HttpRequest.of(RequestHeaders.of(HttpMethod.GET, "/", HttpHeaderNames.AUTHORITY, "bar")), Endpoint.of("baz", 8080))).isEqualTo("bar"); assertThat(extractHost(context(HttpHeaders.of(HttpHeaderNames.AUTHORITY, ":8080")), HttpRequest.of(RequestHeaders.of(HttpMethod.GET, "/", HttpHeaderNames.AUTHORITY, "bar")), Endpoint.of("baz", 8080))).isEqualTo("bar"); }