mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00
Make fetch API more standards compliant (#3667)
This commit is contained in:
parent
fba40d86c4
commit
2b0cf74a8f
5 changed files with 194 additions and 9 deletions
|
@ -5,7 +5,8 @@ import {
|
|||
assert,
|
||||
assertEquals,
|
||||
assertStrContains,
|
||||
assertThrows
|
||||
assertThrows,
|
||||
fail
|
||||
} from "./test_util.ts";
|
||||
|
||||
testPerm({ net: true }, async function fetchConnectionError(): Promise<void> {
|
||||
|
@ -360,3 +361,75 @@ testPerm({ net: true }, async function fetchPostBodyTypedArray():Promise<void> {
|
|||
assertEquals(actual, expected);
|
||||
});
|
||||
*/
|
||||
|
||||
testPerm({ net: true }, async function fetchWithManualRedirection(): Promise<
|
||||
void
|
||||
> {
|
||||
const response = await fetch("http://localhost:4546/", {
|
||||
redirect: "manual"
|
||||
}); // will redirect to http://localhost:4545/
|
||||
assertEquals(response.status, 0);
|
||||
assertEquals(response.statusText, "");
|
||||
assertEquals(response.url, "");
|
||||
assertEquals(response.type, "opaqueredirect");
|
||||
try {
|
||||
await response.text();
|
||||
fail(
|
||||
"Reponse.text() didn't throw on a filtered response without a body (type opaqueredirect)"
|
||||
);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
testPerm({ net: true }, async function fetchWithErrorRedirection(): Promise<
|
||||
void
|
||||
> {
|
||||
const response = await fetch("http://localhost:4546/", {
|
||||
redirect: "error"
|
||||
}); // will redirect to http://localhost:4545/
|
||||
assertEquals(response.status, 0);
|
||||
assertEquals(response.statusText, "");
|
||||
assertEquals(response.url, "");
|
||||
assertEquals(response.type, "error");
|
||||
try {
|
||||
await response.text();
|
||||
fail(
|
||||
"Reponse.text() didn't throw on a filtered response without a body (type error)"
|
||||
);
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
||||
test(function responseRedirect(): void {
|
||||
const response = new Response(
|
||||
"example.com/beforeredirect",
|
||||
200,
|
||||
"OK",
|
||||
[["This-Should", "Disappear"]],
|
||||
-1,
|
||||
false,
|
||||
null
|
||||
);
|
||||
const redir = response.redirect("example.com/newLocation", 301);
|
||||
assertEquals(redir.status, 301);
|
||||
assertEquals(redir.statusText, "");
|
||||
assertEquals(redir.url, "");
|
||||
assertEquals(redir.headers.get("Location"), "example.com/newLocation");
|
||||
assertEquals(redir.type, "default");
|
||||
});
|
||||
|
||||
test(function responseConstructionHeaderRemoval(): void {
|
||||
const res = new Response(
|
||||
"example.com",
|
||||
200,
|
||||
"OK",
|
||||
[["Set-Cookie", "mysessionid"]],
|
||||
-1,
|
||||
false,
|
||||
"basic",
|
||||
null
|
||||
);
|
||||
assert(res.headers.get("Set-Cookie") != "mysessionid");
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue