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:
parent
3a243c8272
commit
7abd72a80f
4 changed files with 21 additions and 10 deletions
2
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
2
cli/tsc/dts/lib.deno.unstable.d.ts
vendored
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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.
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue