mirror of
https://github.com/denoland/deno.git
synced 2024-11-14 16:33:45 -05:00
fix(extensions/fetch): Add Origin header to outgoing requests for fetch (#11557)
This commit is contained in:
parent
ecb4c9492f
commit
f87aa44d94
3 changed files with 18 additions and 20 deletions
|
@ -677,6 +677,7 @@ unitTest(
|
||||||
"POST /blah HTTP/1.1\r\n",
|
"POST /blah HTTP/1.1\r\n",
|
||||||
"hello: World\r\n",
|
"hello: World\r\n",
|
||||||
"foo: Bar\r\n",
|
"foo: Bar\r\n",
|
||||||
|
"origin: http://js-unit-tests\r\n",
|
||||||
"accept: */*\r\n",
|
"accept: */*\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",
|
||||||
|
@ -712,6 +713,7 @@ unitTest(
|
||||||
"hello: World\r\n",
|
"hello: World\r\n",
|
||||||
"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",
|
||||||
|
"origin: http://js-unit-tests\r\n",
|
||||||
"accept: */*\r\n",
|
"accept: */*\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",
|
||||||
|
@ -749,6 +751,7 @@ unitTest(
|
||||||
"POST /blah HTTP/1.1\r\n",
|
"POST /blah HTTP/1.1\r\n",
|
||||||
"hello: World\r\n",
|
"hello: World\r\n",
|
||||||
"foo: Bar\r\n",
|
"foo: Bar\r\n",
|
||||||
|
"origin: http://js-unit-tests\r\n",
|
||||||
"accept: */*\r\n",
|
"accept: */*\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",
|
||||||
|
@ -1128,6 +1131,7 @@ unitTest(
|
||||||
"POST /blah HTTP/1.1\r\n",
|
"POST /blah HTTP/1.1\r\n",
|
||||||
"hello: World\r\n",
|
"hello: World\r\n",
|
||||||
"foo: Bar\r\n",
|
"foo: Bar\r\n",
|
||||||
|
"origin: http://js-unit-tests\r\n",
|
||||||
"accept: */*\r\n",
|
"accept: */*\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",
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
TypeError,
|
TypeError,
|
||||||
Uint8Array,
|
Uint8Array,
|
||||||
} = window.__bootstrap.primordials;
|
} = window.__bootstrap.primordials;
|
||||||
|
const { getLocationHref } = window.__bootstrap.location;
|
||||||
|
const { URL } = window.__bootstrap.url;
|
||||||
|
|
||||||
const REQUEST_BODY_HEADER_NAMES = [
|
const REQUEST_BODY_HEADER_NAMES = [
|
||||||
"content-encoding",
|
"content-encoding",
|
||||||
|
@ -429,6 +431,17 @@
|
||||||
}
|
}
|
||||||
requestObject.signal[abortSignal.add](onabort);
|
requestObject.signal[abortSignal.add](onabort);
|
||||||
|
|
||||||
|
const baseURL = getLocationHref();
|
||||||
|
if (
|
||||||
|
baseURL &&
|
||||||
|
(requestObject.method !== "GET" && requestObject.method !== "HEAD")
|
||||||
|
) {
|
||||||
|
ArrayPrototypePush(request.headerList, [
|
||||||
|
"origin",
|
||||||
|
new URL(baseURL).origin,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
if (!requestObject.headers.has("accept")) {
|
if (!requestObject.headers.has("accept")) {
|
||||||
ArrayPrototypePush(request.headerList, ["accept", "*/*"]);
|
ArrayPrototypePush(request.headerList, ["accept", "*/*"]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2646,26 +2646,7 @@
|
||||||
"request-headers-nonascii.any.html": true,
|
"request-headers-nonascii.any.html": true,
|
||||||
"request-headers.any.html": [
|
"request-headers.any.html": [
|
||||||
"Fetch with PUT without body",
|
"Fetch with PUT without body",
|
||||||
"Fetch with PUT with body",
|
"Fetch with POST without body"
|
||||||
"Fetch with POST without body",
|
|
||||||
"Fetch with POST with text body",
|
|
||||||
"Fetch with POST with FormData body",
|
|
||||||
"Fetch with POST with URLSearchParams body",
|
|
||||||
"Fetch with POST with Blob body",
|
|
||||||
"Fetch with POST with ArrayBuffer body",
|
|
||||||
"Fetch with POST with Uint8Array body",
|
|
||||||
"Fetch with POST with Int8Array body",
|
|
||||||
"Fetch with POST with Float32Array body",
|
|
||||||
"Fetch with POST with Float64Array body",
|
|
||||||
"Fetch with POST with DataView body",
|
|
||||||
"Fetch with POST with Blob body with mime type",
|
|
||||||
"Fetch with Chicken",
|
|
||||||
"Fetch with Chicken with body",
|
|
||||||
"Fetch with POST and mode \"same-origin\" needs an Origin header",
|
|
||||||
"Fetch with POST and mode \"no-cors\" needs an Origin header",
|
|
||||||
"Fetch with PUT and mode \"same-origin\" needs an Origin header",
|
|
||||||
"Fetch with TacO and mode \"same-origin\" needs an Origin header",
|
|
||||||
"Fetch with TacO and mode \"cors\" needs an Origin header"
|
|
||||||
],
|
],
|
||||||
"text-utf8.any.html": true,
|
"text-utf8.any.html": true,
|
||||||
"accept-header.any.html": [
|
"accept-header.any.html": [
|
||||||
|
|
Loading…
Reference in a new issue