summaryrefslogtreecommitdiff
path: root/op_crates/fetch/26_fetch.js
diff options
context:
space:
mode:
Diffstat (limited to 'op_crates/fetch/26_fetch.js')
-rw-r--r--op_crates/fetch/26_fetch.js21
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,