Index: net/url_request/url_request_http_job.cc |
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc |
index b3053b24325a37a5a659adab66e0f56c65c0cc92..c8c492f542c4b3e765f6b05304be35d906d3b44c 100644 |
--- a/net/url_request/url_request_http_job.cc |
+++ b/net/url_request/url_request_http_job.cc |
@@ -1131,6 +1131,41 @@ std::unique_ptr<SourceStream> URLRequestHttpJob::SetUpSourceStream() { |
return upstream; |
} |
+RedirectInfo URLRequestHttpJob::ComputeRedirectInfo(const GURL& location, |
+ int http_status_code) { |
+ // If |request|'s insecure request policy matches its URL, then upgrade it |
+ // from a non-secure protocol to a secure protocol (e.g. "http" => "https"). |
+ // See https://www.w3.org/TR/upgrade-insecure-requests/ for details. |
+ // |
+ // TODO(mkwst): HSTS is currently modeled as a redirect, which makes sense, |
+ // given the web-exposed behavior developers currently rely upon. At some |
+ // point, however, https://wicg.github.io/hsts-priming/ will change that |
+ // expectation. Once those changes are in place, it might make sense to |
+ // merge the HSTS logic from 'MaybeInternallyRedirect' into this function. |
+ if (request_->insecure_request_policy() == |
+ net::URLRequest::DO_NOT_UPGRADE_INSECURE_REQUESTS || |
+ location.SchemeIsCryptographic() || |
+ (request_->initiator() && |
+ request_->insecure_request_policy() == |
+ net::URLRequest::UPGRADE_SAME_HOST_INSECURE_REQUESTS && |
+ request_->initiator()->host() != location.host())) { |
+ return URLRequestJob::ComputeRedirectInfo(location, http_status_code); |
+ } |
+ |
+ request_->net_log().AddEvent( |
+ NetLogEventType::URL_REQUEST_REWRITTEN, |
+ NetLog::StringCallback("reason", "Upgrade-Insecure-Requests")); |
+ |
+ DCHECK(location.SchemeIs(url::kHttpScheme) || |
+ location.SchemeIs(url::kWsScheme)); |
+ GURL::Replacements replacements; |
+ replacements.SetSchemeStr(location.SchemeIs(url::kHttpScheme) |
+ ? url::kHttpsScheme |
+ : url::kWssScheme); |
+ return URLRequestJob::ComputeRedirectInfo( |
+ location.ReplaceComponents(replacements), http_status_code); |
+} |
+ |
bool URLRequestHttpJob::CopyFragmentOnRedirect(const GURL& location) const { |
// Allow modification of reference fragments by default, unless |
// |allowed_unsafe_redirect_url_| is set and equal to the redirect URL. |