@types/node 16.11.39 → 18.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. {node v16.11 → node}/LICENSE +0 -0
  2. node v16.11/README.md → node/README.md +4 -4
  3. {node v16.11 → node}/assert/strict.d.ts +0 -0
  4. node v16.11/assert.d.ts → node/assert.d.ts +7 -8
  5. node v16.11/async_hooks.d.ts → node/async_hooks.d.ts +8 -4
  6. node/buffer.d.ts +2258 -0
  7. node v16.11/child_process.d.ts → node/child_process.d.ts +6 -3
  8. node v16.11/cluster.d.ts → node/cluster.d.ts +14 -18
  9. node v16.11/console.d.ts → node/console.d.ts +1 -1
  10. {node v16.11 → node}/constants.d.ts +0 -0
  11. node v16.11/crypto.d.ts → node/crypto.d.ts +679 -53
  12. node v16.11/dgram.d.ts → node/dgram.d.ts +3 -3
  13. node v16.11/diagnostics_channel.d.ts → node/diagnostics_channel.d.ts +2 -1
  14. node v16.11/dns/promises.d.ts → node/dns/promises.d.ts +10 -8
  15. node v16.11/dns.d.ts → node/dns.d.ts +16 -11
  16. node/dom-events.d.ts +126 -0
  17. node v16.11/domain.d.ts → node/domain.d.ts +3 -2
  18. node v16.11/events.d.ts → node/events.d.ts +65 -10
  19. node v16.11/fs/promises.d.ts → node/fs/promises.d.ts +86 -39
  20. node v16.11/fs.d.ts → node/fs.d.ts +149 -67
  21. node/globals.d.ts +300 -0
  22. {node v16.11 → node}/globals.global.d.ts +0 -0
  23. node v16.11/http.d.ts → node/http.d.ts +305 -77
  24. node v16.11/http2.d.ts → node/http2.d.ts +38 -5
  25. node v16.11/https.d.ts → node/https.d.ts +209 -59
  26. node v16.11/index.d.ts → node/index.d.ts +6 -3
  27. node v16.11/inspector.d.ts → node/inspector.d.ts +11 -15
  28. {node v16.11 → node}/module.d.ts +0 -0
  29. node v16.11/net.d.ts → node/net.d.ts +94 -21
  30. node v16.11/os.d.ts → node/os.d.ts +15 -4
  31. node v16.11/package.json → node/package.json +15 -8
  32. node v16.11/path.d.ts → node/path.d.ts +34 -23
  33. node v16.11/perf_hooks.d.ts → node/perf_hooks.d.ts +76 -8
  34. node v16.11/process.d.ts → node/process.d.ts +17 -16
  35. node v16.11/punycode.d.ts → node/punycode.d.ts +1 -1
  36. node v16.11/querystring.d.ts → node/querystring.d.ts +4 -4
  37. node/readline/promises.d.ts +143 -0
  38. node v16.11/readline.d.ts → node/readline.d.ts +140 -30
  39. node v16.11/repl.d.ts → node/repl.d.ts +2 -2
  40. node v16.11/stream/consumers.d.ts → node/stream/consumers.d.ts +2 -14
  41. {node v16.11 → node}/stream/promises.d.ts +0 -0
  42. node v16.11/stream/web.d.ts → node/stream/web.d.ts +3 -65
  43. node v16.11/stream.d.ts → node/stream.d.ts +97 -19
  44. node v16.11/string_decoder.d.ts → node/string_decoder.d.ts +1 -1
  45. node/test.d.ts +314 -0
  46. {node v16.11 → node}/timers/promises.d.ts +0 -0
  47. node v16.11/timers.d.ts → node/timers.d.ts +1 -1
  48. node v16.11/tls.d.ts → node/tls.d.ts +32 -23
  49. node v16.11/trace_events.d.ts → node/trace_events.d.ts +11 -1
  50. node/ts4.8/assert/strict.d.ts +8 -0
  51. node/ts4.8/assert.d.ts +911 -0
  52. node/ts4.8/async_hooks.d.ts +501 -0
  53. node v16.11/buffer.d.ts → node/ts4.8/buffer.d.ts +46 -19
  54. node/ts4.8/child_process.d.ts +1369 -0
  55. node/ts4.8/cluster.d.ts +410 -0
  56. node/ts4.8/console.d.ts +412 -0
  57. node/ts4.8/constants.d.ts +18 -0
  58. node/ts4.8/crypto.d.ts +3964 -0
  59. node/ts4.8/dgram.d.ts +545 -0
  60. node/ts4.8/diagnostics_channel.d.ts +153 -0
  61. node/ts4.8/dns/promises.d.ts +370 -0
  62. node/ts4.8/dns.d.ts +659 -0
  63. node/ts4.8/dom-events.d.ts +126 -0
  64. node/ts4.8/domain.d.ts +170 -0
  65. node/ts4.8/events.d.ts +678 -0
  66. node/ts4.8/fs/promises.d.ts +1138 -0
  67. node/ts4.8/fs.d.ts +3872 -0
  68. node v16.11/globals.d.ts → node/ts4.8/globals.d.ts +14 -4
  69. node/ts4.8/globals.global.d.ts +1 -0
  70. node/ts4.8/http.d.ts +1607 -0
  71. node/ts4.8/http2.d.ts +2134 -0
  72. node/ts4.8/https.d.ts +541 -0
  73. node/ts4.8/index.d.ts +88 -0
  74. node/ts4.8/inspector.d.ts +2741 -0
  75. node/ts4.8/module.d.ts +114 -0
  76. node/ts4.8/net.d.ts +869 -0
  77. node/ts4.8/os.d.ts +466 -0
  78. node/ts4.8/path.d.ts +191 -0
  79. node/ts4.8/perf_hooks.d.ts +625 -0
  80. node/ts4.8/process.d.ts +1482 -0
  81. node/ts4.8/punycode.d.ts +117 -0
  82. node/ts4.8/querystring.d.ts +131 -0
  83. node/ts4.8/readline/promises.d.ts +143 -0
  84. node/ts4.8/readline.d.ts +653 -0
  85. node/ts4.8/repl.d.ts +424 -0
  86. node/ts4.8/stream/consumers.d.ts +12 -0
  87. node/ts4.8/stream/promises.d.ts +42 -0
  88. node/ts4.8/stream/web.d.ts +330 -0
  89. node/ts4.8/stream.d.ts +1340 -0
  90. node/ts4.8/string_decoder.d.ts +67 -0
  91. node/ts4.8/test.d.ts +314 -0
  92. node/ts4.8/timers/promises.d.ts +68 -0
  93. node/ts4.8/timers.d.ts +94 -0
  94. node/ts4.8/tls.d.ts +1028 -0
  95. node/ts4.8/trace_events.d.ts +171 -0
  96. node v16.11/tty.d.ts → node/ts4.8/tty.d.ts +4 -2
  97. node v16.11/url.d.ts → node/ts4.8/url.d.ts +85 -39
  98. node v16.11/util.d.ts → node/ts4.8/util.d.ts +268 -12
  99. node v16.11/v8.d.ts → node/ts4.8/v8.d.ts +21 -3
  100. node v16.11/vm.d.ts → node/ts4.8/vm.d.ts +6 -4
  101. node v16.11/wasi.d.ts → node/ts4.8/wasi.d.ts +1 -1
  102. node v16.11/worker_threads.d.ts → node/ts4.8/worker_threads.d.ts +50 -10
  103. node v16.11/zlib.d.ts → node/ts4.8/zlib.d.ts +1 -1
  104. node/tty.d.ts +206 -0
  105. node/url.d.ts +897 -0
  106. node/util.d.ts +1850 -0
  107. node/v8.d.ts +396 -0
  108. node/vm.d.ts +509 -0
  109. node/wasi.d.ts +158 -0
  110. node/worker_threads.d.ts +689 -0
  111. node/zlib.d.ts +517 -0
@@ -13,7 +13,7 @@
13
13
  * { 'content-length': '123',
14
14
  * 'content-type': 'text/plain',
15
15
  * 'connection': 'keep-alive',
16
- * 'host': 'mysite.com',
16
+ * 'host': 'example.com',
17
17
  * 'accept': '*' }
18
18
  * ```
19
19
  *
@@ -34,10 +34,10 @@
34
34
  * 'content-LENGTH', '123',
35
35
  * 'content-type', 'text/plain',
36
36
  * 'CONNECTION', 'keep-alive',
37
- * 'Host', 'mysite.com',
37
+ * 'Host', 'example.com',
38
38
  * 'accepT', '*' ]
39
39
  * ```
40
- * @see [source](https://github.com/nodejs/node/blob/v16.9.0/lib/http.js)
40
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/http.js)
41
41
  */
42
42
  declare module 'http' {
43
43
  import * as stream from 'node:stream';
@@ -135,12 +135,17 @@ declare module 'http' {
135
135
  timeout?: number | undefined;
136
136
  setHost?: boolean | undefined;
137
137
  // https://github.com/nodejs/node/blob/master/lib/_http_client.js#L278
138
- createConnection?: ((options: ClientRequestArgs, oncreate: (err: Error, socket: Socket) => void) => Socket) | undefined;
138
+ createConnection?:
139
+ | ((options: ClientRequestArgs, oncreate: (err: Error, socket: Socket) => void) => Socket)
140
+ | undefined;
139
141
  lookup?: LookupFunction | undefined;
140
142
  }
141
- interface ServerOptions {
142
- IncomingMessage?: typeof IncomingMessage | undefined;
143
- ServerResponse?: typeof ServerResponse | undefined;
143
+ interface ServerOptions<
144
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
145
+ Response extends typeof ServerResponse = typeof ServerResponse,
146
+ > {
147
+ IncomingMessage?: Request | undefined;
148
+ ServerResponse?: Response | undefined;
144
149
  /**
145
150
  * Optionally overrides the value of
146
151
  * `--max-http-header-size` for requests received by this server, i.e.
@@ -155,14 +160,39 @@ declare module 'http' {
155
160
  * @default false
156
161
  */
157
162
  insecureHTTPParser?: boolean | undefined;
163
+ /**
164
+ * If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.
165
+ * @default false
166
+ * @since v16.5.0
167
+ */
168
+ noDelay?: boolean | undefined;
169
+ /**
170
+ * If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received,
171
+ * similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`.
172
+ * @default false
173
+ * @since v16.5.0
174
+ */
175
+ keepAlive?: boolean | undefined;
176
+ /**
177
+ * If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket.
178
+ * @default 0
179
+ * @since v16.5.0
180
+ */
181
+ keepAliveInitialDelay?: number | undefined;
158
182
  }
159
- type RequestListener = (req: IncomingMessage, res: ServerResponse) => void;
183
+ type RequestListener<
184
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
185
+ Response extends typeof ServerResponse = typeof ServerResponse,
186
+ > = (req: InstanceType<Request>, res: InstanceType<Response> & { req: InstanceType<Request> }) => void;
160
187
  /**
161
188
  * @since v0.1.17
162
189
  */
163
- class Server extends NetServer {
164
- constructor(requestListener?: RequestListener);
165
- constructor(options: ServerOptions, requestListener?: RequestListener);
190
+ class Server<
191
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
192
+ Response extends typeof ServerResponse = typeof ServerResponse,
193
+ > extends NetServer {
194
+ constructor(requestListener?: RequestListener<Request, Response>);
195
+ constructor(options: ServerOptions<Request, Response>, requestListener?: RequestListener<Request, Response>);
166
196
  /**
167
197
  * Sets the timeout value for sockets, and emits a `'timeout'` event on
168
198
  * the Server object, passing the socket as an argument, if a timeout
@@ -211,14 +241,12 @@ declare module 'http' {
211
241
  * Limit the amount of time the parser will wait to receive the complete HTTP
212
242
  * headers.
213
243
  *
214
- * In case of inactivity, the rules defined in `server.timeout` apply. However,
215
- * that inactivity based timeout would still allow the connection to be kept open
216
- * if the headers are being sent very slowly (by default, up to a byte per 2
217
- * minutes). In order to prevent this, whenever header data arrives an additional
218
- * check is made that more than `server.headersTimeout` milliseconds has not
219
- * passed since the connection was established. If the check fails, a `'timeout'`event is emitted on the server object, and (by default) the socket is destroyed.
220
- * See `server.timeout` for more information on how timeout behavior can be
221
- * customized.
244
+ * If the timeout expires, the server responds with status 408 without
245
+ * forwarding the request to the request listener and then closes the connection.
246
+ *
247
+ * It must be set to a non-zero value (e.g. 120 seconds) to protect against
248
+ * potential Denial-of-Service attacks in case the server is deployed without a
249
+ * reverse proxy in front.
222
250
  * @since v11.3.0, v10.14.0
223
251
  */
224
252
  headersTimeout: number;
@@ -251,80 +279,126 @@ declare module 'http' {
251
279
  * @since v14.11.0
252
280
  */
253
281
  requestTimeout: number;
282
+ /**
283
+ * Closes all connections connected to this server.
284
+ * @since v18.2.0
285
+ */
286
+ closeAllConnections(): void;
287
+ /**
288
+ * Closes all connections connected to this server which are not sending a request or waiting for a response.
289
+ * @since v18.2.0
290
+ */
291
+ closeIdleConnections(): void;
254
292
  addListener(event: string, listener: (...args: any[]) => void): this;
255
293
  addListener(event: 'close', listener: () => void): this;
256
294
  addListener(event: 'connection', listener: (socket: Socket) => void): this;
257
295
  addListener(event: 'error', listener: (err: Error) => void): this;
258
296
  addListener(event: 'listening', listener: () => void): this;
259
- addListener(event: 'checkContinue', listener: RequestListener): this;
260
- addListener(event: 'checkExpectation', listener: RequestListener): this;
297
+ addListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
298
+ addListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
261
299
  addListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
262
- addListener(event: 'connect', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
263
- addListener(event: 'request', listener: RequestListener): this;
264
- addListener(event: 'upgrade', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
300
+ addListener(
301
+ event: 'connect',
302
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
303
+ ): this;
304
+ addListener(event: 'request', listener: RequestListener<Request, Response>): this;
305
+ addListener(
306
+ event: 'upgrade',
307
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
308
+ ): this;
265
309
  emit(event: string, ...args: any[]): boolean;
266
310
  emit(event: 'close'): boolean;
267
311
  emit(event: 'connection', socket: Socket): boolean;
268
312
  emit(event: 'error', err: Error): boolean;
269
313
  emit(event: 'listening'): boolean;
270
- emit(event: 'checkContinue', req: IncomingMessage, res: ServerResponse): boolean;
271
- emit(event: 'checkExpectation', req: IncomingMessage, res: ServerResponse): boolean;
314
+ emit(
315
+ event: 'checkContinue',
316
+ req: InstanceType<Request>,
317
+ res: InstanceType<Response> & { req: InstanceType<Request> },
318
+ ): boolean;
319
+ emit(
320
+ event: 'checkExpectation',
321
+ req: InstanceType<Request>,
322
+ res: InstanceType<Response> & { req: InstanceType<Request> },
323
+ ): boolean;
272
324
  emit(event: 'clientError', err: Error, socket: stream.Duplex): boolean;
273
- emit(event: 'connect', req: IncomingMessage, socket: stream.Duplex, head: Buffer): boolean;
274
- emit(event: 'request', req: IncomingMessage, res: ServerResponse): boolean;
275
- emit(event: 'upgrade', req: IncomingMessage, socket: stream.Duplex, head: Buffer): boolean;
325
+ emit(event: 'connect', req: InstanceType<Request>, socket: stream.Duplex, head: Buffer): boolean;
326
+ emit(
327
+ event: 'request',
328
+ req: InstanceType<Request>,
329
+ res: InstanceType<Response> & { req: InstanceType<Request> },
330
+ ): boolean;
331
+ emit(event: 'upgrade', req: InstanceType<Request>, socket: stream.Duplex, head: Buffer): boolean;
276
332
  on(event: string, listener: (...args: any[]) => void): this;
277
333
  on(event: 'close', listener: () => void): this;
278
334
  on(event: 'connection', listener: (socket: Socket) => void): this;
279
335
  on(event: 'error', listener: (err: Error) => void): this;
280
336
  on(event: 'listening', listener: () => void): this;
281
- on(event: 'checkContinue', listener: RequestListener): this;
282
- on(event: 'checkExpectation', listener: RequestListener): this;
337
+ on(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
338
+ on(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
283
339
  on(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
284
- on(event: 'connect', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
285
- on(event: 'request', listener: RequestListener): this;
286
- on(event: 'upgrade', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
340
+ on(event: 'connect', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
341
+ on(event: 'request', listener: RequestListener<Request, Response>): this;
342
+ on(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
287
343
  once(event: string, listener: (...args: any[]) => void): this;
288
344
  once(event: 'close', listener: () => void): this;
289
345
  once(event: 'connection', listener: (socket: Socket) => void): this;
290
346
  once(event: 'error', listener: (err: Error) => void): this;
291
347
  once(event: 'listening', listener: () => void): this;
292
- once(event: 'checkContinue', listener: RequestListener): this;
293
- once(event: 'checkExpectation', listener: RequestListener): this;
348
+ once(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
349
+ once(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
294
350
  once(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
295
- once(event: 'connect', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
296
- once(event: 'request', listener: RequestListener): this;
297
- once(event: 'upgrade', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
351
+ once(
352
+ event: 'connect',
353
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
354
+ ): this;
355
+ once(event: 'request', listener: RequestListener<Request, Response>): this;
356
+ once(
357
+ event: 'upgrade',
358
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
359
+ ): this;
298
360
  prependListener(event: string, listener: (...args: any[]) => void): this;
299
361
  prependListener(event: 'close', listener: () => void): this;
300
362
  prependListener(event: 'connection', listener: (socket: Socket) => void): this;
301
363
  prependListener(event: 'error', listener: (err: Error) => void): this;
302
364
  prependListener(event: 'listening', listener: () => void): this;
303
- prependListener(event: 'checkContinue', listener: RequestListener): this;
304
- prependListener(event: 'checkExpectation', listener: RequestListener): this;
365
+ prependListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
366
+ prependListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
305
367
  prependListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
306
- prependListener(event: 'connect', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
307
- prependListener(event: 'request', listener: RequestListener): this;
308
- prependListener(event: 'upgrade', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
368
+ prependListener(
369
+ event: 'connect',
370
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
371
+ ): this;
372
+ prependListener(event: 'request', listener: RequestListener<Request, Response>): this;
373
+ prependListener(
374
+ event: 'upgrade',
375
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
376
+ ): this;
309
377
  prependOnceListener(event: string, listener: (...args: any[]) => void): this;
310
378
  prependOnceListener(event: 'close', listener: () => void): this;
311
379
  prependOnceListener(event: 'connection', listener: (socket: Socket) => void): this;
312
380
  prependOnceListener(event: 'error', listener: (err: Error) => void): this;
313
381
  prependOnceListener(event: 'listening', listener: () => void): this;
314
- prependOnceListener(event: 'checkContinue', listener: RequestListener): this;
315
- prependOnceListener(event: 'checkExpectation', listener: RequestListener): this;
382
+ prependOnceListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
383
+ prependOnceListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
316
384
  prependOnceListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
317
- prependOnceListener(event: 'connect', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
318
- prependOnceListener(event: 'request', listener: RequestListener): this;
319
- prependOnceListener(event: 'upgrade', listener: (req: IncomingMessage, socket: stream.Duplex, head: Buffer) => void): this;
385
+ prependOnceListener(
386
+ event: 'connect',
387
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
388
+ ): this;
389
+ prependOnceListener(event: 'request', listener: RequestListener<Request, Response>): this;
390
+ prependOnceListener(
391
+ event: 'upgrade',
392
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
393
+ ): this;
320
394
  }
321
395
  /**
322
396
  * This class serves as the parent class of {@link ClientRequest} and {@link ServerResponse}. It is an abstract of outgoing message from
323
397
  * the perspective of the participants of HTTP transaction.
324
398
  * @since v0.1.17
325
399
  */
326
- class OutgoingMessage extends stream.Writable {
327
- readonly req: IncomingMessage;
400
+ class OutgoingMessage<Request extends IncomingMessage = IncomingMessage> extends stream.Writable {
401
+ readonly req: Request;
328
402
  chunkedEncoding: boolean;
329
403
  shouldKeepAlive: boolean;
330
404
  useChunkedEncodingByDefault: boolean;
@@ -341,7 +415,7 @@ declare module 'http' {
341
415
  /**
342
416
  * Aliases of `outgoingMessage.socket`
343
417
  * @since v0.3.0
344
- * @deprecated Since v15.12.0 - Use `socket` instead.
418
+ * @deprecated Since v15.12.0,v14.17.1 - Use `socket` instead.
345
419
  */
346
420
  readonly connection: Socket | null;
347
421
  /**
@@ -392,13 +466,13 @@ declare module 'http' {
392
466
  * const headers = outgoingMessage.getHeaders();
393
467
  * // headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }
394
468
  * ```
395
- * @since v8.0.0
469
+ * @since v7.7.0
396
470
  */
397
471
  getHeaders(): OutgoingHttpHeaders;
398
472
  /**
399
473
  * Returns an array of names of headers of the outgoing outgoingMessage. All
400
474
  * names are lowercase.
401
- * @since v8.0.0
475
+ * @since v7.7.0
402
476
  */
403
477
  getHeaderNames(): string[];
404
478
  /**
@@ -408,7 +482,7 @@ declare module 'http' {
408
482
  * ```js
409
483
  * const hasContentType = outgoingMessage.hasHeader('content-type');
410
484
  * ```
411
- * @since v8.0.0
485
+ * @since v7.7.0
412
486
  */
413
487
  hasHeader(name: string): boolean;
414
488
  /**
@@ -418,6 +492,7 @@ declare module 'http' {
418
492
  * outgoingMessage.removeHeader('Content-Encoding');
419
493
  * ```
420
494
  * @since v0.4.0
495
+ * @param name Header name
421
496
  */
422
497
  removeHeader(name: string): void;
423
498
  /**
@@ -461,7 +536,7 @@ declare module 'http' {
461
536
  * passed as the second parameter to the `'request'` event.
462
537
  * @since v0.1.17
463
538
  */
464
- class ServerResponse extends OutgoingMessage {
539
+ class ServerResponse<Request extends IncomingMessage = IncomingMessage> extends OutgoingMessage<Request> {
465
540
  /**
466
541
  * When using implicit headers (not calling `response.writeHead()` explicitly),
467
542
  * this property controls the status code that will be sent to the client when
@@ -491,15 +566,50 @@ declare module 'http' {
491
566
  * @since v0.11.8
492
567
  */
493
568
  statusMessage: string;
494
- constructor(req: IncomingMessage);
569
+ constructor(req: Request);
495
570
  assignSocket(socket: Socket): void;
496
571
  detachSocket(socket: Socket): void;
497
572
  /**
498
- * Sends a HTTP/1.1 100 Continue message to the client, indicating that
573
+ * Sends an HTTP/1.1 100 Continue message to the client, indicating that
499
574
  * the request body should be sent. See the `'checkContinue'` event on`Server`.
500
575
  * @since v0.3.0
501
576
  */
502
577
  writeContinue(callback?: () => void): void;
578
+ /**
579
+ * Sends an HTTP/1.1 103 Early Hints message to the client with a Link header,
580
+ * indicating that the user agent can preload/preconnect the linked resources.
581
+ * The `hints` is an object containing the values of headers to be sent with
582
+ * early hints message. The optional `callback` argument will be called when
583
+ * the response message has been written.
584
+ *
585
+ * Example:
586
+ *
587
+ * ```js
588
+ * const earlyHintsLink = '</styles.css>; rel=preload; as=style';
589
+ * response.writeEarlyHints({
590
+ * 'link': earlyHintsLink,
591
+ * });
592
+ *
593
+ * const earlyHintsLinks = [
594
+ * '</styles.css>; rel=preload; as=style',
595
+ * '</scripts.js>; rel=preload; as=script',
596
+ * ];
597
+ * response.writeEarlyHints({
598
+ * 'link': earlyHintsLinks,
599
+ * 'x-trace-id': 'id for diagnostics'
600
+ * });
601
+ *
602
+ * const earlyHintsCallback = () => console.log('early hints message sent');
603
+ * response.writeEarlyHints({
604
+ * 'link': earlyHintsLinks
605
+ * }, earlyHintsCallback);
606
+ * ```
607
+ *
608
+ * @since v18.11.0
609
+ * @param hints An object containing the values of headers
610
+ * @param callback Will be called when the response message has been written
611
+ */
612
+ writeEarlyHints(hints: Record<string, string | string[]>, callback?: () => void): void;
503
613
  /**
504
614
  * Sends a response header to the request. The status code is a 3-digit HTTP
505
615
  * status code, like `404`. The last argument, `headers`, are the response headers.
@@ -557,10 +667,14 @@ declare module 'http' {
557
667
  * will result in a `TypeError` being thrown.
558
668
  * @since v0.1.30
559
669
  */
560
- writeHead(statusCode: number, statusMessage?: string, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[]): this;
670
+ writeHead(
671
+ statusCode: number,
672
+ statusMessage?: string,
673
+ headers?: OutgoingHttpHeaders | OutgoingHttpHeader[],
674
+ ): this;
561
675
  writeHead(statusCode: number, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[]): this;
562
676
  /**
563
- * Sends a HTTP/1.1 102 Processing message to the client, indicating that
677
+ * Sends an HTTP/1.1 102 Processing message to the client, indicating that
564
678
  * the request body should be sent.
565
679
  * @since v10.0.0
566
680
  */
@@ -608,6 +722,7 @@ declare module 'http' {
608
722
  * The `request.aborted` property will be `true` if the request has
609
723
  * been aborted.
610
724
  * @since v0.11.14
725
+ * @deprecated Since v17.0.0,v16.12.0 - Check `destroyed` instead.
611
726
  */
612
727
  aborted: boolean;
613
728
  /**
@@ -621,13 +736,58 @@ declare module 'http' {
621
736
  */
622
737
  protocol: string;
623
738
  /**
624
- * Whether the request is send through a reused socket.
739
+ * When sending request through a keep-alive enabled agent, the underlying socket
740
+ * might be reused. But if server closes connection at unfortunate time, client
741
+ * may run into a 'ECONNRESET' error.
742
+ *
743
+ * ```js
744
+ * const http = require('http');
745
+ *
746
+ * // Server has a 5 seconds keep-alive timeout by default
747
+ * http
748
+ * .createServer((req, res) => {
749
+ * res.write('hello\n');
750
+ * res.end();
751
+ * })
752
+ * .listen(3000);
753
+ *
754
+ * setInterval(() => {
755
+ * // Adapting a keep-alive agent
756
+ * http.get('http://localhost:3000', { agent }, (res) => {
757
+ * res.on('data', (data) => {
758
+ * // Do nothing
759
+ * });
760
+ * });
761
+ * }, 5000); // Sending request on 5s interval so it's easy to hit idle timeout
762
+ * ```
763
+ *
764
+ * By marking a request whether it reused socket or not, we can do
765
+ * automatic error retry base on it.
766
+ *
767
+ * ```js
768
+ * const http = require('http');
769
+ * const agent = new http.Agent({ keepAlive: true });
770
+ *
771
+ * function retriableRequest() {
772
+ * const req = http
773
+ * .get('http://localhost:3000', { agent }, (res) => {
774
+ * // ...
775
+ * })
776
+ * .on('error', (err) => {
777
+ * // Check if retry is needed
778
+ * if (req.reusedSocket &#x26;&#x26; err.code === 'ECONNRESET') {
779
+ * retriableRequest();
780
+ * }
781
+ * });
782
+ * }
783
+ *
784
+ * retriableRequest();
785
+ * ```
625
786
  * @since v13.0.0, v12.16.0
626
787
  */
627
788
  reusedSocket: boolean;
628
789
  /**
629
790
  * Limits maximum response headers count. If set to 0, no limit will be applied.
630
- * @default 2000
631
791
  */
632
792
  maxHeadersCount: number;
633
793
  constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void);
@@ -677,17 +837,26 @@ declare module 'http' {
677
837
  * const headerNames = request.getRawHeaderNames();
678
838
  * // headerNames === ['Foo', 'Set-Cookie']
679
839
  * ```
680
- * @since v15.13.0
840
+ * @since v15.13.0, v14.17.0
681
841
  */
682
842
  getRawHeaderNames(): string[];
843
+ /**
844
+ * @deprecated
845
+ */
683
846
  addListener(event: 'abort', listener: () => void): this;
684
- addListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
847
+ addListener(
848
+ event: 'connect',
849
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
850
+ ): this;
685
851
  addListener(event: 'continue', listener: () => void): this;
686
852
  addListener(event: 'information', listener: (info: InformationEvent) => void): this;
687
853
  addListener(event: 'response', listener: (response: IncomingMessage) => void): this;
688
854
  addListener(event: 'socket', listener: (socket: Socket) => void): this;
689
855
  addListener(event: 'timeout', listener: () => void): this;
690
- addListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
856
+ addListener(
857
+ event: 'upgrade',
858
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
859
+ ): this;
691
860
  addListener(event: 'close', listener: () => void): this;
692
861
  addListener(event: 'drain', listener: () => void): this;
693
862
  addListener(event: 'error', listener: (err: Error) => void): this;
@@ -695,6 +864,9 @@ declare module 'http' {
695
864
  addListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
696
865
  addListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
697
866
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
867
+ /**
868
+ * @deprecated
869
+ */
698
870
  on(event: 'abort', listener: () => void): this;
699
871
  on(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
700
872
  on(event: 'continue', listener: () => void): this;
@@ -710,6 +882,9 @@ declare module 'http' {
710
882
  on(event: 'pipe', listener: (src: stream.Readable) => void): this;
711
883
  on(event: 'unpipe', listener: (src: stream.Readable) => void): this;
712
884
  on(event: string | symbol, listener: (...args: any[]) => void): this;
885
+ /**
886
+ * @deprecated
887
+ */
713
888
  once(event: 'abort', listener: () => void): this;
714
889
  once(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
715
890
  once(event: 'continue', listener: () => void): this;
@@ -725,14 +900,23 @@ declare module 'http' {
725
900
  once(event: 'pipe', listener: (src: stream.Readable) => void): this;
726
901
  once(event: 'unpipe', listener: (src: stream.Readable) => void): this;
727
902
  once(event: string | symbol, listener: (...args: any[]) => void): this;
903
+ /**
904
+ * @deprecated
905
+ */
728
906
  prependListener(event: 'abort', listener: () => void): this;
729
- prependListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
907
+ prependListener(
908
+ event: 'connect',
909
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
910
+ ): this;
730
911
  prependListener(event: 'continue', listener: () => void): this;
731
912
  prependListener(event: 'information', listener: (info: InformationEvent) => void): this;
732
913
  prependListener(event: 'response', listener: (response: IncomingMessage) => void): this;
733
914
  prependListener(event: 'socket', listener: (socket: Socket) => void): this;
734
915
  prependListener(event: 'timeout', listener: () => void): this;
735
- prependListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
916
+ prependListener(
917
+ event: 'upgrade',
918
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
919
+ ): this;
736
920
  prependListener(event: 'close', listener: () => void): this;
737
921
  prependListener(event: 'drain', listener: () => void): this;
738
922
  prependListener(event: 'error', listener: (err: Error) => void): this;
@@ -740,14 +924,23 @@ declare module 'http' {
740
924
  prependListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
741
925
  prependListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
742
926
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
927
+ /**
928
+ * @deprecated
929
+ */
743
930
  prependOnceListener(event: 'abort', listener: () => void): this;
744
- prependOnceListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
931
+ prependOnceListener(
932
+ event: 'connect',
933
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
934
+ ): this;
745
935
  prependOnceListener(event: 'continue', listener: () => void): this;
746
936
  prependOnceListener(event: 'information', listener: (info: InformationEvent) => void): this;
747
937
  prependOnceListener(event: 'response', listener: (response: IncomingMessage) => void): this;
748
938
  prependOnceListener(event: 'socket', listener: (socket: Socket) => void): this;
749
939
  prependOnceListener(event: 'timeout', listener: () => void): this;
750
- prependOnceListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
940
+ prependOnceListener(
941
+ event: 'upgrade',
942
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
943
+ ): this;
751
944
  prependOnceListener(event: 'close', listener: () => void): this;
752
945
  prependOnceListener(event: 'drain', listener: () => void): this;
753
946
  prependOnceListener(event: 'error', listener: (err: Error) => void): this;
@@ -772,6 +965,7 @@ declare module 'http' {
772
965
  * The `message.aborted` property will be `true` if the request has
773
966
  * been aborted.
774
967
  * @since v10.1.0
968
+ * @deprecated Since v17.0.0,v16.12.0 - Check `message.destroyed` from <a href="stream.html#class-streamreadable" class="type">stream.Readable</a>.
775
969
  */
776
970
  aborted: boolean;
777
971
  /**
@@ -823,7 +1017,7 @@ declare module 'http' {
823
1017
  *
824
1018
  * This property is guaranteed to be an instance of the `net.Socket` class,
825
1019
  * a subclass of `stream.Duplex`, unless the user specified a socket
826
- * type other than `net.Socket`.
1020
+ * type other than `net.Socket` or internally nulled.
827
1021
  * @since v0.3.0
828
1022
  */
829
1023
  socket: Socket;
@@ -838,7 +1032,7 @@ declare module 'http' {
838
1032
  * // { 'user-agent': 'curl/7.22.0',
839
1033
  * // host: '127.0.0.1:8000',
840
1034
  * // accept: '*' }
841
- * console.log(request.headers);
1035
+ * console.log(request.getHeaders());
842
1036
  * ```
843
1037
  *
844
1038
  * Duplicates in raw headers are handled in the following ways, depending on the
@@ -914,14 +1108,14 @@ declare module 'http' {
914
1108
  * To parse the URL into its parts:
915
1109
  *
916
1110
  * ```js
917
- * new URL(request.url, `http://${request.headers.host}`);
1111
+ * new URL(request.url, `http://${request.getHeaders().host}`);
918
1112
  * ```
919
1113
  *
920
- * When `request.url` is `'/status?name=ryan'` and`request.headers.host` is `'localhost:3000'`:
1114
+ * When `request.url` is `'/status?name=ryan'` and`request.getHeaders().host` is `'localhost:3000'`:
921
1115
  *
922
1116
  * ```console
923
1117
  * $ node
924
- * > new URL(request.url, `http://${request.headers.host}`)
1118
+ * > new URL(request.url, `http://${request.getHeaders().host}`)
925
1119
  * URL {
926
1120
  * href: 'http://localhost:3000/status?name=ryan',
927
1121
  * origin: 'http://localhost:3000',
@@ -1114,12 +1308,23 @@ declare module 'http' {
1114
1308
  * added to the `'request'` event.
1115
1309
  * @since v0.1.13
1116
1310
  */
1117
- function createServer(requestListener?: RequestListener): Server;
1118
- function createServer(options: ServerOptions, requestListener?: RequestListener): Server;
1311
+ function createServer<
1312
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
1313
+ Response extends typeof ServerResponse = typeof ServerResponse,
1314
+ >(requestListener?: RequestListener<Request, Response>): Server<Request, Response>;
1315
+ function createServer<
1316
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
1317
+ Response extends typeof ServerResponse = typeof ServerResponse,
1318
+ >(
1319
+ options: ServerOptions<Request, Response>,
1320
+ requestListener?: RequestListener<Request, Response>,
1321
+ ): Server<Request, Response>;
1119
1322
  // although RequestOptions are passed as ClientRequestArgs to ClientRequest directly,
1120
1323
  // create interface RequestOptions would make the naming more clear to developers
1121
1324
  interface RequestOptions extends ClientRequestArgs {}
1122
1325
  /**
1326
+ * `options` in `socket.connect()` are also supported.
1327
+ *
1123
1328
  * Node.js maintains several connections per server to make HTTP requests.
1124
1329
  * This function allows one to transparently issue requests.
1125
1330
  *
@@ -1304,7 +1509,11 @@ declare module 'http' {
1304
1509
  * @since v0.3.6
1305
1510
  */
1306
1511
  function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
1307
- function request(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
1512
+ function request(
1513
+ url: string | URL,
1514
+ options: RequestOptions,
1515
+ callback?: (res: IncomingMessage) => void,
1516
+ ): ClientRequest;
1308
1517
  /**
1309
1518
  * Since most requests are GET requests without bodies, Node.js provides this
1310
1519
  * convenience method. The only difference between this method and {@link request} is that it sets the method to GET and calls `req.end()`automatically. The callback must take care to consume the
@@ -1367,6 +1576,25 @@ declare module 'http' {
1367
1576
  */
1368
1577
  function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
1369
1578
  function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
1579
+
1580
+ /**
1581
+ * Performs the low-level validations on the provided name that are done when `res.setHeader(name, value)` is called.
1582
+ * Passing illegal value as name will result in a TypeError being thrown, identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
1583
+ * @param name Header name
1584
+ * @since v14.3.0
1585
+ */
1586
+ function validateHeaderName(name: string): void;
1587
+ /**
1588
+ * Performs the low-level validations on the provided value that are done when `res.setHeader(name, value)` is called.
1589
+ * Passing illegal value as value will result in a TypeError being thrown.
1590
+ * - Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
1591
+ * - Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
1592
+ * @param name Header name
1593
+ * @param value Header value
1594
+ * @since v14.3.0
1595
+ */
1596
+ function validateHeaderValue(name: string, value: string): void;
1597
+
1370
1598
  let globalAgent: Agent;
1371
1599
  /**
1372
1600
  * Read-only property specifying the maximum allowed size of HTTP headers in bytes.