1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(ext/fetch): add accept-language default header to fetch (#14882)

This commit is contained in:
Mark Ladyshau 2022-06-19 23:33:24 +02:00 committed by GitHub
parent 9f1f76f0b0
commit 60869c2598
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 7 deletions

View file

@ -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`,

View file

@ -452,6 +452,10 @@
ArrayPrototypePush(request.headerList, ["Accept", "*/*"]);
}
if (!requestObject.headers.has("Accept-Language")) {
ArrayPrototypePush(request.headerList, ["Accept-Language", "*"]);
}
// 12.
opPromise = PromisePrototypeCatch(
PromisePrototypeThen(

View file

@ -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
}
}
}