From e7c14c45c80070fee70451deb8a0a53de66e5a43 Mon Sep 17 00:00:00 2001 From: Jesse Wilson Date: Mon, 6 Dec 2010 15:12:37 -0800 Subject: Use proxies specified by system properties in DefaultHttpClient. Change-Id: Ic05f450a301d5478ff3a8f03af56ac0c0dbe3620 http://b/3254717 --- src/org/apache/http/impl/client/DefaultHttpClient.java | 8 +++++--- .../apache/http/impl/conn/ProxySelectorRoutePlanner.java | 14 +++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/org/apache/http/impl/client/DefaultHttpClient.java b/src/org/apache/http/impl/client/DefaultHttpClient.java index 7dcb2a2..7b3a3fa 100644 --- a/src/org/apache/http/impl/client/DefaultHttpClient.java +++ b/src/org/apache/http/impl/client/DefaultHttpClient.java @@ -61,7 +61,7 @@ import org.apache.http.cookie.CookieSpecRegistry; import org.apache.http.impl.DefaultConnectionReuseStrategy; import org.apache.http.impl.auth.BasicSchemeFactory; import org.apache.http.impl.auth.DigestSchemeFactory; -import org.apache.http.impl.conn.DefaultHttpRoutePlanner; +import org.apache.http.impl.conn.ProxySelectorRoutePlanner; import org.apache.http.impl.conn.SingleClientConnManager; import org.apache.http.impl.cookie.BestMatchSpecFactory; import org.apache.http.impl.cookie.BrowserCompatSpecFactory; @@ -326,8 +326,10 @@ public class DefaultHttpClient extends AbstractHttpClient { @Override protected HttpRoutePlanner createHttpRoutePlanner() { - return new DefaultHttpRoutePlanner - (getConnectionManager().getSchemeRegistry()); + // BEGIN android-changed + // Use the proxy specified by system properties + return new ProxySelectorRoutePlanner(getConnectionManager().getSchemeRegistry(), null); + // END android-changed } diff --git a/src/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java b/src/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java index 136caf4..daa7227 100644 --- a/src/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java +++ b/src/org/apache/http/impl/conn/ProxySelectorRoutePlanner.java @@ -51,6 +51,7 @@ import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.scheme.SchemeRegistry; import org.apache.http.conn.params.ConnRouteParams; +import org.apache.http.conn.params.ConnRoutePNames; /** @@ -140,7 +141,18 @@ public class ProxySelectorRoutePlanner implements HttpRoutePlanner { final InetAddress local = ConnRouteParams.getLocalAddress(request.getParams()); - final HttpHost proxy = determineProxy(target, request, context); + + // BEGIN android-changed + // If the client or request explicitly specifies a proxy (or no + // proxy), prefer that over the ProxySelector's VM-wide default. + HttpHost proxy = (HttpHost) request.getParams().getParameter(ConnRoutePNames.DEFAULT_PROXY); + if (proxy == null) { + proxy = determineProxy(target, request, context); + } else if (ConnRouteParams.NO_HOST.equals(proxy)) { + // value is explicitly unset + proxy = null; + } + // END android-changed final Scheme schm = this.schemeRegistry.getScheme(target.getSchemeName()); -- cgit v1.1