mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
fix(ext/fetch): add accept-language
default header to fetch (#14882)
This commit is contained in:
parent
9f1f76f0b0
commit
60869c2598
3 changed files with 43 additions and 7 deletions
|
@ -643,6 +643,39 @@ Deno.test(
|
|||
"hello: World\r\n",
|
||||
"foo: Bar\r\n",
|
||||
"accept: */*\r\n",
|
||||
"accept-language: *\r\n",
|
||||
`user-agent: Deno/${Deno.version.deno}\r\n`,
|
||||
"accept-encoding: gzip, br\r\n",
|
||||
`host: ${addr}\r\n\r\n`,
|
||||
].join("");
|
||||
assertEquals(actual, expected);
|
||||
},
|
||||
);
|
||||
|
||||
Deno.test(
|
||||
{
|
||||
permissions: { net: true },
|
||||
},
|
||||
async function fetchRequestAcceptHeaders() {
|
||||
const addr = "127.0.0.1:4501";
|
||||
const bufPromise = bufferServer(addr);
|
||||
const response = await fetch(`http://${addr}/blah`, {
|
||||
method: "POST",
|
||||
headers: [
|
||||
["Accept", "text/html"],
|
||||
["Accept-Language", "en-US"],
|
||||
],
|
||||
});
|
||||
await response.arrayBuffer();
|
||||
assertEquals(response.status, 404);
|
||||
assertEquals(response.headers.get("Content-Length"), "2");
|
||||
|
||||
const actual = new TextDecoder().decode((await bufPromise).bytes());
|
||||
const expected = [
|
||||
"POST /blah HTTP/1.1\r\n",
|
||||
"content-length: 0\r\n",
|
||||
"accept: text/html\r\n",
|
||||
"accept-language: en-US\r\n",
|
||||
`user-agent: Deno/${Deno.version.deno}\r\n`,
|
||||
"accept-encoding: gzip, br\r\n",
|
||||
`host: ${addr}\r\n\r\n`,
|
||||
|
@ -678,6 +711,7 @@ Deno.test(
|
|||
"foo: Bar\r\n",
|
||||
"content-type: text/plain;charset=UTF-8\r\n",
|
||||
"accept: */*\r\n",
|
||||
"accept-language: *\r\n",
|
||||
`user-agent: Deno/${Deno.version.deno}\r\n`,
|
||||
"accept-encoding: gzip, br\r\n",
|
||||
`host: ${addr}\r\n`,
|
||||
|
@ -715,6 +749,7 @@ Deno.test(
|
|||
"hello: World\r\n",
|
||||
"foo: Bar\r\n",
|
||||
"accept: */*\r\n",
|
||||
"accept-language: *\r\n",
|
||||
`user-agent: Deno/${Deno.version.deno}\r\n`,
|
||||
"accept-encoding: gzip, br\r\n",
|
||||
`host: ${addr}\r\n`,
|
||||
|
@ -1072,6 +1107,7 @@ Deno.test(
|
|||
"hello: World\r\n",
|
||||
"foo: Bar\r\n",
|
||||
"accept: */*\r\n",
|
||||
"accept-language: *\r\n",
|
||||
`user-agent: Deno/${Deno.version.deno}\r\n`,
|
||||
"accept-encoding: gzip, br\r\n",
|
||||
`host: ${addr}\r\n`,
|
||||
|
|
|
@ -452,6 +452,10 @@
|
|||
ArrayPrototypePush(request.headerList, ["Accept", "*/*"]);
|
||||
}
|
||||
|
||||
if (!requestObject.headers.has("Accept-Language")) {
|
||||
ArrayPrototypePush(request.headerList, ["Accept-Language", "*"]);
|
||||
}
|
||||
|
||||
// 12.
|
||||
opPromise = PromisePrototypeCatch(
|
||||
PromisePrototypeThen(
|
||||
|
|
|
@ -3018,12 +3018,8 @@
|
|||
],
|
||||
"text-utf8.any.html": true,
|
||||
"text-utf8.any.worker.html": true,
|
||||
"accept-header.any.html": [
|
||||
"Request through fetch should have a 'accept-language' header"
|
||||
],
|
||||
"accept-header.any.worker.html": [
|
||||
"Request through fetch should have a 'accept-language' header"
|
||||
],
|
||||
"accept-header.any.html": true,
|
||||
"accept-header.any.worker.html": true,
|
||||
"conditional-get.any.html": false,
|
||||
"conditional-get.any.worker.html": false,
|
||||
"error-after-response.any.html": false,
|
||||
|
@ -4613,4 +4609,4 @@
|
|||
"idlharness.https.any.worker.html": true,
|
||||
"idlharness-shadowrealm.window.html": false
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue