From 2aacf9e6941b4d90fa24b8ad20e35f12184cdad6 Mon Sep 17 00:00:00 2001 From: Idel Pivnitskiy Date: Mon, 2 Oct 2023 23:28:56 -0700 Subject: [PATCH] Remove unnecessary `proxyAddress` from `HttpClientBuildContext` (#2720) Motivation: `HttpClientBuildContext` takes a copy of `DefaultSingleAddressHttpClientBuilder`. There is no need to worry that `ctx.builder.proxyAddress` can change. As the result, we can safely remove `ctx.proxyAddress`. Modifications: - Remove `HttpClientBuildContext.proxyAddress`; Result: Less code. --- .../DefaultSingleAddressHttpClientBuilder.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/servicetalk-http-netty/src/main/java/io/servicetalk/http/netty/DefaultSingleAddressHttpClientBuilder.java b/servicetalk-http-netty/src/main/java/io/servicetalk/http/netty/DefaultSingleAddressHttpClientBuilder.java index 0cee7535b8..ec0a25c6c7 100644 --- a/servicetalk-http-netty/src/main/java/io/servicetalk/http/netty/DefaultSingleAddressHttpClientBuilder.java +++ b/servicetalk-http-netty/src/main/java/io/servicetalk/http/netty/DefaultSingleAddressHttpClientBuilder.java @@ -176,26 +176,20 @@ private static final class HttpClientBuildContext { @Nullable private final BiIntFunction serviceDiscovererRetryStrategy; - @Nullable - private final U proxyAddress; HttpClientBuildContext( final DefaultSingleAddressHttpClientBuilder builder, final ServiceDiscoverer> sd, - @Nullable final BiIntFunction serviceDiscovererRetryStrategy, - @Nullable final U proxyAddress) { + @Nullable final BiIntFunction serviceDiscovererRetryStrategy) { this.builder = builder; this.serviceDiscovererRetryStrategy = serviceDiscovererRetryStrategy; - this.proxyAddress = proxyAddress; this.sd = sd; this.sdStatus = new SdStatusCompletable(); } U address() { assert builder.address != null : "Attempted to buildStreaming with an unknown address"; - return proxyAddress != null ? proxyAddress : - // the builder can be modified post-context creation, therefore proxy can be set - (builder.proxyAddress != null ? builder.proxyAddress : builder.address); + return builder.proxyAddress != null ? builder.proxyAddress : builder.address; } HttpClientConfig httpConfig() { @@ -383,8 +377,9 @@ private static StreamingHttpRequestResponseFactory defaultReqRespFactory(ReadOnl } private static String targetAddress(final HttpClientBuildContext ctx) { - return ctx.proxyAddress == null ? - ctx.builder.address.toString() : ctx.builder.address + " (via " + ctx.proxyAddress + ")"; + assert ctx.builder.address != null; + return ctx.builder.proxyAddress == null ? + ctx.builder.address.toString() : ctx.builder.address + " (via " + ctx.builder.proxyAddress + ")"; } private static ContextAwareStreamingHttpClientFilterFactory appendFilter( @@ -433,7 +428,7 @@ private static ContextAwareStreamingHttpClientFilterFactory appendFilter( */ private HttpClientBuildContext copyBuildCtx() { return new HttpClientBuildContext<>(new DefaultSingleAddressHttpClientBuilder<>(address, this), - this.serviceDiscoverer, this.serviceDiscovererRetryStrategy, this.proxyAddress); + this.serviceDiscoverer, this.serviceDiscovererRetryStrategy); } private AbsoluteAddressHttpRequesterFilter proxyAbsoluteAddressFilterFactory() {