summaryrefslogtreecommitdiff
path: root/ext/fetch/22_http_client.js
blob: dd5b99bfecb4bbe986da0148138b53c8ee8b2313 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

// @ts-check
/// <reference path="../webidl/internal.d.ts" />
/// <reference path="../web/internal.d.ts" />
/// <reference path="../url/internal.d.ts" />
/// <reference path="../web/lib.deno_web.d.ts" />
/// <reference path="./internal.d.ts" />
/// <reference path="../web/06_streams_types.d.ts" />
/// <reference path="./lib.deno_fetch.d.ts" />
/// <reference lib="esnext" />

import { core } from "ext:core/mod.js";
const ops = core.ops;
import { SymbolDispose } from "ext:deno_web/00_infra.js";

/**
 * @param {Deno.CreateHttpClientOptions} options
 * @returns {HttpClient}
 */
function createHttpClient(options) {
  options.caCerts ??= [];
  return new HttpClient(
    ops.op_fetch_custom_client(
      options,
    ),
  );
}

class HttpClient {
  /**
   * @param {number} rid
   */
  constructor(rid) {
    this.rid = rid;
  }

  close() {
    core.close(this.rid);
  }

  [SymbolDispose]() {
    core.tryClose(this.rid);
  }
}
const HttpClientPrototype = HttpClient.prototype;

export { createHttpClient, HttpClient, HttpClientPrototype };