diff --git a/okhttp-urlconnection/src/main/java/com/squareup/okhttp/OkUrlFactory.java b/okhttp-urlconnection/src/main/java/com/squareup/okhttp/OkUrlFactory.java index 4b34559e4c74..8052e2a2006c 100644 --- a/okhttp-urlconnection/src/main/java/com/squareup/okhttp/OkUrlFactory.java +++ b/okhttp-urlconnection/src/main/java/com/squareup/okhttp/OkUrlFactory.java @@ -53,9 +53,13 @@ HttpURLConnection open(URL url, Proxy proxy) { OkHttpClient copy = client.copyWithDefaults(); copy.setProxy(proxy); - if (protocol.equals("http")) return new HttpURLConnectionImpl(url, copy); - if (protocol.equals("https")) return new HttpsURLConnectionImpl(url, copy); - throw new IllegalArgumentException("Unexpected protocol: " + protocol); + HttpURLConnection conn; + if (protocol.equals("http")) conn = new HttpURLConnectionImpl(url, copy); + else if (protocol.equals("https")) conn = new HttpsURLConnectionImpl(url, copy); + else throw new IllegalArgumentException("Unexpected protocol: " + protocol); + + if (copy.getCache() != null) conn.setUseCaches(true); + return conn; } /** diff --git a/okhttp/src/main/java/com/squareup/okhttp/OkHttpClient.java b/okhttp/src/main/java/com/squareup/okhttp/OkHttpClient.java index 06c9fbd44303..20a97cdd4481 100644 --- a/okhttp/src/main/java/com/squareup/okhttp/OkHttpClient.java +++ b/okhttp/src/main/java/com/squareup/okhttp/OkHttpClient.java @@ -342,7 +342,7 @@ InternalCache internalCache() { public OkHttpClient setCache(Cache cache) { this.cache = cache; - this.internalCache = null; + this.internalCache = cache.internalCache; return this; }