Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1825)

Unified Diff: components/cronet/android/java/src/org/chromium/net/urlconnection/CronetHttpURLConnection.java

Issue 1404423006: [Cronet] Do not follow Http <-> Https redirects (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | components/cronet/android/test/assets/test/redirect_invalid_scheme.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/cronet/android/java/src/org/chromium/net/urlconnection/CronetHttpURLConnection.java
diff --git a/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetHttpURLConnection.java b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetHttpURLConnection.java
index a9222b5bd720c79ec4b449cfce2bb0c334fe487a..d08d27a4a148c9132447c0efceb3005f77de8945 100644
--- a/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetHttpURLConnection.java
+++ b/components/cronet/android/java/src/org/chromium/net/urlconnection/CronetHttpURLConnection.java
@@ -439,18 +439,24 @@ public class CronetHttpURLConnection extends HttpURLConnection {
public void onReceivedRedirect(
UrlRequest request, UrlResponseInfo info, String newLocationUrl) {
mOnRedirectCalled = true;
- if (instanceFollowRedirects) {
- try {
- url = new URL(newLocationUrl);
- } catch (MalformedURLException e) {
- // Ignored.
+ try {
+ URL newUrl = new URL(newLocationUrl);
+ boolean sameProtocol = newUrl.getProtocol().equals(url.getProtocol());
+ if (instanceFollowRedirects) {
+ // Update the url variable even if the redirect will not be
+ // followed due to different protocols.
+ url = newUrl;
}
- mRequest.followRedirect();
- } else {
- mResponseInfo = info;
- mRequest.cancel();
- setResponseDataCompleted();
+ if (instanceFollowRedirects && sameProtocol) {
+ mRequest.followRedirect();
+ return;
+ }
+ } catch (MalformedURLException e) {
+ // Ignored. Just cancel the request and not follow the redirect.
}
+ mResponseInfo = info;
+ mRequest.cancel();
+ setResponseDataCompleted();
}
@Override
« no previous file with comments | « no previous file | components/cronet/android/test/assets/test/redirect_invalid_scheme.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698