use of okhttp3.Dns in project okhttp by square.
the class CallTest method recoverWhenRetryOnConnectionFailureIsTrue.
@Test
public void recoverWhenRetryOnConnectionFailureIsTrue() throws Exception {
server.enqueue(new MockResponse().setBody("seed connection pool"));
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AFTER_REQUEST));
server.enqueue(new MockResponse().setBody("retry success"));
client = client.newBuilder().dns(new DoubleInetAddressDns()).build();
assertTrue(client.retryOnConnectionFailure());
executeSynchronously("/").assertBody("seed connection pool");
executeSynchronously("/").assertBody("retry success");
}
use of okhttp3.Dns in project okhttp by square.
the class CallTest method invalidHost.
// This may fail in DNS lookup, which we don't have timeouts for.
@Ignore
@Test
public void invalidHost() throws Exception {
Request request = new Request.Builder().url(HttpUrl.parse("http://1234.1.1.1/")).build();
executeSynchronously(request).assertFailure(UnknownHostException.class);
}
use of okhttp3.Dns in project okhttp by square.
the class CallTest method customDns.
@Test
public void customDns() throws Exception {
// Configure a DNS that returns our local MockWebServer for android.com.
FakeDns dns = new FakeDns();
dns.set("android.com", Dns.SYSTEM.lookup(server.url("/").host()));
client = client.newBuilder().dns(dns).build();
server.enqueue(new MockResponse());
Request request = new Request.Builder().url(server.url("/").newBuilder().host("android.com").build()).build();
executeSynchronously(request).assertCode(200);
dns.assertRequests("android.com");
}
use of okhttp3.Dns in project okhttp by square.
the class URLConnectionTest method unexpectedExceptionAsync.
/** Confirm that runtime exceptions thrown inside of OkHttp propagate to the caller. */
@Test
public void unexpectedExceptionAsync() throws Exception {
urlFactory.setClient(urlFactory.client().newBuilder().dns(new Dns() {
@Override
public List<InetAddress> lookup(String hostname) {
throw new RuntimeException("boom!");
}
}).build());
server.enqueue(new MockResponse());
HttpURLConnection connection = urlFactory.open(server.url("/").url());
try {
// Force the async implementation.
connection.connect();
fail();
} catch (RuntimeException expected) {
assertEquals("boom!", expected.getMessage());
}
}
use of okhttp3.Dns in project okhttp by square.
the class URLConnectionTest method connectViaHttpProxyToHttpsUsingBadProxyAndHttpResponseCache.
/** Tolerate bad https proxy response when using HttpResponseCache. Android bug 6754912. */
@Test
public void connectViaHttpProxyToHttpsUsingBadProxyAndHttpResponseCache() throws Exception {
initResponseCache();
server.useHttps(sslClient.socketFactory, true);
// The inclusion of a body in the response to a CONNECT is key to reproducing b/6754912.
MockResponse badProxyResponse = new MockResponse().setSocketPolicy(UPGRADE_TO_SSL_AT_END).setBody("bogus proxy connect response content");
server.enqueue(badProxyResponse);
server.enqueue(new MockResponse().setBody("response"));
// Configure a single IP address for the host and a single configuration, so we only need one
// failure to fail permanently.
urlFactory.setClient(urlFactory.client().newBuilder().dns(new SingleInetAddressDns()).sslSocketFactory(sslClient.socketFactory, sslClient.trustManager).connectionSpecs(Util.immutableList(ConnectionSpec.MODERN_TLS)).hostnameVerifier(new RecordingHostnameVerifier()).proxy(server.toProxyAddress()).build());
URL url = new URL("https://android.com/foo");
connection = urlFactory.open(url);
assertContent("response", connection);
RecordedRequest connect = server.takeRequest();
assertEquals("CONNECT android.com:443 HTTP/1.1", connect.getRequestLine());
assertEquals("android.com:443", connect.getHeader("Host"));
}
Aggregations