use of okhttp3.Connection in project okhttp by square.
the class ConnectionReuseTest method connectionsAreNotReusedIfSslSocketFactoryChanges.
@Test
public void connectionsAreNotReusedIfSslSocketFactoryChanges() throws Exception {
enableHttps();
server.enqueue(new MockResponse());
server.enqueue(new MockResponse());
Request request = new Request.Builder().url(server.url("/")).build();
Response response = client.newCall(request).execute();
response.body().close();
// This client shares a connection pool but has a different SSL socket factory.
SslClient sslClient2 = new SslClient.Builder().build();
OkHttpClient anotherClient = client.newBuilder().sslSocketFactory(sslClient2.socketFactory, sslClient2.trustManager).build();
// This client fails to connect because the new SSL socket factory refuses.
try {
anotherClient.newCall(request).execute();
fail();
} catch (SSLException expected) {
}
}
use of okhttp3.Connection in project okhttp by square.
the class ConnectionReuseTest method connectionsAreNotReusedIfHostnameVerifierChanges.
@Test
public void connectionsAreNotReusedIfHostnameVerifierChanges() throws Exception {
enableHttps();
server.enqueue(new MockResponse());
server.enqueue(new MockResponse());
Request request = new Request.Builder().url(server.url("/")).build();
Response response1 = client.newCall(request).execute();
response1.body().close();
// This client shares a connection pool but has a different SSL socket factory.
OkHttpClient anotherClient = client.newBuilder().hostnameVerifier(new RecordingHostnameVerifier()).build();
Response response2 = anotherClient.newCall(request).execute();
response2.body().close();
assertEquals(0, server.takeRequest().getSequenceNumber());
assertEquals(0, server.takeRequest().getSequenceNumber());
}
use of okhttp3.Connection in project okhttp by square.
the class ConnectionReuseTest method connectionsAreNotReusedWithResponseConnectionClose.
@Test
public void connectionsAreNotReusedWithResponseConnectionClose() throws Exception {
server.enqueue(new MockResponse().addHeader("Connection", "close").setBody("a"));
server.enqueue(new MockResponse().setBody("b"));
Request requestA = new Request.Builder().url(server.url("/")).build();
Request requestB = new Request.Builder().url(server.url("/")).build();
assertConnectionNotReused(requestA, requestB);
}
use of okhttp3.Connection in project okhttp by square.
the class HeadersTest method readNameValueBlockDropsForbiddenHeadersHttp2.
@Test
public void readNameValueBlockDropsForbiddenHeadersHttp2() throws IOException {
List<Header> headerBlock = headerEntries(":status", "200 OK", ":version", "HTTP/1.1", "connection", "close");
Request request = new Request.Builder().url("http://square.com/").build();
Response response = Http2Codec.readHttp2HeadersList(headerBlock).request(request).build();
Headers headers = response.headers();
assertEquals(1, headers.size());
assertEquals(":version", headers.name(0));
assertEquals("HTTP/1.1", headers.value(0));
}
use of okhttp3.Connection in project okhttp by square.
the class HeadersTest method headersNotEquals.
@Test
public void headersNotEquals() {
Headers headers1 = new Headers.Builder().add("Connection", "close").add("Transfer-Encoding", "chunked").build();
Headers headers2 = new Headers.Builder().add("Connection", "keep-alive").add("Transfer-Encoding", "chunked").build();
assertFalse(headers1.equals(headers2));
assertFalse(headers1.hashCode() == headers2.hashCode());
}
Aggregations