2023-01-02 16:00:42 -05:00
|
|
|
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
2021-04-20 08:47:22 -04:00
|
|
|
|
|
|
|
// @ts-check
|
|
|
|
/// <reference path="../webidl/internal.d.ts" />
|
|
|
|
/// <reference path="../web/internal.d.ts" />
|
|
|
|
/// <reference path="../url/internal.d.ts" />
|
2021-06-10 09:26:10 -04:00
|
|
|
/// <reference path="../web/lib.deno_web.d.ts" />
|
2021-04-20 08:47:22 -04:00
|
|
|
/// <reference path="./internal.d.ts" />
|
2021-06-14 07:51:02 -04:00
|
|
|
/// <reference path="../web/06_streams_types.d.ts" />
|
2021-04-20 08:47:22 -04:00
|
|
|
/// <reference path="./lib.deno_fetch.d.ts" />
|
|
|
|
/// <reference lib="esnext" />
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
((window) => {
|
|
|
|
const core = window.Deno.core;
|
2022-08-11 09:56:56 -04:00
|
|
|
const ops = core.ops;
|
2021-04-20 08:47:22 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Deno.CreateHttpClientOptions} options
|
|
|
|
* @returns {HttpClient}
|
|
|
|
*/
|
|
|
|
function createHttpClient(options) {
|
2021-09-30 03:26:15 -04:00
|
|
|
options.caCerts ??= [];
|
2022-04-23 12:49:06 -04:00
|
|
|
return new HttpClient(
|
2022-08-11 09:56:56 -04:00
|
|
|
ops.op_fetch_custom_client(
|
2022-04-23 12:49:06 -04:00
|
|
|
options,
|
|
|
|
),
|
|
|
|
);
|
2021-04-20 08:47:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
class HttpClient {
|
|
|
|
/**
|
2021-04-28 10:08:51 -04:00
|
|
|
* @param {number} rid
|
2021-04-20 08:47:22 -04:00
|
|
|
*/
|
|
|
|
constructor(rid) {
|
|
|
|
this.rid = rid;
|
|
|
|
}
|
|
|
|
close() {
|
|
|
|
core.close(this.rid);
|
|
|
|
}
|
|
|
|
}
|
2022-02-01 12:06:11 -05:00
|
|
|
const HttpClientPrototype = HttpClient.prototype;
|
2021-04-20 08:47:22 -04:00
|
|
|
|
|
|
|
window.__bootstrap.fetch ??= {};
|
|
|
|
window.__bootstrap.fetch.createHttpClient = createHttpClient;
|
|
|
|
window.__bootstrap.fetch.HttpClient = HttpClient;
|
2022-02-01 12:06:11 -05:00
|
|
|
window.__bootstrap.fetch.HttpClientPrototype = HttpClientPrototype;
|
2021-04-20 08:47:22 -04:00
|
|
|
})(globalThis);
|