2022-01-07 22:09:52 -05:00
|
|
|
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
|
2021-04-20 14:47:22 +02:00
|
|
|
|
|
|
|
// @ts-check
|
|
|
|
/// <reference path="../webidl/internal.d.ts" />
|
|
|
|
/// <reference path="../web/internal.d.ts" />
|
|
|
|
/// <reference path="../url/internal.d.ts" />
|
2021-06-10 15:26:10 +02:00
|
|
|
/// <reference path="../web/lib.deno_web.d.ts" />
|
2021-04-20 14:47:22 +02:00
|
|
|
/// <reference path="./internal.d.ts" />
|
2021-06-14 13:51:02 +02:00
|
|
|
/// <reference path="../web/06_streams_types.d.ts" />
|
2021-04-20 14:47:22 +02: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 09:26:15 +02:00
|
|
|
options.caCerts ??= [];
|
2021-10-31 19:14:22 +01:00
|
|
|
return new HttpClient(core.opSync("op_fetch_custom_client", options));
|
2021-04-20 14:47:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class HttpClient {
|
|
|
|
/**
|
2021-04-28 19:38:51 +05:30
|
|
|
* @param {number} rid
|
2021-04-20 14:47:22 +02:00
|
|
|
*/
|
|
|
|
constructor(rid) {
|
|
|
|
this.rid = rid;
|
|
|
|
}
|
|
|
|
close() {
|
|
|
|
core.close(this.rid);
|
|
|
|
}
|
|
|
|
}
|
2022-02-01 18:06:11 +01:00
|
|
|
const HttpClientPrototype = HttpClient.prototype;
|
2021-04-20 14:47:22 +02:00
|
|
|
|
|
|
|
window.__bootstrap.fetch ??= {};
|
|
|
|
window.__bootstrap.fetch.createHttpClient = createHttpClient;
|
|
|
|
window.__bootstrap.fetch.HttpClient = HttpClient;
|
2022-02-01 18:06:11 +01:00
|
|
|
window.__bootstrap.fetch.HttpClientPrototype = HttpClientPrototype;
|
2021-04-20 14:47:22 +02:00
|
|
|
})(globalThis);
|