0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

BREAKING(unstable): remove Deno.HttpClient.rid (#22075)

As part of ongoing works to make `rid` private.

---------

Co-authored-by: Matt Mastracci <matthew@mastracci.com>
This commit is contained in:
Asher Gomez 2024-02-19 01:27:06 +11:00 committed by GitHub
parent 3a243c8272
commit 7abd72a80f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 21 additions and 10 deletions

View file

@ -876,8 +876,6 @@ declare namespace Deno {
* @category Fetch API * @category Fetch API
*/ */
export interface HttpClient extends Disposable { export interface HttpClient extends Disposable {
/** The resource ID associated with the client. */
rid: number;
/** Close the HTTP client. */ /** Close the HTTP client. */
close(): void; close(): void;
} }

View file

@ -10,11 +10,14 @@
/// <reference path="./lib.deno_fetch.d.ts" /> /// <reference path="./lib.deno_fetch.d.ts" />
/// <reference lib="esnext" /> /// <reference lib="esnext" />
import { core } from "ext:core/mod.js"; import { core, primordials } from "ext:core/mod.js";
import { SymbolDispose } from "ext:deno_web/00_infra.js"; import { SymbolDispose } from "ext:deno_web/00_infra.js";
import { op_fetch_custom_client } from "ext:core/ops"; import { op_fetch_custom_client } from "ext:core/ops";
const { internalRidSymbol } = core;
const { ObjectDefineProperty } = primordials;
/** /**
* @param {Deno.CreateHttpClientOptions} options * @param {Deno.CreateHttpClientOptions} options
* @returns {HttpClient} * @returns {HttpClient}
@ -29,19 +32,25 @@ function createHttpClient(options) {
} }
class HttpClient { class HttpClient {
#rid;
/** /**
* @param {number} rid * @param {number} rid
*/ */
constructor(rid) { constructor(rid) {
this.rid = rid; ObjectDefineProperty(this, internalRidSymbol, {
enumerable: false,
value: rid,
});
this.#rid = rid;
} }
close() { close() {
core.close(this.rid); core.close(this.#rid);
} }
[SymbolDispose]() { [SymbolDispose]() {
core.tryClose(this.rid); core.tryClose(this.#rid);
} }
} }
const HttpClientPrototype = HttpClient.prototype; const HttpClientPrototype = HttpClient.prototype;

View file

@ -9,7 +9,7 @@
/// <reference path="./lib.deno_fetch.d.ts" /> /// <reference path="./lib.deno_fetch.d.ts" />
/// <reference lib="esnext" /> /// <reference lib="esnext" />
import { primordials } from "ext:core/mod.js"; import { core, primordials } from "ext:core/mod.js";
const { const {
ArrayPrototypeMap, ArrayPrototypeMap,
ArrayPrototypeSlice, ArrayPrototypeSlice,
@ -45,6 +45,8 @@ import {
import { HttpClientPrototype } from "ext:deno_fetch/22_http_client.js"; import { HttpClientPrototype } from "ext:deno_fetch/22_http_client.js";
import * as abortSignal from "ext:deno_web/03_abort_signal.js"; import * as abortSignal from "ext:deno_web/03_abort_signal.js";
const { internalRidSymbol } = core;
const _request = Symbol("request"); const _request = Symbol("request");
const _headers = Symbol("headers"); const _headers = Symbol("headers");
const _getHeaders = Symbol("get headers"); const _getHeaders = Symbol("get headers");
@ -355,7 +357,7 @@ class Request {
"Argument 2", "Argument 2",
); );
} }
request.clientRid = init.client?.rid ?? null; request.clientRid = init.client?.[internalRidSymbol] ?? null;
} }
// 28. // 28.

View file

@ -65,6 +65,8 @@ import { clearTimeout as webClearTimeout } from "ext:deno_web/02_timers.js";
import { resourceForReadableStream } from "ext:deno_web/06_streams.js"; import { resourceForReadableStream } from "ext:deno_web/06_streams.js";
import { TcpConn } from "ext:deno_net/01_net.js"; import { TcpConn } from "ext:deno_net/01_net.js";
const { internalRidSymbol } = core;
enum STATUS_CODES { enum STATUS_CODES {
/** RFC 7231, 6.2.1 */ /** RFC 7231, 6.2.1 */
Continue = 100, Continue = 100,
@ -616,7 +618,7 @@ class ClientRequest extends OutgoingMessage {
this.method, this.method,
url, url,
headers, headers,
client.rid, client[internalRidSymbol],
this._bodyWriteRid, this._bodyWriteRid,
); );
} }
@ -802,7 +804,7 @@ class ClientRequest extends OutgoingMessage {
} }
this.destroyed = true; this.destroyed = true;
const rid = this._client?.rid; const rid = this._client?.[internalRidSymbol];
if (rid) { if (rid) {
core.tryClose(rid); core.tryClose(rid);
} }