use of okhttp3.Dns in project okhttp by square.
the class HttpOverHttp2Test method setUp.
@Before
public void setUp() throws Exception {
server.useHttps(sslClient.socketFactory, false);
cache = new Cache(tempDir.getRoot(), Integer.MAX_VALUE);
client = defaultClient().newBuilder().protocols(Arrays.asList(Protocol.HTTP_2, Protocol.HTTP_1_1)).dns(new SingleInetAddressDns()).sslSocketFactory(sslClient.socketFactory, sslClient.trustManager).hostnameVerifier(hostnameVerifier).build();
}
use of okhttp3.Dns in project okhttp by square.
the class URLConnectionTest method streamedBodyIsNotRetried.
@Test
public void streamedBodyIsNotRetried() throws Exception {
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.DISCONNECT_AFTER_REQUEST));
urlFactory = new OkUrlFactory(defaultClient().newBuilder().dns(new DoubleInetAddressDns()).build());
HttpURLConnection connection = urlFactory.open(server.url("/").url());
connection.setDoOutput(true);
connection.setChunkedStreamingMode(100);
OutputStream os = connection.getOutputStream();
os.write("OutputStream is no fun.".getBytes("UTF-8"));
os.close();
try {
connection.getResponseCode();
fail();
} catch (IOException expected) {
}
assertEquals(1, server.getRequestCount());
}
use of okhttp3.Dns in project okhttp by square.
the class URLConnectionTest method sameConnectionRedirectAndReuse.
/**
* Retry redirects if the socket is closed.
* https://code.google.com/p/android/issues/detail?id=41576
*/
@Test
public void sameConnectionRedirectAndReuse() throws Exception {
urlFactory.setClient(urlFactory.client().newBuilder().dns(new SingleInetAddressDns()).build());
server.enqueue(new MockResponse().setResponseCode(HttpURLConnection.HTTP_MOVED_TEMP).setSocketPolicy(SHUTDOWN_INPUT_AT_END).addHeader("Location: /foo"));
server.enqueue(new MockResponse().setBody("This is the new page!"));
assertContent("This is the new page!", urlFactory.open(server.url("/").url()));
assertEquals(0, server.takeRequest().getSequenceNumber());
assertEquals(0, server.takeRequest().getSequenceNumber());
}
use of okhttp3.Dns in project okhttp by square.
the class CallTest method networkDropsOnConditionalGet.
@Test
public void networkDropsOnConditionalGet() throws IOException {
client = client.newBuilder().cache(cache).build();
// Seed the cache.
server.enqueue(new MockResponse().addHeader("ETag: v1").setBody("A"));
executeSynchronously("/").assertCode(200).assertBody("A");
// Attempt conditional cache validation and a DNS miss.
client.connectionPool().evictAll();
client = client.newBuilder().dns(new FakeDns()).build();
executeSynchronously("/").assertFailure(UnknownHostException.class);
}
use of okhttp3.Dns in project okhttp by square.
the class CallTest method noRecoveryFromTlsHandshakeFailureWhenTlsFallbackIsDisabled.
@Test
public void noRecoveryFromTlsHandshakeFailureWhenTlsFallbackIsDisabled() throws Exception {
client = client.newBuilder().connectionSpecs(Arrays.asList(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT)).hostnameVerifier(new RecordingHostnameVerifier()).dns(new SingleInetAddressDns()).sslSocketFactory(suppressTlsFallbackClientSocketFactory(), sslClient.trustManager).build();
server.useHttps(sslClient.socketFactory, false);
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.FAIL_HANDSHAKE));
Request request = new Request.Builder().url(server.url("/")).build();
try {
client.newCall(request).execute();
fail();
} catch (SSLProtocolException expected) {
// RI response to the FAIL_HANDSHAKE
} catch (SSLHandshakeException expected) {
// Android's response to the FAIL_HANDSHAKE
}
}
Aggregations