use of okhttp3.internal.huc.OkHttpURLConnection in project okhttp by square.
the class ResponseCacheTest method otherStacks_cacheHitWithoutVary.
// Other stacks (e.g. older versions of OkHttp bundled inside Android apps) can interact with the
// default ResponseCache. We try to keep this case working as much as possible because apps break
// if we don't.
@Test
public void otherStacks_cacheHitWithoutVary() throws Exception {
server.enqueue(new MockResponse().addHeader("Cache-Control: max-age=60").setBody("A"));
server.enqueue(new MockResponse().setBody("FAIL"));
// Set the cache as the shared cache.
ResponseCache.setDefault(cache);
// Use the platform's HTTP stack.
URLConnection connection = server.url("/").url().openConnection();
assertFalse(connection instanceof OkHttpURLConnection);
assertEquals("A", readAscii(connection));
URLConnection connection2 = server.url("/").url().openConnection();
assertFalse(connection2 instanceof OkHttpURLConnection);
assertEquals("A", readAscii(connection2));
}
use of okhttp3.internal.huc.OkHttpURLConnection in project NoHttp by yanzhenjie.
the class URLConnectionFactory method open.
/**
* Open url.
*
* @param url {@link URL}.
* @param proxy {@link Proxy}.
* @return {@link HttpURLConnection}.
*/
public HttpURLConnection open(URL url, Proxy proxy) {
OkHttpClient copy = mClient.newBuilder().proxy(proxy).build();
String protocol = url.getProtocol();
if (protocol.equals("http"))
return new OkHttpURLConnection(url, copy);
if (protocol.equals("https"))
return new OkHttpsURLConnection(url, copy);
throw new IllegalArgumentException("Unexpected protocol: " + protocol);
}
Aggregations