Skip to content

Commit

Permalink
Cherry pick PR #1071: Add disable_cors support to net_fetcher (#1080)
Browse files Browse the repository at this point in the history
Co-authored-by: Sherry Zhou <[email protected]>
  • Loading branch information
cobalt-github-releaser-bot and sherryzy authored Jul 31, 2023
1 parent 999e455 commit 0f1aa3b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cobalt/loader/net_fetcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ NetFetcher::NetFetcher(const GURL& url, bool main_resource,
security_callback_(security_callback),
ALLOW_THIS_IN_INITIALIZER_LIST(start_callback_(
base::Bind(&NetFetcher::Start, base::Unretained(this)))),
cors_policy_(network_module->network_delegate()->cors_policy()),
request_cross_origin_(false),
origin_(origin),
request_script_(options.resource_type == disk_cache::kUncompiledScript),
Expand Down Expand Up @@ -225,7 +226,8 @@ void NetFetcher::OnURLFetchResponseStarted(const net::URLFetcher* source) {
if (request_cross_origin_ &&
(!source->GetResponseHeaders() ||
!CORSPreflight::CORSCheck(*source->GetResponseHeaders(),
origin_.SerializedOrigin(), false))) {
origin_.SerializedOrigin(), false,
cors_policy_))) {
std::string msg(base::StringPrintf(
"Cross origin request to %s was rejected by Same-Origin-Policy",
source->GetURL().spec().c_str()));
Expand Down
1 change: 1 addition & 0 deletions cobalt/loader/net_fetcher.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class NetFetcher : public Fetcher,
// after being constructed, but before Start() runs.
base::CancelableClosure start_callback_;

network::CORSPolicy cors_policy_;
// True if request mode is CORS and request URL's origin is different from
// request's origin.
bool request_cross_origin_;
Expand Down

0 comments on commit 0f1aa3b

Please sign in to comment.