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" />
|
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
const core = globalThis.Deno.core;
|
|
|
|
const ops = core.ops;
|
2021-04-20 08:47:22 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
/**
|
|
|
|
* @param {Deno.CreateHttpClientOptions} options
|
|
|
|
* @returns {HttpClient}
|
|
|
|
*/
|
|
|
|
function createHttpClient(options) {
|
|
|
|
options.caCerts ??= [];
|
|
|
|
return new HttpClient(
|
|
|
|
ops.op_fetch_custom_client(
|
|
|
|
options,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
class HttpClient {
|
2021-04-20 08:47:22 -04:00
|
|
|
/**
|
2023-02-07 14:22:46 -05:00
|
|
|
* @param {number} rid
|
2021-04-20 08:47:22 -04:00
|
|
|
*/
|
2023-02-07 14:22:46 -05:00
|
|
|
constructor(rid) {
|
|
|
|
this.rid = rid;
|
2021-04-20 08:47:22 -04:00
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
close() {
|
|
|
|
core.close(this.rid);
|
2021-04-20 08:47:22 -04:00
|
|
|
}
|
2023-02-07 14:22:46 -05:00
|
|
|
}
|
|
|
|
const HttpClientPrototype = HttpClient.prototype;
|
2021-04-20 08:47:22 -04:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
export { createHttpClient, HttpClient, HttpClientPrototype };
|