diff options
| author | Neil Fuller <nfuller@google.com> | 2014-12-02 10:45:07 +0000 |
|---|---|---|
| committer | Neil Fuller <nfuller@google.com> | 2014-12-04 17:50:17 +0000 |
| commit | 797fdc6cc6bf16372e9464f189b535148f944ce9 (patch) | |
| tree | 9bdfaff8374e231be866357f2d2bad94607db31b /okhttp | |
| parent | 442180cdae6a99817e98724901cb5f5263025e64 (diff) | |
| download | android_external_okhttp-797fdc6cc6bf16372e9464f189b535148f944ce9.tar.gz android_external_okhttp-797fdc6cc6bf16372e9464f189b535148f944ce9.tar.bz2 android_external_okhttp-797fdc6cc6bf16372e9464f189b535148f944ce9.zip | |
Avoid a reverse DNS-lookup for a numeric proxy address
When the proxy is specified as an IP address the RouteSelector
would force a reverse-lookup. This can introduce extra latency
when the DNS is slow or missing. It also then turns the name
back into a set of IPs, which may result in the original IP
address not being given priority.
This is upstream commit:
https://github.com/square/okhttp/commit/9acd5e7b54fb55f62a5dd16865c30787dfba4c8b
Bug: 18327075
Change-Id: Idafd72f4d5b901e267081f924377db4ada9afe1b
Diffstat (limited to 'okhttp')
| -rw-r--r-- | okhttp/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/okhttp/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java b/okhttp/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java index a5ffa77..876bac4 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java +++ b/okhttp/src/main/java/com/squareup/okhttp/internal/http/RouteSelector.java @@ -197,7 +197,7 @@ public final class RouteSelector { "Proxy.address() is not an " + "InetSocketAddress: " + proxyAddress.getClass()); } InetSocketAddress proxySocketAddress = (InetSocketAddress) proxyAddress; - socketHost = proxySocketAddress.getHostName(); + socketHost = getHostString(proxySocketAddress); socketPort = proxySocketAddress.getPort(); } @@ -206,6 +206,24 @@ public final class RouteSelector { nextSocketAddressIndex = 0; } + /** + * Obtain a "host" from an {@link InetSocketAddress}. This returns a string containing either an + * actual host name or a numeric IP address. + */ + // Visible for testing + static String getHostString(InetSocketAddress socketAddress) { + InetAddress address = socketAddress.getAddress(); + if (address == null) { + // The InetSocketAddress was specified with a string (either a numeric IP or a host name). If + // it is a name, all IPs for that name should be tried. If it is an IP address, only that IP + // address should be tried. + return socketAddress.getHostName(); + } + // The InetSocketAddress has a specific address: we should only try that address. Therefore we + // return the address and ignore any host name that may be available. + return address.getHostAddress(); + } + /** Returns true if there's another socket address to try. */ private boolean hasNextInetSocketAddress() { return socketAddresses != null; |
