diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2021-01-07 18:06:08 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-07 19:06:08 +0100 |
commit | e61e81eb57351782862aa50775ce4348f10b1856 (patch) | |
tree | 6099aa60857f586774a195034f18ac1fb10ca519 /op_crates/fetch/26_fetch.js | |
parent | c347dfcd565c3a396ae84dff46e7374851913462 (diff) |
feat: add --location=<href> and globalThis.location (#7369)
Diffstat (limited to 'op_crates/fetch/26_fetch.js')
-rw-r--r-- | op_crates/fetch/26_fetch.js | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/op_crates/fetch/26_fetch.js b/op_crates/fetch/26_fetch.js index 379c88e2f..0d405d4ec 100644 --- a/op_crates/fetch/26_fetch.js +++ b/op_crates/fetch/26_fetch.js @@ -5,6 +5,7 @@ // provided by "deno_web" const { URLSearchParams } = window.__bootstrap.url; + const { getLocationHref } = window.__bootstrap.location; const { requiredArguments } = window.__bootstrap.fetchUtil; const { ReadableStream, isReadableStreamDisturbed } = @@ -987,8 +988,10 @@ this.credentials = input.credentials; this._stream = input._stream; } else { - // TODO(nayeemrmn): Base from `--location` when implemented and set. - this.url = new URL(String(input)).href; + const baseUrl = getLocationHref(); + this.url = baseUrl != null + ? new URL(String(input), baseUrl).href + : new URL(String(input)).href; } if (init && "method" in init && init.method) { @@ -1175,20 +1178,25 @@ } } + let baseUrl = null; + + function setBaseUrl(href) { + baseUrl = href; + } + function sendFetchReq(url, method, headers, body, clientRid) { let headerArray = []; if (headers) { headerArray = Array.from(headers.entries()); } - const args = { + return opFetch({ method, url, + baseUrl, headers: headerArray, clientRid, - }; - - return opFetch(args, body); + }, body); } async function fetch(input, init) { @@ -1385,6 +1393,7 @@ Blob, DomFile, FormData, + setBaseUrl, fetch, Request, Response, |