Skip to content

Commit 47ce111

Browse files
authored
🤖 Merge PR DefinitelyTyped#73527 [node] https: deconflict overridable Agent methods by @Renegade334
1 parent 4163c3a commit 47ce111

File tree

12 files changed

+72
-4
lines changed

12 files changed

+72
-4
lines changed

‎types/node/http.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ declare module "http" {
16151615
createConnection(
16161616
options: ClientRequestArgs,
16171617
callback?: (err: Error | null, stream: stream.Duplex) => void,
1618-
): stream.Duplex;
1618+
): stream.Duplex | null | undefined;
16191619
/**
16201620
* Called when `socket` is detached from a request and could be persisted by the`Agent`. Default behavior is to:
16211621
*

‎types/node/https.d.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ declare module "https" {
3232
class Agent extends http.Agent {
3333
constructor(options?: AgentOptions);
3434
options: AgentOptions;
35+
createConnection(
36+
options: RequestOptions,
37+
callback?: (err: Error | null, stream: Duplex) => void,
38+
): Duplex | null | undefined;
39+
getName(options?: RequestOptions): string;
3540
}
3641
interface Server<
3742
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,

‎types/node/test/https.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@ import * as url from "node:url";
2222

2323
agent = https.globalAgent;
2424

25+
class CustomAgent extends https.Agent {
26+
createConnection(options: https.RequestOptions, callback?: (err: Error | null, socket: net.Socket) => void) {
27+
const socket = new net.Socket(options);
28+
callback?.(null, socket);
29+
return socket;
30+
}
31+
getName(options: https.RequestOptions) {
32+
return `${super.getName(options)}:${options?.ca}:${options?.cert}:${options?.key}`;
33+
}
34+
}
35+
agent = new CustomAgent();
36+
2537
let sockets: NodeJS.ReadOnlyDict<net.Socket[]> = agent.sockets;
2638
sockets = agent.freeSockets;
2739

‎types/node/v18/http.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ declare module "http" {
15591559
createConnection(
15601560
options: ClientRequestArgs,
15611561
callback?: (err: Error | null, stream: stream.Duplex) => void,
1562-
): stream.Duplex;
1562+
): stream.Duplex | null | undefined;
15631563
/**
15641564
* Called when `socket` is detached from a request and could be persisted by the`Agent`. Default behavior is to:
15651565
*

‎types/node/v18/https.d.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ declare module "https" {
3131
class Agent extends http.Agent {
3232
constructor(options?: AgentOptions);
3333
options: AgentOptions;
34+
createConnection(
35+
options: RequestOptions,
36+
callback?: (err: Error | null, stream: Duplex) => void,
37+
): Duplex | null | undefined;
38+
getName(options?: RequestOptions): string;
3439
}
3540
interface Server<
3641
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,

‎types/node/v18/test/https.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ import * as url from "node:url";
1919

2020
agent = https.globalAgent;
2121

22+
class CustomAgent extends https.Agent {
23+
createConnection(options: https.RequestOptions, callback?: (err: Error | null, socket: net.Socket) => void) {
24+
const socket = new net.Socket(options);
25+
callback?.(null, socket);
26+
return socket;
27+
}
28+
getName(options: https.RequestOptions) {
29+
return `${super.getName(options)}:${options?.ca}:${options?.cert}:${options?.key}`;
30+
}
31+
}
32+
agent = new CustomAgent();
33+
2234
let sockets: NodeJS.ReadOnlyDict<net.Socket[]> = agent.sockets;
2335
sockets = agent.freeSockets;
2436

‎types/node/v20/http.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ declare module "http" {
15891589
createConnection(
15901590
options: ClientRequestArgs,
15911591
callback?: (err: Error | null, stream: stream.Duplex) => void,
1592-
): stream.Duplex;
1592+
): stream.Duplex | null | undefined;
15931593
/**
15941594
* Called when `socket` is detached from a request and could be persisted by the`Agent`. Default behavior is to:
15951595
*

‎types/node/v20/https.d.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ declare module "https" {
3131
class Agent extends http.Agent {
3232
constructor(options?: AgentOptions);
3333
options: AgentOptions;
34+
createConnection(
35+
options: RequestOptions,
36+
callback?: (err: Error | null, stream: Duplex) => void,
37+
): Duplex | null | undefined;
38+
getName(options?: RequestOptions): string;
3439
}
3540
interface Server<
3641
Request extends typeof http.IncomingMessage = typeof http.IncomingMessage,

‎types/node/v20/test/https.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ import * as url from "node:url";
1919

2020
agent = https.globalAgent;
2121

22+
class CustomAgent extends https.Agent {
23+
createConnection(options: https.RequestOptions, callback?: (err: Error | null, socket: net.Socket) => void) {
24+
const socket = new net.Socket(options);
25+
callback?.(null, socket);
26+
return socket;
27+
}
28+
getName(options: https.RequestOptions) {
29+
return `${super.getName(options)}:${options?.ca}:${options?.cert}:${options?.key}`;
30+
}
31+
}
32+
agent = new CustomAgent();
33+
2234
let sockets: NodeJS.ReadOnlyDict<net.Socket[]> = agent.sockets;
2335
sockets = agent.freeSockets;
2436

‎types/node/v22/http.d.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ declare module "http" {
15911591
createConnection(
15921592
options: ClientRequestArgs,
15931593
callback?: (err: Error | null, stream: stream.Duplex) => void,
1594-
): stream.Duplex;
1594+
): stream.Duplex | null | undefined;
15951595
/**
15961596
* Called when `socket` is detached from a request and could be persisted by the`Agent`. Default behavior is to:
15971597
*

0 commit comments

Comments
 (0)