Skip to content

Commit

Permalink
Remove unnecessary proxyAddress from HttpClientBuildContext (#2720)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
idelpivnitskiy authored Oct 3, 2023
1 parent da1ea3b commit 2aacf9e
Showing 1 changed file with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,26 +176,20 @@ private static final class HttpClientBuildContext<U, R> {

@Nullable
private final BiIntFunction<Throwable, ? extends Completable> serviceDiscovererRetryStrategy;
@Nullable
private final U proxyAddress;

HttpClientBuildContext(
final DefaultSingleAddressHttpClientBuilder<U, R> builder,
final ServiceDiscoverer<U, R, ? extends ServiceDiscovererEvent<R>> sd,
@Nullable final BiIntFunction<Throwable, ? extends Completable> serviceDiscovererRetryStrategy,
@Nullable final U proxyAddress) {
@Nullable final BiIntFunction<Throwable, ? extends Completable> 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() {
Expand Down Expand Up @@ -383,8 +377,9 @@ private static StreamingHttpRequestResponseFactory defaultReqRespFactory(ReadOnl
}

private static <U, R> String targetAddress(final HttpClientBuildContext<U, R> 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(
Expand Down Expand Up @@ -433,7 +428,7 @@ private static ContextAwareStreamingHttpClientFilterFactory appendFilter(
*/
private HttpClientBuildContext<U, R> copyBuildCtx() {
return new HttpClientBuildContext<>(new DefaultSingleAddressHttpClientBuilder<>(address, this),
this.serviceDiscoverer, this.serviceDiscovererRetryStrategy, this.proxyAddress);
this.serviceDiscoverer, this.serviceDiscovererRetryStrategy);
}

private AbsoluteAddressHttpRequesterFilter proxyAbsoluteAddressFilterFactory() {
Expand Down

0 comments on commit 2aacf9e

Please sign in to comment.