Search in sources :

Example 6 with SingleInetAddressDns

use of okhttp3.internal.SingleInetAddressDns 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"));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) SingleInetAddressDns(okhttp3.internal.SingleInetAddressDns) URL(java.net.URL) Test(org.junit.Test)

Aggregations

SingleInetAddressDns (okhttp3.internal.SingleInetAddressDns)6 MockResponse (okhttp3.mockwebserver.MockResponse)5 Test (org.junit.Test)5 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)3 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)2 URL (java.net.URL)1 SSLProtocolException (javax.net.ssl.SSLProtocolException)1 SSLSocket (javax.net.ssl.SSLSocket)1 Cache (okhttp3.Cache)1 Before (org.junit.Before)1