summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/tests/unit/fetch_test.ts36
-rw-r--r--ext/fetch/26_fetch.js4
-rw-r--r--tools/wpt/expectation.json10
3 files changed, 43 insertions, 7 deletions
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts
index 0720a0531..7adbb7721 100644
--- a/cli/tests/unit/fetch_test.ts
+++ b/cli/tests/unit/fetch_test.ts
@@ -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`,
diff --git a/ext/fetch/26_fetch.js b/ext/fetch/26_fetch.js
index 7ef9bdaf7..9a4916e21 100644
--- a/ext/fetch/26_fetch.js
+++ b/ext/fetch/26_fetch.js
@@ -452,6 +452,10 @@
ArrayPrototypePush(request.headerList, ["Accept", "*/*"]);
}
+ if (!requestObject.headers.has("Accept-Language")) {
+ ArrayPrototypePush(request.headerList, ["Accept-Language", "*"]);
+ }
+
// 12.
opPromise = PromisePrototypeCatch(
PromisePrototypeThen(
diff --git a/tools/wpt/expectation.json b/tools/wpt/expectation.json
index 3b25e5fbb..df2f24655 100644
--- a/tools/wpt/expectation.json
+++ b/tools/wpt/expectation.json
@@ -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
}
-}
+} \ No newline at end of file