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-12-07 08:21:01 -05:00
|
|
|
import { core } from "ext:core/mod.js";
|
2023-02-07 14:22:46 -05:00
|
|
|
const ops = core.ops;
|
2023-12-06 02:52:59 -05:00
|
|
|
import { SymbolDispose } from "ext:deno_web/00_infra.js";
|
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-12-06 02:52:59 -05:00
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
close() {
|
|
|
|
core.close(this.rid);
|
2021-04-20 08:47:22 -04:00
|
|
|
}
|
2023-12-06 02:52:59 -05:00
|
|
|
|
|
|
|
[SymbolDispose]() {
|
|
|
|
core.tryClose(this.rid);
|
|
|
|
}
|
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 };
|