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

Side by Side Diff: Source/core/fetch/CrossOriginAccessControl.cpp

Issue 1300083002: Add suggestion to use "no-cors" with Fetch fails CORS check. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Patch CORS error expectation files to include message about Fetch CORS. Created 5 years, 4 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 unified diff | Download patch
« no previous file with comments | « LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-unsafe-redirect-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 errorDescription = buildAccessControlFailureMessage("A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true.", securityOrigin); 151 errorDescription = buildAccessControlFailureMessage("A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true.", securityOrigin);
152 return false; 152 return false;
153 } 153 }
154 } else if (allowOriginHeaderValue != securityOrigin->toAtomicString()) { 154 } else if (allowOriginHeaderValue != securityOrigin->toAtomicString()) {
155 if (allowOriginHeaderValue.isNull()) { 155 if (allowOriginHeaderValue.isNull()) {
156 errorDescription = buildAccessControlFailureMessage("No 'Access-Cont rol-Allow-Origin' header is present on the requested resource.", securityOrigin) ; 156 errorDescription = buildAccessControlFailureMessage("No 'Access-Cont rol-Allow-Origin' header is present on the requested resource.", securityOrigin) ;
157 157
158 if (isInterestingStatusCode(statusCode)) 158 if (isInterestingStatusCode(statusCode))
159 errorDescription.append(" The response had HTTP status code " + String::number(statusCode) + "."); 159 errorDescription.append(" The response had HTTP status code " + String::number(statusCode) + ".");
160 160
161 errorDescription.append(" Alternatively, if you want an opaque respo nse, switch to The Fetch API in 'no-cors' mode.");
hiroshige 2015/08/28 08:24:23 nit: s/The Fetch API/the Fetch API/
162
161 return false; 163 return false;
162 } 164 }
163 165
164 String detail; 166 String detail;
165 if (allowOriginHeaderValue.string().find(isOriginSeparator, 0) != kNotFo und) { 167 if (allowOriginHeaderValue.string().find(isOriginSeparator, 0) != kNotFo und) {
166 detail = "The 'Access-Control-Allow-Origin' header contains multiple values '" + allowOriginHeaderValue + "', but only one is allowed."; 168 detail = "The 'Access-Control-Allow-Origin' header contains multiple values '" + allowOriginHeaderValue + "', but only one is allowed.";
167 } else { 169 } else {
168 KURL headerOrigin(KURL(), allowOriginHeaderValue); 170 KURL headerOrigin(KURL(), allowOriginHeaderValue);
169 if (!headerOrigin.isValid()) 171 if (!headerOrigin.isValid())
170 detail = "The 'Access-Control-Allow-Origin' header contains the invalid value '" + allowOriginHeaderValue + "'."; 172 detail = "The 'Access-Control-Allow-Origin' header contains the invalid value '" + allowOriginHeaderValue + "'.";
171 else 173 else
172 detail = "The 'Access-Control-Allow-Origin' header has a value ' " + allowOriginHeaderValue + "' that is not equal to the supplied origin."; 174 detail = "The 'Access-Control-Allow-Origin' header has a value ' " + allowOriginHeaderValue + "' that is not equal to the supplied origin.";
173 } 175 }
174 errorDescription = buildAccessControlFailureMessage(detail, securityOrig in); 176 errorDescription = buildAccessControlFailureMessage(detail, securityOrig in);
177 errorDescription.append(" Either change the header, or, if you want an o paque response, use the Fetch API in 'no-cors' mode.");
175 return false; 178 return false;
176 } 179 }
177 180
178 if (includeCredentials == AllowStoredCredentials) { 181 if (includeCredentials == AllowStoredCredentials) {
179 const AtomicString& allowCredentialsHeaderValue = response.httpHeaderFie ld(allowCredentialsHeaderName); 182 const AtomicString& allowCredentialsHeaderValue = response.httpHeaderFie ld(allowCredentialsHeaderName);
180 if (allowCredentialsHeaderValue != "true") { 183 if (allowCredentialsHeaderValue != "true") {
181 errorDescription = buildAccessControlFailureMessage("Credentials fla g is 'true', but the 'Access-Control-Allow-Credentials' header is '" + allowCred entialsHeaderValue + "'. It must be 'true' to allow credentials.", securityOrigi n); 184 errorDescription = buildAccessControlFailureMessage("Credentials fla g is 'true', but the 'Access-Control-Allow-Credentials' header is '" + allowCred entialsHeaderValue + "'. It must be 'true' to allow credentials.", securityOrigi n);
182 return false; 185 return false;
183 } 186 }
184 } 187 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 newRequest.setHTTPOrigin(securityOrigin->toAtomicString()); 272 newRequest.setHTTPOrigin(securityOrigin->toAtomicString());
270 // If the user didn't request credentials in the first place, update our 273 // If the user didn't request credentials in the first place, update our
271 // state so we neither request them nor expect they must be allowed. 274 // state so we neither request them nor expect they must be allowed.
272 if (options.credentialsRequested == ClientDidNotRequestCredentials) 275 if (options.credentialsRequested == ClientDidNotRequestCredentials)
273 options.allowCredentials = DoNotAllowStoredCredentials; 276 options.allowCredentials = DoNotAllowStoredCredentials;
274 } 277 }
275 return true; 278 return true;
276 } 279 }
277 280
278 } // namespace blink 281 } // namespace blink
OLDNEW
« no previous file with comments | « LayoutTests/http/tests/xmlhttprequest/xmlhttprequest-unsafe-redirect-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698