diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/config/RequestConfig.java b/httpclient5/src/main/java/org/apache/hc/client5/http/config/RequestConfig.java index 80f345892..7b9e8b93f 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/config/RequestConfig.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/config/RequestConfig.java @@ -27,7 +27,6 @@ package org.apache.hc.client5.http.config; -import java.net.InetAddress; import java.util.Collection; import java.util.concurrent.TimeUnit; @@ -50,7 +49,6 @@ public class RequestConfig implements Cloneable { private final boolean expectContinueEnabled; private final HttpHost proxy; - private final InetAddress localAddress; private final String cookieSpec; private final boolean redirectsEnabled; private final boolean circularRedirectsAllowed; @@ -67,14 +65,13 @@ public class RequestConfig implements Cloneable { * Intended for CDI compatibility */ protected RequestConfig() { - this(false, null, null, null, false, false, 0, false, null, null, + this(false, null, null, false, false, 0, false, null, null, DEFAULT_CONNECTION_REQUEST_TIMEOUT, DEFAULT_CONNECT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT, false); } RequestConfig( final boolean expectContinueEnabled, final HttpHost proxy, - final InetAddress localAddress, final String cookieSpec, final boolean redirectsEnabled, final boolean circularRedirectsAllowed, @@ -89,7 +86,6 @@ public class RequestConfig implements Cloneable { super(); this.expectContinueEnabled = expectContinueEnabled; this.proxy = proxy; - this.localAddress = localAddress; this.cookieSpec = cookieSpec; this.redirectsEnabled = redirectsEnabled; this.circularRedirectsAllowed = circularRedirectsAllowed; @@ -139,21 +135,6 @@ public class RequestConfig implements Cloneable { return proxy; } - /** - * Returns local address to be used for request execution. - *
- * On machines with multiple network interfaces, this parameter - * can be used to select the network interface from which the - * connection originates. - *
- *- * Default: {@code null} - *
- */ - public InetAddress getLocalAddress() { - return localAddress; - } - /** * Determines the name of the cookie specification to be used for HTTP state * management. @@ -300,7 +281,6 @@ public class RequestConfig implements Cloneable { builder.append("["); builder.append("expectContinueEnabled=").append(expectContinueEnabled); builder.append(", proxy=").append(proxy); - builder.append(", localAddress=").append(localAddress); builder.append(", cookieSpec=").append(cookieSpec); builder.append(", redirectsEnabled=").append(redirectsEnabled); builder.append(", maxRedirects=").append(maxRedirects); @@ -324,7 +304,6 @@ public class RequestConfig implements Cloneable { return new Builder() .setExpectContinueEnabled(config.isExpectContinueEnabled()) .setProxy(config.getProxy()) - .setLocalAddress(config.getLocalAddress()) .setCookieSpec(config.getCookieSpec()) .setRedirectsEnabled(config.isRedirectsEnabled()) .setCircularRedirectsAllowed(config.isCircularRedirectsAllowed()) @@ -342,7 +321,6 @@ public class RequestConfig implements Cloneable { private boolean expectContinueEnabled; private HttpHost proxy; - private InetAddress localAddress; private String cookieSpec; private boolean redirectsEnabled; private boolean circularRedirectsAllowed; @@ -376,11 +354,6 @@ public class RequestConfig implements Cloneable { return this; } - public Builder setLocalAddress(final InetAddress localAddress) { - this.localAddress = localAddress; - return this; - } - public Builder setCookieSpec(final String cookieSpec) { this.cookieSpec = cookieSpec; return this; @@ -455,7 +428,6 @@ public class RequestConfig implements Cloneable { return new RequestConfig( expectContinueEnabled, proxy, - localAddress, cookieSpec, redirectsEnabled, circularRedirectsAllowed, diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java index d415bc6db..c68ee4acb 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/classic/ProxyClient.java @@ -148,7 +148,7 @@ public class ProxyClient { } final HttpRoute route = new HttpRoute( host, - this.requestConfig.getLocalAddress(), + null, proxy, false, TunnelType.TUNNELLED, LayerType.PLAIN); final ManagedHttpClientConnection conn = this.connFactory.createConnection(null); diff --git a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultRoutePlanner.java b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultRoutePlanner.java index 2505bbed5..02cc5ab88 100644 --- a/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultRoutePlanner.java +++ b/httpclient5/src/main/java/org/apache/hc/client5/http/impl/routing/DefaultRoutePlanner.java @@ -63,13 +63,12 @@ public class DefaultRoutePlanner implements HttpRoutePlanner { } @Override - public HttpRoute determineRoute(final HttpHost host, final HttpContext context) throws HttpException { + public final HttpRoute determineRoute(final HttpHost host, final HttpContext context) throws HttpException { if (host == null) { throw new ProtocolException("Target host is not specified"); } final HttpClientContext clientContext = HttpClientContext.adapt(context); final RequestConfig config = clientContext.getRequestConfig(); - final InetAddress local = config.getLocalAddress(); HttpHost proxy = config.getProxy(); if (proxy == null) { proxy = determineProxy(host, context); @@ -90,14 +89,14 @@ public class DefaultRoutePlanner implements HttpRoutePlanner { } final boolean secure = target.getSchemeName().equalsIgnoreCase("https"); if (proxy == null) { - return new HttpRoute(target, local, secure); + return new HttpRoute(target, determineLocalAddress(target, context), secure); } else { - return new HttpRoute(target, local, proxy, secure); + return new HttpRoute(target, determineLocalAddress(proxy, context), proxy, secure); } } @Override - public HttpHost determineTargetHost(final HttpRequest request, final HttpContext context) throws HttpException { + public final HttpHost determineTargetHost(final HttpRequest request, final HttpContext context) throws HttpException { final URIAuthority authority = request.getAuthority(); if (authority != null) { final String scheme = request.getScheme(); @@ -121,4 +120,15 @@ public class DefaultRoutePlanner implements HttpRoutePlanner { return null; } + /** + * This implementation returns null. + * + * @throws HttpException may be thrown if overridden + */ + protected InetAddress determineLocalAddress( + final HttpHost firstHop, + final HttpContext context) throws HttpException { + return null; + } + } diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java b/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java index 36a8558de..487b3859d 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/config/TestRequestConfig.java @@ -27,7 +27,6 @@ package org.apache.hc.client5.http.config; -import java.net.InetAddress; import java.util.Arrays; import java.util.concurrent.TimeUnit; @@ -57,7 +56,6 @@ public class TestRequestConfig { Assert.assertEquals(false, config.isCircularRedirectsAllowed()); Assert.assertEquals(50, config.getMaxRedirects()); Assert.assertEquals(null, config.getCookieSpec()); - Assert.assertEquals(null, config.getLocalAddress()); Assert.assertEquals(null, config.getProxy()); Assert.assertEquals(null, config.getTargetPreferredAuthSchemes()); Assert.assertEquals(null, config.getProxyPreferredAuthSchemes()); @@ -76,7 +74,6 @@ public class TestRequestConfig { .setCircularRedirectsAllowed(true) .setMaxRedirects(100) .setCookieSpec(CookieSpecs.STANDARD) - .setLocalAddress(InetAddress.getLocalHost()) .setProxy(new HttpHost("someproxy")) .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM)) .setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.DIGEST)) @@ -92,7 +89,6 @@ public class TestRequestConfig { Assert.assertEquals(true, config.isCircularRedirectsAllowed()); Assert.assertEquals(100, config.getMaxRedirects()); Assert.assertEquals(CookieSpecs.STANDARD, config.getCookieSpec()); - Assert.assertEquals(InetAddress.getLocalHost(), config.getLocalAddress()); Assert.assertEquals(new HttpHost("someproxy"), config.getProxy()); Assert.assertEquals(Arrays.asList(AuthSchemes.NTLM), config.getTargetPreferredAuthSchemes()); Assert.assertEquals(Arrays.asList(AuthSchemes.DIGEST), config.getProxyPreferredAuthSchemes());