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

Don't explode if DNS fails or if the address is malformed.

We had a bug where we were trying to report a proxy problem
before the connection was even created.
This commit is contained in:
Jesse Wilson
2012-11-12 12:32:47 -08:00
parent 6af7cd22b3
commit 084fa33870
2 changed files with 23 additions and 3 deletions

View File

@@ -338,7 +338,11 @@ public class HttpURLConnectionImpl extends OkHttpConnection {
return true;
} catch (IOException e) {
RouteSelector routeSelector = httpEngine.routeSelector;
routeSelector.connectFailed(httpEngine.connection, e);
if (routeSelector == null) {
throw e; // Without a route selector, we can't retry.
} else if (httpEngine.connection != null) {
routeSelector.connectFailed(httpEngine.connection, e);
}
// The connection failure isn't fatal if there's another route to attempt.
OutputStream requestBody = httpEngine.getRequestBody();

View File

@@ -133,8 +133,6 @@ public final class URLConnectionTest extends TestCase {
// TODO: test that request bodies are retransmitted on IP address failures
// TODO: pooled proxy failures are not reported to the proxy selector
// TODO: a URI with no host should fail in Address creation.
// TODO: make HttpURLConnection.connect() include a loop around execute
public void testRequestHeaders() throws IOException, InterruptedException {
server.enqueue(new MockResponse());
@@ -1936,6 +1934,24 @@ public final class URLConnectionTest extends TestCase {
}
}
public void testDnsFailureThrowsIOException() throws IOException {
OkHttpConnection connection = openConnection(new URL("http://host.unlikelytld"));
try {
connection.connect();
fail();
} catch (IOException expected) {
}
}
public void testMalformedUrlThrowsUnknownHostException() throws IOException {
OkHttpConnection connection = openConnection(new URL("http:///foo.html"));
try {
connection.connect();
fail();
} catch (UnknownHostException expected) {
}
}
public void SUPPRESSED_testGetKeepAlive() throws Exception {
MockWebServer server = new MockWebServer();
server.enqueue(new MockResponse().setBody("ABC"));