diff options
author | Feng Yu <f3n67u@gmail.com> | 2021-08-02 17:19:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-02 02:19:21 -0700 |
commit | f87aa44d94240327fb4ab1dc756d70f71247edb4 (patch) | |
tree | 6ec2bef85c980fe5f5102bc36f83c3bbe69bc91c /extensions | |
parent | ecb4c9492f83b4d4a13fa098aeea2cbf1d03aad8 (diff) |
fix(extensions/fetch): Add Origin header to outgoing requests for fetch (#11557)
Diffstat (limited to 'extensions')
-rw-r--r-- | extensions/fetch/26_fetch.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/extensions/fetch/26_fetch.js b/extensions/fetch/26_fetch.js index f7166001e..f6cfced14 100644 --- a/extensions/fetch/26_fetch.js +++ b/extensions/fetch/26_fetch.js @@ -40,6 +40,8 @@ TypeError, Uint8Array, } = window.__bootstrap.primordials; + const { getLocationHref } = window.__bootstrap.location; + const { URL } = window.__bootstrap.url; const REQUEST_BODY_HEADER_NAMES = [ "content-encoding", @@ -429,6 +431,17 @@ } 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")) { ArrayPrototypePush(request.headerList, ["accept", "*/*"]); } |