Skip to content

Commit d335a8f

Browse files
committed
Give SocketMetadata a proper type and attach it to H2 streams too
1 parent de493e7 commit d335a8f

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/util/socket-util.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ import {
1111
OngoingRequest,
1212
RawPassthroughEvent,
1313
TlsConnectionEvent,
14-
TlsSocketMetadata,
15-
TlsTimingEvents
14+
TlsSocketMetadata
1615
} from '../types';
1716

1817
// We store a bunch of metadata that we directly attach to sockets, TLS
@@ -27,6 +26,11 @@ export const ClientErrorInProgress = Symbol('client-error-in-progress');
2726
export const SocketTimingInfo = Symbol('socket-timing-info');
2827
export const SocketMetadata = Symbol('socket-metadata');
2928

29+
export type SocketMetadata = {
30+
tags?: string[];
31+
[key: string]: any;
32+
}
33+
3034
declare module 'net' {
3135
interface Socket {
3236
/**
@@ -78,10 +82,7 @@ declare module 'net' {
7882
* setup that will then be visible on all 'response' event data (for
7983
* example) later on.
8084
*/
81-
[SocketMetadata]?: {
82-
tags?: string[];
83-
[key: string]: any;
84-
}
85+
[SocketMetadata]?: SocketMetadata;
8586
}
8687
}
8788

@@ -121,6 +122,7 @@ declare module 'http2' {
121122
[LastHopEncrypted]?: net.Socket[typeof LastHopEncrypted];
122123
[LastTunnelAddress]?: net.Socket[typeof LastTunnelAddress];
123124
[SocketTimingInfo]?: net.Socket[typeof SocketTimingInfo];
125+
[SocketMetadata]?: SocketMetadata;
124126
}
125127
}
126128

@@ -333,6 +335,6 @@ export function buildSocketTimingInfo(): Required<net.Socket>[typeof SocketTimin
333335
return { initialSocket: Date.now(), initialSocketTimestamp: now() };
334336
}
335337

336-
export function getSocketMetadataTags(socket: net.Socket | undefined) {
338+
export function getSocketMetadataTags(socket: { [SocketMetadata]?: SocketMetadata } | undefined) {
337339
return (socket?.[SocketMetadata]?.tags || []).map((tag: string) => `socket-metadata:${tag}`);
338340
}

0 commit comments

Comments
 (0)