summaryrefslogtreecommitdiff
path: root/cli/rt
diff options
context:
space:
mode:
Diffstat (limited to 'cli/rt')
-rw-r--r--cli/rt/26_fetch.js52
-rw-r--r--cli/rt/90_deno_ns.js2
2 files changed, 38 insertions, 16 deletions
diff --git a/cli/rt/26_fetch.js b/cli/rt/26_fetch.js
index 2aee7c457..9e34aa8d8 100644
--- a/cli/rt/26_fetch.js
+++ b/cli/rt/26_fetch.js
@@ -6,16 +6,30 @@
const { Blob, bytesSymbol: blobBytesSymbol } = window.__bootstrap.blob;
const { read } = window.__bootstrap.io;
const { close } = window.__bootstrap.resources;
- const { sendAsync } = window.__bootstrap.dispatchJson;
+ const { sendSync, sendAsync } = window.__bootstrap.dispatchJson;
const Body = window.__bootstrap.body;
const { ReadableStream } = window.__bootstrap.streams;
const { MultipartBuilder } = window.__bootstrap.multipart;
const { Headers } = window.__bootstrap.headers;
- function opFetch(
- args,
- body,
- ) {
+ function createHttpClient(options) {
+ return new HttpClient(opCreateHttpClient(options));
+ }
+
+ function opCreateHttpClient(args) {
+ return sendSync("op_create_http_client", args);
+ }
+
+ class HttpClient {
+ constructor(rid) {
+ this.rid = rid;
+ }
+ close() {
+ close(this.rid);
+ }
+ }
+
+ function opFetch(args, body) {
let zeroCopy;
if (body != null) {
zeroCopy = new Uint8Array(body.buffer, body.byteOffset, body.byteLength);
@@ -169,12 +183,7 @@
}
}
- function sendFetchReq(
- url,
- method,
- headers,
- body,
- ) {
+ function sendFetchReq(url, method, headers, body, clientRid) {
let headerArray = [];
if (headers) {
headerArray = Array.from(headers.entries());
@@ -184,19 +193,18 @@
method,
url,
headers: headerArray,
+ clientRid,
};
return opFetch(args, body);
}
- async function fetch(
- input,
- init,
- ) {
+ async function fetch(input, init) {
let url;
let method = null;
let headers = null;
let body;
+ let clientRid = null;
let redirected = false;
let remRedirectCount = 20; // TODO: use a better way to handle
@@ -250,6 +258,10 @@
headers.set("content-type", contentType);
}
}
+
+ if (init.client instanceof HttpClient) {
+ clientRid = init.client.rid;
+ }
}
} else {
url = input.url;
@@ -264,7 +276,13 @@
let responseBody;
let responseInit = {};
while (remRedirectCount) {
- const fetchResponse = await sendFetchReq(url, method, headers, body);
+ const fetchResponse = await sendFetchReq(
+ url,
+ method,
+ headers,
+ body,
+ clientRid,
+ );
if (
NULL_BODY_STATUS.includes(fetchResponse.status) ||
@@ -366,5 +384,7 @@
window.__bootstrap.fetch = {
fetch,
Response,
+ HttpClient,
+ createHttpClient,
};
})(this);
diff --git a/cli/rt/90_deno_ns.js b/cli/rt/90_deno_ns.js
index bb556146c..ac22410f6 100644
--- a/cli/rt/90_deno_ns.js
+++ b/cli/rt/90_deno_ns.js
@@ -126,4 +126,6 @@ __bootstrap.denoNsUnstable = {
fdatasync: __bootstrap.fs.fdatasync,
fsyncSync: __bootstrap.fs.fsyncSync,
fsync: __bootstrap.fs.fsync,
+ HttpClient: __bootstrap.fetch.HttpClient,
+ createHttpClient: __bootstrap.fetch.createHttpClient,
};