mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -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",
|
"hello: World\r\n",
|
||||||
"foo: Bar\r\n",
|
"foo: Bar\r\n",
|
||||||
"accept: */*\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`,
|
`user-agent: Deno/${Deno.version.deno}\r\n`,
|
||||||
"accept-encoding: gzip, br\r\n",
|
"accept-encoding: gzip, br\r\n",
|
||||||
`host: ${addr}\r\n\r\n`,
|
`host: ${addr}\r\n\r\n`,
|
||||||
|
@ -678,6 +711,7 @@ Deno.test(
|
||||||
"foo: Bar\r\n",
|
"foo: Bar\r\n",
|
||||||
"content-type: text/plain;charset=UTF-8\r\n",
|
"content-type: text/plain;charset=UTF-8\r\n",
|
||||||
"accept: */*\r\n",
|
"accept: */*\r\n",
|
||||||
|
"accept-language: *\r\n",
|
||||||
`user-agent: Deno/${Deno.version.deno}\r\n`,
|
`user-agent: Deno/${Deno.version.deno}\r\n`,
|
||||||
"accept-encoding: gzip, br\r\n",
|
"accept-encoding: gzip, br\r\n",
|
||||||
`host: ${addr}\r\n`,
|
`host: ${addr}\r\n`,
|
||||||
|
@ -715,6 +749,7 @@ Deno.test(
|
||||||
"hello: World\r\n",
|
"hello: World\r\n",
|
||||||
"foo: Bar\r\n",
|
"foo: Bar\r\n",
|
||||||
"accept: */*\r\n",
|
"accept: */*\r\n",
|
||||||
|
"accept-language: *\r\n",
|
||||||
`user-agent: Deno/${Deno.version.deno}\r\n`,
|
`user-agent: Deno/${Deno.version.deno}\r\n`,
|
||||||
"accept-encoding: gzip, br\r\n",
|
"accept-encoding: gzip, br\r\n",
|
||||||
`host: ${addr}\r\n`,
|
`host: ${addr}\r\n`,
|
||||||
|
@ -1072,6 +1107,7 @@ Deno.test(
|
||||||
"hello: World\r\n",
|
"hello: World\r\n",
|
||||||
"foo: Bar\r\n",
|
"foo: Bar\r\n",
|
||||||
"accept: */*\r\n",
|
"accept: */*\r\n",
|
||||||
|
"accept-language: *\r\n",
|
||||||
`user-agent: Deno/${Deno.version.deno}\r\n`,
|
`user-agent: Deno/${Deno.version.deno}\r\n`,
|
||||||
"accept-encoding: gzip, br\r\n",
|
"accept-encoding: gzip, br\r\n",
|
||||||
`host: ${addr}\r\n`,
|
`host: ${addr}\r\n`,
|
||||||
|
|
|
@ -452,6 +452,10 @@
|
||||||
ArrayPrototypePush(request.headerList, ["Accept", "*/*"]);
|
ArrayPrototypePush(request.headerList, ["Accept", "*/*"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!requestObject.headers.has("Accept-Language")) {
|
||||||
|
ArrayPrototypePush(request.headerList, ["Accept-Language", "*"]);
|
||||||
|
}
|
||||||
|
|
||||||
// 12.
|
// 12.
|
||||||
opPromise = PromisePrototypeCatch(
|
opPromise = PromisePrototypeCatch(
|
||||||
PromisePrototypeThen(
|
PromisePrototypeThen(
|
||||||
|
|
|
@ -3018,12 +3018,8 @@
|
||||||
],
|
],
|
||||||
"text-utf8.any.html": true,
|
"text-utf8.any.html": true,
|
||||||
"text-utf8.any.worker.html": true,
|
"text-utf8.any.worker.html": true,
|
||||||
"accept-header.any.html": [
|
"accept-header.any.html": true,
|
||||||
"Request through fetch should have a 'accept-language' header"
|
"accept-header.any.worker.html": true,
|
||||||
],
|
|
||||||
"accept-header.any.worker.html": [
|
|
||||||
"Request through fetch should have a 'accept-language' header"
|
|
||||||
],
|
|
||||||
"conditional-get.any.html": false,
|
"conditional-get.any.html": false,
|
||||||
"conditional-get.any.worker.html": false,
|
"conditional-get.any.worker.html": false,
|
||||||
"error-after-response.any.html": false,
|
"error-after-response.any.html": false,
|
||||||
|
|
Loading…
Reference in a new issue