1
0
mirror of https://github.com/square/okhttp.git synced 2026-01-22 15:42:00 +03:00

Don't do DNS lookups on null hosts.

This commit is contained in:
jwilson
2014-02-22 09:11:30 -05:00
parent dce4bb2c13
commit 8377182cfe
2 changed files with 12 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ import java.net.UnknownHostException;
public interface Dns {
Dns DEFAULT = new Dns() {
@Override public InetAddress[] getAllByName(String host) throws UnknownHostException {
if (host == null) throw new UnknownHostException("host == null");
return InetAddress.getAllByName(host);
}
};

View File

@@ -399,6 +399,17 @@ public final class URLConnectionTest {
testServerClosesOutput(SHUTDOWN_OUTPUT_AT_END);
}
@Test public void invalidHost() throws Exception {
// Note that 1234.1.1.1 is an invalid host in a URI, but URL isn't as strict.
URL url = new URL("http://1234.1.1.1/index.html");
HttpURLConnection connection = client.open(url);
try {
connection.connect();
fail();
} catch (UnknownHostException expected) {
}
}
private void testServerClosesOutput(SocketPolicy socketPolicy) throws Exception {
server.enqueue(new MockResponse().setBody("This connection won't pool properly")
.setSocketPolicy(socketPolicy));