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:
@@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user