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

Unified Diff: Source/core/fetch/CrossOriginAccessControl.cpp

Issue 332633006: Include error status code in console message for non-CORS response. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update test expectation Created 6 years, 6 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 | « LayoutTests/http/tests/xmlhttprequest/workers/access-control-basic-get-fail-non-simple-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/fetch/CrossOriginAccessControl.cpp
diff --git a/Source/core/fetch/CrossOriginAccessControl.cpp b/Source/core/fetch/CrossOriginAccessControl.cpp
index ddcb29c406424386cc69bfafc051b9d6f413c30a..76040fb3b778d27f4c9b3166a92af542822f4c2a 100644
--- a/Source/core/fetch/CrossOriginAccessControl.cpp
+++ b/Source/core/fetch/CrossOriginAccessControl.cpp
@@ -142,6 +142,14 @@ static bool isOriginSeparator(UChar ch)
return isASCIISpace(ch) || ch == ',';
}
+static bool isInterestingStatusCode(int statusCode)
+{
+ // Predicate that gates what status codes should be included in
+ // console error messages for responses containing no access
+ // control headers.
+ return statusCode >= 400;
+}
+
bool passesAccessControlCheck(const ResourceResponse& response, StoredCredentials includeCredentials, SecurityOrigin* securityOrigin, String& errorDescription)
{
AtomicallyInitializedStatic(AtomicString&, accessControlAllowOrigin = *new AtomicString("access-control-allow-origin", AtomicString::ConstructFromLiteral));
@@ -165,6 +173,9 @@ bool passesAccessControlCheck(const ResourceResponse& response, StoredCredential
} else if (accessControlOriginString != securityOrigin->toAtomicString()) {
if (accessControlOriginString.isEmpty()) {
errorDescription = "No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '" + securityOrigin->toString() + "' is therefore not allowed access.";
+
+ if (isInterestingStatusCode(response.httpStatusCode()))
+ errorDescription.append(" The response had HTTP status code " + String::number(response.httpStatusCode()) + ".");
} else if (accessControlOriginString.string().find(isOriginSeparator, 0) != kNotFound) {
errorDescription = "The 'Access-Control-Allow-Origin' header contains multiple values '" + accessControlOriginString + "', but only one is allowed. Origin '" + securityOrigin->toString() + "' is therefore not allowed access.";
} else {
« no previous file with comments | « LayoutTests/http/tests/xmlhttprequest/workers/access-control-basic-get-fail-non-simple-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698