-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1504733 [wpt PR 13921] - Fetch: CORS and request's Content-Type h…
…eader, a=testonly Automatic update from web-platform-testsFetch: CORS and request's Content-Type header For whatwg/fetch#829. -- wpt-commits: eed621bc2f995bced9481df2cead4c4632c72cdd wpt-pr: 13921 UltraBlame original commit: 7f3034a3afb3e49f04faf7b21bf4bc7c597e285c
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
testing/web-platform/tests/cors/cors-safelisted-request-header.any.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
|
||
|
||
|
||
|
||
|
||
|
||
function safelist(headers, expectPreflight = false) { | ||
promise_test(async t => { | ||
const uuid = token(), | ||
url = CROSSDOMAIN + "resources/preflight.py?token=" + uuid, | ||
checkURL = "resources/preflight.py?check&token=" + uuid, | ||
request = () => fetch(url, { method: "POST", headers, body: "data" }); | ||
if (expectPreflight) { | ||
await promise_rejects(t, TypeError(), request()); | ||
} else { | ||
const response = await request(); | ||
assert_equals(response.headers.get("content-type"), "text/plain"); | ||
assert_equals(await response.text(), "NO"); | ||
} | ||
const checkResponse = await fetch(checkURL, { method: "POST", body: "data" }); | ||
assert_equals(await checkResponse.text(), (expectPreflight ? "1" : "0")); | ||
}, (expectPreflight ? "Preflight" : "No preflight") + " for " + JSON.stringify(headers)); | ||
} | ||
|
||
[ | ||
["text /plain", true], | ||
["text\t/\tplain", true], | ||
["text/plain;"], | ||
["text/plain;garbage"], | ||
["text/plain;garbage\u0001\u0002", true], | ||
["text/plain,", true], | ||
[",text/plain", true], | ||
["text/plain,text/plain", true], | ||
["text/plain,x/x", true], | ||
["text/plain\u000B", true], | ||
["text/plain\u000C", true], | ||
["application/www-form-urlencoded", true], | ||
["application/x-www-form-urlencoded;\u007F", true], | ||
["multipart/form-data"], | ||
["multipart/form-data;\"", true] | ||
].forEach(([mimeType, preflight = false]) => { | ||
safelist({"content-type": mimeType}, preflight); | ||
}) |