use of okhttp3.Address in project okhttp by square.
the class AddressTest method differentProxySelectorsAreDifferent.
@Test
public void differentProxySelectorsAreDifferent() throws Exception {
Address a = new Address("square.com", 80, dns, socketFactory, null, null, null, authenticator, null, protocols, connectionSpecs, new RecordingProxySelector());
Address b = new Address("square.com", 80, dns, socketFactory, null, null, null, authenticator, null, protocols, connectionSpecs, new RecordingProxySelector());
assertFalse(a.equals(b));
}
use of okhttp3.Address in project okhttp by square.
the class ConnectionPoolTest method allocateAndLeakAllocation.
/** Use a helper method so there's no hidden reference remaining on the stack. */
private void allocateAndLeakAllocation(ConnectionPool pool, RealConnection connection) {
synchronized (pool) {
StreamAllocation leak = new StreamAllocation(pool, connection.route().address(), null);
leak.acquire(connection);
}
}
use of okhttp3.Address 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"));
}
use of okhttp3.Address in project okhttp by square.
the class RouteSelectorTest method singleRoute.
@Test
public void singleRoute() throws Exception {
Address address = httpAddress();
RouteSelector routeSelector = new RouteSelector(address, routeDatabase);
assertTrue(routeSelector.hasNext());
dns.set(uriHost, dns.allocate(1));
assertRoute(routeSelector.next(), address, NO_PROXY, dns.lookup(uriHost, 0), uriPort);
dns.assertRequests(uriHost);
assertFalse(routeSelector.hasNext());
try {
routeSelector.next();
fail();
} catch (NoSuchElementException expected) {
}
}
use of okhttp3.Address in project okhttp by square.
the class RouteSelectorTest method proxySelectorReturnsNull.
@Test
public void proxySelectorReturnsNull() throws Exception {
ProxySelector nullProxySelector = new ProxySelector() {
@Override
public List<Proxy> select(URI uri) {
assertEquals(uriHost, uri.getHost());
return null;
}
@Override
public void connectFailed(URI uri, SocketAddress socketAddress, IOException e) {
throw new AssertionError();
}
};
Address address = new Address(uriHost, uriPort, dns, socketFactory, null, null, null, authenticator, null, protocols, connectionSpecs, nullProxySelector);
RouteSelector routeSelector = new RouteSelector(address, routeDatabase);
assertTrue(routeSelector.hasNext());
dns.set(uriHost, dns.allocate(1));
assertRoute(routeSelector.next(), address, NO_PROXY, dns.lookup(uriHost, 0), uriPort);
dns.assertRequests(uriHost);
assertFalse(routeSelector.hasNext());
}
Aggregations