From 393ca21e0004bac55f405b36a4d0006db7f52018 Mon Sep 17 00:00:00 2001 From: yegorius Date: Mon, 8 Jun 2015 17:56:08 +0300 Subject: [PATCH] fix bug --- .../main/java/com/squareup/okhttp/OkUrlFactory.java | 10 +++++++--- .../main/java/com/squareup/okhttp/OkHttpClient.java | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) 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; }