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

[7_5_X][TIMOB-26534] Android: Modified native HTTP handling to only cache "GET" responses #10448

Merged
merged 1 commit into from
Nov 8, 2018
Merged
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 @@ -19,6 +19,7 @@
import java.io.OutputStream;
import java.net.CacheRequest;
import java.net.CacheResponse;
import java.net.HttpURLConnection;
import java.net.ResponseCache;
import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -412,8 +413,15 @@ public TiResponseCache(File cachedir, TiApplication tiApp)
@Override
public CacheResponse get(URI uri, String rqstMethod, Map<String, List<String>> rqstHeaders) throws IOException
{
if (uri == null || cacheDir == null)
if (uri == null || cacheDir == null || rqstMethod == null) {
return null;
}

// We only support caching HTTP "GET" requests. (Apple and Google do not normally cache "HEAD".)
// Never cache methods which can make server-side changes such as "POST", "PUT", "DELETE", etc.
if (!rqstMethod.equals("GET")) {
return null;
}

// Workaround for https://jira.appcelerator.org/browse/TIMOB-18913
// This workaround should be removed when HTTPClient is refactored with HttpUrlConnection
Expand Down Expand Up @@ -509,8 +517,18 @@ private Map<String, List<String>> makeLowerCaseHeaders(Map<String, List<String>>
@Override
public CacheRequest put(URI uri, URLConnection conn) throws IOException
{
if (cacheDir == null)
if (cacheDir == null) {
return null;
}

// We only support caching HTTP "GET" requests. (Apple and Google do not normally cache "HEAD".)
// Never cache methods which can make server-side changes such as "POST", "PUT", "DELETE", etc.
if (conn instanceof HttpURLConnection) {
String requestMethod = ((HttpURLConnection) conn).getRequestMethod();
if ((requestMethod == null) || !requestMethod.equals("GET")) {
return null;
}
}

// Workaround for https://jira.appcelerator.org/browse/TIMOB-18913
// This workaround should be removed when HTTPClient is refactored with HttpUrlConnection
Expand Down