Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cache finally #1689

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion okhttp/src/main/java/com/squareup/okhttp/OkHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ InternalCache internalCache() {

public OkHttpClient setCache(Cache cache) {
this.cache = cache;
this.internalCache = null;
this.internalCache = cache.internalCache;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is really nasty 😄

return this;
}

Expand Down