Skip to content

Commit 2aacf9e

Browse files
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.
1 parent da1ea3b commit 2aacf9e

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

servicetalk-http-netty/src/main/java/io/servicetalk/http/netty/DefaultSingleAddressHttpClientBuilder.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,26 +176,20 @@ private static final class HttpClientBuildContext<U, R> {
176176

177177
@Nullable
178178
private final BiIntFunction<Throwable, ? extends Completable> serviceDiscovererRetryStrategy;
179-
@Nullable
180-
private final U proxyAddress;
181179

182180
HttpClientBuildContext(
183181
final DefaultSingleAddressHttpClientBuilder<U, R> builder,
184182
final ServiceDiscoverer<U, R, ? extends ServiceDiscovererEvent<R>> sd,
185-
@Nullable final BiIntFunction<Throwable, ? extends Completable> serviceDiscovererRetryStrategy,
186-
@Nullable final U proxyAddress) {
183+
@Nullable final BiIntFunction<Throwable, ? extends Completable> serviceDiscovererRetryStrategy) {
187184
this.builder = builder;
188185
this.serviceDiscovererRetryStrategy = serviceDiscovererRetryStrategy;
189-
this.proxyAddress = proxyAddress;
190186
this.sd = sd;
191187
this.sdStatus = new SdStatusCompletable();
192188
}
193189

194190
U address() {
195191
assert builder.address != null : "Attempted to buildStreaming with an unknown address";
196-
return proxyAddress != null ? proxyAddress :
197-
// the builder can be modified post-context creation, therefore proxy can be set
198-
(builder.proxyAddress != null ? builder.proxyAddress : builder.address);
192+
return builder.proxyAddress != null ? builder.proxyAddress : builder.address;
199193
}
200194

201195
HttpClientConfig httpConfig() {
@@ -383,8 +377,9 @@ private static StreamingHttpRequestResponseFactory defaultReqRespFactory(ReadOnl
383377
}
384378

385379
private static <U, R> String targetAddress(final HttpClientBuildContext<U, R> ctx) {
386-
return ctx.proxyAddress == null ?
387-
ctx.builder.address.toString() : ctx.builder.address + " (via " + ctx.proxyAddress + ")";
380+
assert ctx.builder.address != null;
381+
return ctx.builder.proxyAddress == null ?
382+
ctx.builder.address.toString() : ctx.builder.address + " (via " + ctx.builder.proxyAddress + ")";
388383
}
389384

390385
private static ContextAwareStreamingHttpClientFilterFactory appendFilter(
@@ -433,7 +428,7 @@ private static ContextAwareStreamingHttpClientFilterFactory appendFilter(
433428
*/
434429
private HttpClientBuildContext<U, R> copyBuildCtx() {
435430
return new HttpClientBuildContext<>(new DefaultSingleAddressHttpClientBuilder<>(address, this),
436-
this.serviceDiscoverer, this.serviceDiscovererRetryStrategy, this.proxyAddress);
431+
this.serviceDiscoverer, this.serviceDiscovererRetryStrategy);
437432
}
438433

439434
private AbsoluteAddressHttpRequesterFilter proxyAbsoluteAddressFilterFactory() {

0 commit comments

Comments
 (0)