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

Unified Diff: net/url_request/url_request_redirect_job.cc

Issue 348253002: Add CORS headers to URLRequestRedirectJob. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: EXPECT GURL -> std::string Created 6 years, 3 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 | « net/url_request/url_request_redirect_job.h ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/url_request/url_request_redirect_job.cc
diff --git a/net/url_request/url_request_redirect_job.cc b/net/url_request/url_request_redirect_job.cc
index 15ebdcdf1c098afbc165eba8a0cc9088f263e030..dbcdb5a8b84db63c1ff7060b64d03f820f6649fd 100644
--- a/net/url_request/url_request_redirect_job.cc
+++ b/net/url_request/url_request_redirect_job.cc
@@ -89,6 +89,23 @@ void URLRequestRedirectJob::StartAsync() {
response_code_,
redirect_destination_.spec().c_str(),
redirect_reason_.c_str());
+
+ std::string http_origin;
+ const net::HttpRequestHeaders& request_headers =
+ request_->extra_request_headers();
+ if (request_headers.GetHeader("Origin", &http_origin)) {
+ // If this redirect is used in a cross-origin request, add CORS headers to
+ // make sure that the redirect gets through. Note that the destination URL
+ // is still subject to the usual CORS policy, i.e. the resource will only
+ // be available to web pages if the server serves the response with the
+ // required CORS response headers.
+ header_string += base::StringPrintf(
+ "\n"
+ "Access-Control-Allow-Origin: %s\n"
+ "Access-Control-Allow-Credentials: true",
+ http_origin.c_str());
+ }
+
fake_headers_ = new HttpResponseHeaders(
HttpUtil::AssembleRawHeaders(header_string.c_str(),
header_string.length()));
« no previous file with comments | « net/url_request/url_request_redirect_job.h ('k') | net/url_request/url_request_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698