2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Deno.CreateHttpClientOptions} options
|
|
|
|
* @returns {HttpClient}
|
|
|
|
*/
|
|
|
|
function createHttpClient(options) {
|
2021-09-30 03:26:15 -04:00
|
|
|
options.caCerts ??= [];
|
2021-10-31 14:14:22 -04:00
|
|
|
return new HttpClient(core.opSync("op_fetch_custom_client", 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);
|