2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 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" />
|
|
|
|
|
2024-02-18 09:27:06 -05:00
|
|
|
import { core, primordials } from "ext:core/mod.js";
|
2024-01-10 17:37:25 -05:00
|
|
|
|
2023-12-06 02:52:59 -05:00
|
|
|
import { SymbolDispose } from "ext:deno_web/00_infra.js";
|
2024-01-26 17:46:46 -05:00
|
|
|
import { op_fetch_custom_client } from "ext:core/ops";
|
2024-04-08 17:01:02 -04:00
|
|
|
import { loadTlsKeyPair } from "ext:deno_net/02_tls.js";
|
2021-04-20 08:47:22 -04:00
|
|
|
|
2024-02-18 09:27:06 -05:00
|
|
|
const { internalRidSymbol } = core;
|
|
|
|
const { ObjectDefineProperty } = primordials;
|
|
|
|
|
2023-02-07 14:22:46 -05:00
|
|
|
/**
|
|
|
|
* @param {Deno.CreateHttpClientOptions} options
|
|
|
|
* @returns {HttpClient}
|
|
|
|
*/
|
|
|
|
function createHttpClient(options) {
|
|
|
|
options.caCerts ??= [];
|
2024-04-18 13:21:08 -04:00
|
|
|
const keyPair = loadTlsKeyPair("Deno.createHttpClient", options);
|
2023-02-07 14:22:46 -05:00
|
|
|
return new HttpClient(
|
2024-01-10 17:37:25 -05:00
|
|
|
op_fetch_custom_client(
|
2023-02-07 14:22:46 -05:00
|
|
|
options,
|
2024-04-08 17:01:02 -04:00
|
|
|
keyPair,
|
2023-02-07 14:22:46 -05:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
class HttpClient {
|
2024-02-18 09:27:06 -05:00
|
|
|
#rid;
|
|
|
|
|
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) {
|
2024-02-18 09:27:06 -05:00
|
|
|
ObjectDefineProperty(this, internalRidSymbol, {
|
|
|
|
enumerable: false,
|
|
|
|
value: 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() {
|
2024-02-18 09:27:06 -05:00
|
|
|
core.close(this.#rid);
|
2021-04-20 08:47:22 -04:00
|
|
|
}
|
2023-12-06 02:52:59 -05:00
|
|
|
|
|
|
|
[SymbolDispose]() {
|
2024-02-18 09:27:06 -05:00
|
|
|
core.tryClose(this.#rid);
|
2023-12-06 02:52:59 -05: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 };
|