@types/node 18.16.3 → 20.1.0

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 (96) hide show
  1. node/README.md +1 -1
  2. node/assert.d.ts +71 -75
  3. node/async_hooks.d.ts +62 -42
  4. node/buffer.d.ts +127 -99
  5. node/child_process.d.ts +50 -54
  6. node/cluster.d.ts +12 -12
  7. node/console.d.ts +5 -5
  8. node/crypto.d.ts +209 -220
  9. node/dgram.d.ts +15 -15
  10. node/diagnostics_channel.d.ts +25 -26
  11. node/dns/promises.d.ts +6 -6
  12. node/dns.d.ts +24 -16
  13. node/domain.d.ts +4 -4
  14. node/events.d.ts +60 -60
  15. node/fs/promises.d.ts +78 -48
  16. node/fs.d.ts +117 -81
  17. node/http.d.ts +158 -147
  18. node/http2.d.ts +42 -46
  19. node/https.d.ts +52 -153
  20. node/index.d.ts +1 -1
  21. node/inspector.d.ts +10 -3
  22. node/module.d.ts +5 -4
  23. node/net.d.ts +21 -18
  24. node/os.d.ts +22 -18
  25. node/package.json +2 -2
  26. node/path.d.ts +4 -4
  27. node/perf_hooks.d.ts +28 -15
  28. node/process.d.ts +43 -46
  29. node/punycode.d.ts +1 -1
  30. node/querystring.d.ts +5 -5
  31. node/readline/promises.d.ts +6 -4
  32. node/readline.d.ts +15 -15
  33. node/repl.d.ts +9 -9
  34. node/stream/consumers.d.ts +1 -1
  35. node/stream.d.ts +88 -136
  36. node/string_decoder.d.ts +6 -6
  37. node/test.d.ts +423 -186
  38. node/timers/promises.d.ts +3 -3
  39. node/timers.d.ts +2 -2
  40. node/tls.d.ts +24 -16
  41. node/trace_events.d.ts +20 -9
  42. node/ts4.8/assert.d.ts +71 -75
  43. node/ts4.8/async_hooks.d.ts +62 -42
  44. node/ts4.8/buffer.d.ts +127 -99
  45. node/ts4.8/child_process.d.ts +50 -54
  46. node/ts4.8/cluster.d.ts +12 -12
  47. node/ts4.8/console.d.ts +5 -5
  48. node/ts4.8/crypto.d.ts +209 -220
  49. node/ts4.8/dgram.d.ts +15 -15
  50. node/ts4.8/diagnostics_channel.d.ts +25 -26
  51. node/ts4.8/dns/promises.d.ts +6 -6
  52. node/ts4.8/dns.d.ts +24 -16
  53. node/ts4.8/domain.d.ts +4 -4
  54. node/ts4.8/events.d.ts +60 -60
  55. node/ts4.8/fs/promises.d.ts +96 -45
  56. node/ts4.8/fs.d.ts +203 -67
  57. node/ts4.8/globals.d.ts +29 -28
  58. node/ts4.8/http.d.ts +198 -126
  59. node/ts4.8/http2.d.ts +42 -46
  60. node/ts4.8/https.d.ts +52 -153
  61. node/ts4.8/inspector.d.ts +10 -3
  62. node/ts4.8/module.d.ts +5 -4
  63. node/ts4.8/net.d.ts +24 -21
  64. node/ts4.8/os.d.ts +22 -18
  65. node/ts4.8/path.d.ts +4 -4
  66. node/ts4.8/perf_hooks.d.ts +28 -15
  67. node/ts4.8/process.d.ts +43 -46
  68. node/ts4.8/punycode.d.ts +1 -1
  69. node/ts4.8/querystring.d.ts +5 -5
  70. node/ts4.8/readline/promises.d.ts +6 -4
  71. node/ts4.8/readline.d.ts +15 -15
  72. node/ts4.8/repl.d.ts +9 -9
  73. node/ts4.8/stream/consumers.d.ts +1 -1
  74. node/ts4.8/stream.d.ts +91 -139
  75. node/ts4.8/string_decoder.d.ts +6 -6
  76. node/ts4.8/test.d.ts +423 -186
  77. node/ts4.8/timers/promises.d.ts +3 -3
  78. node/ts4.8/timers.d.ts +9 -2
  79. node/ts4.8/tls.d.ts +24 -16
  80. node/ts4.8/trace_events.d.ts +20 -9
  81. node/ts4.8/tty.d.ts +4 -5
  82. node/ts4.8/url.d.ts +26 -36
  83. node/ts4.8/util.d.ts +143 -116
  84. node/ts4.8/v8.d.ts +110 -16
  85. node/ts4.8/vm.d.ts +292 -42
  86. node/ts4.8/wasi.d.ts +13 -19
  87. node/ts4.8/worker_threads.d.ts +32 -34
  88. node/ts4.8/zlib.d.ts +11 -11
  89. node/tty.d.ts +4 -5
  90. node/url.d.ts +26 -36
  91. node/util.d.ts +146 -111
  92. node/v8.d.ts +110 -16
  93. node/vm.d.ts +292 -42
  94. node/wasi.d.ts +13 -19
  95. node/worker_threads.d.ts +32 -34
  96. node/zlib.d.ts +11 -11
node/ts4.8/http.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * To use the HTTP server and client one must `require('http')`.
2
+ * To use the HTTP server and client one must `require('node:http')`.
3
3
  *
4
4
  * The HTTP interfaces in Node.js are designed to support many features
5
5
  * of the protocol which have been traditionally difficult to use.
@@ -37,7 +37,7 @@
37
37
  * 'Host', 'example.com',
38
38
  * 'accepT', '*' ]
39
39
  * ```
40
- * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/http.js)
40
+ * @see [source](https://github.com/nodejs/node/blob/v20.1.0/lib/http.js)
41
41
  */
42
42
  declare module 'http' {
43
43
  import * as stream from 'node:stream';
@@ -144,6 +144,7 @@ declare module 'http' {
144
144
  socketPath?: string | undefined;
145
145
  timeout?: number | undefined;
146
146
  uniqueHeaders?: Array<string | string[]> | undefined;
147
+ joinDuplicateHeaders?: boolean;
147
148
  }
148
149
  interface ServerOptions<
149
150
  Request extends typeof IncomingMessage = typeof IncomingMessage,
@@ -164,6 +165,12 @@ declare module 'http' {
164
165
  * @since v18.0.0
165
166
  */
166
167
  requestTimeout?: number | undefined;
168
+ /**
169
+ * It joins the field line values of multiple headers in a request with `, ` instead of discarding the duplicates.
170
+ * @default false
171
+ * @since v18.14.0
172
+ */
173
+ joinDuplicateHeaders?: boolean;
167
174
  /**
168
175
  * The number of milliseconds of inactivity a server needs to wait for additional incoming data,
169
176
  * after it has finished writing the last response, before a socket will be destroyed.
@@ -177,6 +184,13 @@ declare module 'http' {
177
184
  * @default 30000
178
185
  */
179
186
  connectionsCheckingInterval?: number | undefined;
187
+ /**
188
+ * Optionally overrides all `socket`s' `readableHighWaterMark` and `writableHighWaterMark`.
189
+ * This affects `highWaterMark` property of both `IncomingMessage` and `ServerResponse`.
190
+ * Default: @see stream.getDefaultHighWaterMark().
191
+ * @since v20.1.0
192
+ */
193
+ highWaterMark?: number | undefined;
180
194
  /**
181
195
  * Use an insecure HTTP parser that accepts invalid HTTP headers when `true`.
182
196
  * Using the insecure parser should be avoided.
@@ -322,7 +336,8 @@ declare module 'http' {
322
336
  */
323
337
  closeAllConnections(): void;
324
338
  /**
325
- * Closes all connections connected to this server which are not sending a request or waiting for a response.
339
+ * Closes all connections connected to this server which are not sending a request
340
+ * or waiting for a response.
326
341
  * @since v18.2.0
327
342
  */
328
343
  closeIdleConnections(): void;
@@ -334,15 +349,10 @@ declare module 'http' {
334
349
  addListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
335
350
  addListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
336
351
  addListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
337
- addListener(
338
- event: 'connect',
339
- listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
340
- ): this;
352
+ addListener(event: 'connect', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
353
+ addListener(event: 'dropRequest', listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
341
354
  addListener(event: 'request', listener: RequestListener<Request, Response>): this;
342
- addListener(
343
- event: 'upgrade',
344
- listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
345
- ): this;
355
+ addListener(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
346
356
  emit(event: string, ...args: any[]): boolean;
347
357
  emit(event: 'close'): boolean;
348
358
  emit(event: 'connection', socket: Socket): boolean;
@@ -360,6 +370,7 @@ declare module 'http' {
360
370
  ): boolean;
361
371
  emit(event: 'clientError', err: Error, socket: stream.Duplex): boolean;
362
372
  emit(event: 'connect', req: InstanceType<Request>, socket: stream.Duplex, head: Buffer): boolean;
373
+ emit(event: 'dropRequest', req: InstanceType<Request>, socket: stream.Duplex): boolean;
363
374
  emit(
364
375
  event: 'request',
365
376
  req: InstanceType<Request>,
@@ -375,6 +386,7 @@ declare module 'http' {
375
386
  on(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
376
387
  on(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
377
388
  on(event: 'connect', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
389
+ on(event: 'dropRequest', listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
378
390
  on(event: 'request', listener: RequestListener<Request, Response>): this;
379
391
  on(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
380
392
  once(event: string, listener: (...args: any[]) => void): this;
@@ -385,15 +397,10 @@ declare module 'http' {
385
397
  once(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
386
398
  once(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
387
399
  once(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
388
- once(
389
- event: 'connect',
390
- listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
391
- ): this;
400
+ once(event: 'connect', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
401
+ once(event: 'dropRequest', listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
392
402
  once(event: 'request', listener: RequestListener<Request, Response>): this;
393
- once(
394
- event: 'upgrade',
395
- listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
396
- ): this;
403
+ once(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
397
404
  prependListener(event: string, listener: (...args: any[]) => void): this;
398
405
  prependListener(event: 'close', listener: () => void): this;
399
406
  prependListener(event: 'connection', listener: (socket: Socket) => void): this;
@@ -402,15 +409,10 @@ declare module 'http' {
402
409
  prependListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
403
410
  prependListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
404
411
  prependListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
405
- prependListener(
406
- event: 'connect',
407
- listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
408
- ): this;
412
+ prependListener(event: 'connect', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
413
+ prependListener(event: 'dropRequest', listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
409
414
  prependListener(event: 'request', listener: RequestListener<Request, Response>): this;
410
- prependListener(
411
- event: 'upgrade',
412
- listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
413
- ): this;
415
+ prependListener(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
414
416
  prependOnceListener(event: string, listener: (...args: any[]) => void): this;
415
417
  prependOnceListener(event: 'close', listener: () => void): this;
416
418
  prependOnceListener(event: 'connection', listener: (socket: Socket) => void): this;
@@ -419,19 +421,14 @@ declare module 'http' {
419
421
  prependOnceListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
420
422
  prependOnceListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
421
423
  prependOnceListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
422
- prependOnceListener(
423
- event: 'connect',
424
- listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
425
- ): this;
424
+ prependOnceListener(event: 'connect', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
425
+ prependOnceListener(event: 'dropRequest', listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
426
426
  prependOnceListener(event: 'request', listener: RequestListener<Request, Response>): this;
427
- prependOnceListener(
428
- event: 'upgrade',
429
- listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
430
- ): this;
427
+ prependOnceListener(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
431
428
  }
432
429
  /**
433
- * This class serves as the parent class of {@link ClientRequest} and {@link ServerResponse}. It is an abstract of outgoing message from
434
- * the perspective of the participants of HTTP transaction.
430
+ * This class serves as the parent class of {@link ClientRequest} and {@link ServerResponse}. It is an abstract outgoing message from
431
+ * the perspective of the participants of an HTTP transaction.
435
432
  * @since v0.1.17
436
433
  */
437
434
  class OutgoingMessage<Request extends IncomingMessage = IncomingMessage> extends stream.Writable {
@@ -450,7 +447,7 @@ declare module 'http' {
450
447
  */
451
448
  readonly headersSent: boolean;
452
449
  /**
453
- * Aliases of `outgoingMessage.socket`
450
+ * Alias of `outgoingMessage.socket`.
454
451
  * @since v0.3.0
455
452
  * @deprecated Since v15.12.0,v14.17.1 - Use `socket` instead.
456
453
  */
@@ -471,15 +468,33 @@ declare module 'http' {
471
468
  */
472
469
  setTimeout(msecs: number, callback?: () => void): this;
473
470
  /**
474
- * Sets a single header value for the header object.
471
+ * Sets a single header value. If the header already exists in the to-be-sent
472
+ * headers, its value will be replaced. Use an array of strings to send multiple
473
+ * headers with the same name.
475
474
  * @since v0.4.0
476
475
  * @param name Header name
477
476
  * @param value Header value
478
477
  */
479
478
  setHeader(name: string, value: number | string | ReadonlyArray<string>): this;
480
479
  /**
481
- * Gets the value of HTTP header with the given name. If such a name doesn't
482
- * exist in message, it will be `undefined`.
480
+ * Append a single header value for the header object.
481
+ *
482
+ * If the value is an array, this is equivalent of calling this method multiple
483
+ * times.
484
+ *
485
+ * If there were no previous value for the header, this is equivalent of calling `outgoingMessage.setHeader(name, value)`.
486
+ *
487
+ * Depending of the value of `options.uniqueHeaders` when the client request or the
488
+ * server were created, this will end up in the header being sent multiple times or
489
+ * a single time with values joined using `; `.
490
+ * @since v18.3.0, v16.17.0
491
+ * @param name Header name
492
+ * @param value Header value
493
+ */
494
+ appendHeader(name: string, value: string | ReadonlyArray<string>): this;
495
+ /**
496
+ * Gets the value of the HTTP header with the given name. If that header is not
497
+ * set, the returned value will be `undefined`.
483
498
  * @since v0.4.0
484
499
  * @param name Name of header
485
500
  */
@@ -492,8 +507,8 @@ declare module 'http' {
492
507
  * values. All header names are lowercase.
493
508
  *
494
509
  * The object returned by the `outgoingMessage.getHeaders()` method does
495
- * not prototypically inherit from the JavaScript Object. This means that
496
- * typical Object methods such as `obj.toString()`, `obj.hasOwnProperty()`,
510
+ * not prototypically inherit from the JavaScript `Object`. This means that
511
+ * typical `Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`,
497
512
  * and others are not defined and will not work.
498
513
  *
499
514
  * ```js
@@ -507,8 +522,8 @@ declare module 'http' {
507
522
  */
508
523
  getHeaders(): OutgoingHttpHeaders;
509
524
  /**
510
- * Returns an array of names of headers of the outgoing outgoingMessage. All
511
- * names are lowercase.
525
+ * Returns an array containing the unique names of the current outgoing headers.
526
+ * All names are lowercase.
512
527
  * @since v7.7.0
513
528
  */
514
529
  getHeaderNames(): string[];
@@ -535,11 +550,11 @@ declare module 'http' {
535
550
  /**
536
551
  * Adds HTTP trailers (headers but at the end of the message) to the message.
537
552
  *
538
- * Trailers are **only** be emitted if the message is chunked encoded. If not,
539
- * the trailer will be silently discarded.
553
+ * Trailers will **only** be emitted if the message is chunked encoded. If not,
554
+ * the trailers will be silently discarded.
540
555
  *
541
556
  * HTTP requires the `Trailer` header to be sent to emit trailers,
542
- * with a list of header fields in its value, e.g.
557
+ * with a list of header field names in its value, e.g.
543
558
  *
544
559
  * ```js
545
560
  * message.writeHead(200, { 'Content-Type': 'text/plain',
@@ -555,7 +570,7 @@ declare module 'http' {
555
570
  */
556
571
  addTrailers(headers: OutgoingHttpHeaders | ReadonlyArray<[string, string]>): void;
557
572
  /**
558
- * Compulsorily flushes the message headers
573
+ * Flushes the message headers.
559
574
  *
560
575
  * For efficiency reason, Node.js normally buffers the message headers
561
576
  * until `outgoingMessage.end()` is called or the first chunk of message data
@@ -563,7 +578,7 @@ declare module 'http' {
563
578
  * packet.
564
579
  *
565
580
  * It is usually desired (it saves a TCP round-trip), but not when the first
566
- * data is not sent until possibly much later. `outgoingMessage.flushHeaders()`bypasses the optimization and kickstarts the request.
581
+ * data is not sent until possibly much later. `outgoingMessage.flushHeaders()`bypasses the optimization and kickstarts the message.
567
582
  * @since v1.6.0
568
583
  */
569
584
  flushHeaders(): void;
@@ -603,6 +618,13 @@ declare module 'http' {
603
618
  * @since v0.11.8
604
619
  */
605
620
  statusMessage: string;
621
+ /**
622
+ * If set to `true`, Node.js will check whether the `Content-Length`header value and the size of the body, in bytes, are equal.
623
+ * Mismatching the `Content-Length` header value will result
624
+ * in an `Error` being thrown, identified by `code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.
625
+ * @since v18.10.0, v16.18.0
626
+ */
627
+ strictContentLength: boolean;
606
628
  constructor(req: Request);
607
629
  assignSocket(socket: Socket): void;
608
630
  detachSocket(socket: Socket): void;
@@ -619,7 +641,7 @@ declare module 'http' {
619
641
  * early hints message. The optional `callback` argument will be called when
620
642
  * the response message has been written.
621
643
  *
622
- * Example:
644
+ * **Example**
623
645
  *
624
646
  * ```js
625
647
  * const earlyHintsLink = '</styles.css>; rel=preload; as=style';
@@ -633,15 +655,14 @@ declare module 'http' {
633
655
  * ];
634
656
  * response.writeEarlyHints({
635
657
  * 'link': earlyHintsLinks,
636
- * 'x-trace-id': 'id for diagnostics'
658
+ * 'x-trace-id': 'id for diagnostics',
637
659
  * });
638
660
  *
639
661
  * const earlyHintsCallback = () => console.log('early hints message sent');
640
662
  * response.writeEarlyHints({
641
- * 'link': earlyHintsLinks
663
+ * 'link': earlyHintsLinks,
642
664
  * }, earlyHintsCallback);
643
665
  * ```
644
- *
645
666
  * @since v18.11.0
646
667
  * @param hints An object containing the values of headers
647
668
  * @param callback Will be called when the response message has been written
@@ -665,7 +686,7 @@ declare module 'http' {
665
686
  * response
666
687
  * .writeHead(200, {
667
688
  * 'Content-Length': Buffer.byteLength(body),
668
- * 'Content-Type': 'text/plain'
689
+ * 'Content-Type': 'text/plain',
669
690
  * })
670
691
  * .end(body);
671
692
  * ```
@@ -696,12 +717,12 @@ declare module 'http' {
696
717
  * });
697
718
  * ```
698
719
  *
699
- * `Content-Length` is given in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes. Node.js
700
- * does not check whether `Content-Length` and the length of the body which has
720
+ * `Content-Length` is read in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes. Node.js
721
+ * will check whether `Content-Length` and the length of the body which has
701
722
  * been transmitted are equal or not.
702
723
  *
703
724
  * Attempting to set a header field name or value that contains invalid characters
704
- * will result in a `TypeError` being thrown.
725
+ * will result in a \[`Error`\]\[\] being thrown.
705
726
  * @since v0.1.30
706
727
  */
707
728
  writeHead(
@@ -711,7 +732,7 @@ declare module 'http' {
711
732
  ): this;
712
733
  writeHead(statusCode: number, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[]): this;
713
734
  /**
714
- * Sends an HTTP/1.1 102 Processing message to the client, indicating that
735
+ * Sends a HTTP/1.1 102 Processing message to the client, indicating that
715
736
  * the request body should be sent.
716
737
  * @since v10.0.0
717
738
  */
@@ -750,8 +771,11 @@ declare module 'http' {
750
771
  *
751
772
  * For backward compatibility, `res` will only emit `'error'` if there is an`'error'` listener registered.
752
773
  *
753
- * Node.js does not check whether Content-Length and the length of the
754
- * body which has been transmitted are equal or not.
774
+ * Set `Content-Length` header to limit the response body size.
775
+ * If `response.strictContentLength` is set to `true`, mismatching the`Content-Length` header value will result in an `Error` being thrown,
776
+ * identified by `code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.
777
+ *
778
+ * `Content-Length` value should be in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes.
755
779
  * @since v0.1.17
756
780
  */
757
781
  class ClientRequest extends OutgoingMessage {
@@ -778,7 +802,7 @@ declare module 'http' {
778
802
  * may run into a 'ECONNRESET' error.
779
803
  *
780
804
  * ```js
781
- * const http = require('http');
805
+ * const http = require('node:http');
782
806
  *
783
807
  * // Server has a 5 seconds keep-alive timeout by default
784
808
  * http
@@ -802,7 +826,7 @@ declare module 'http' {
802
826
  * automatic error retry base on it.
803
827
  *
804
828
  * ```js
805
- * const http = require('http');
829
+ * const http = require('node:http');
806
830
  * const agent = new http.Agent({ keepAlive: true });
807
831
  *
808
832
  * function retriableRequest() {
@@ -881,19 +905,13 @@ declare module 'http' {
881
905
  * @deprecated
882
906
  */
883
907
  addListener(event: 'abort', listener: () => void): this;
884
- addListener(
885
- event: 'connect',
886
- listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
887
- ): this;
908
+ addListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
888
909
  addListener(event: 'continue', listener: () => void): this;
889
910
  addListener(event: 'information', listener: (info: InformationEvent) => void): this;
890
911
  addListener(event: 'response', listener: (response: IncomingMessage) => void): this;
891
912
  addListener(event: 'socket', listener: (socket: Socket) => void): this;
892
913
  addListener(event: 'timeout', listener: () => void): this;
893
- addListener(
894
- event: 'upgrade',
895
- listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
896
- ): this;
914
+ addListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
897
915
  addListener(event: 'close', listener: () => void): this;
898
916
  addListener(event: 'drain', listener: () => void): this;
899
917
  addListener(event: 'error', listener: (err: Error) => void): this;
@@ -941,19 +959,13 @@ declare module 'http' {
941
959
  * @deprecated
942
960
  */
943
961
  prependListener(event: 'abort', listener: () => void): this;
944
- prependListener(
945
- event: 'connect',
946
- listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
947
- ): this;
962
+ prependListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
948
963
  prependListener(event: 'continue', listener: () => void): this;
949
964
  prependListener(event: 'information', listener: (info: InformationEvent) => void): this;
950
965
  prependListener(event: 'response', listener: (response: IncomingMessage) => void): this;
951
966
  prependListener(event: 'socket', listener: (socket: Socket) => void): this;
952
967
  prependListener(event: 'timeout', listener: () => void): this;
953
- prependListener(
954
- event: 'upgrade',
955
- listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
956
- ): this;
968
+ prependListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
957
969
  prependListener(event: 'close', listener: () => void): this;
958
970
  prependListener(event: 'drain', listener: () => void): this;
959
971
  prependListener(event: 'error', listener: (err: Error) => void): this;
@@ -965,19 +977,13 @@ declare module 'http' {
965
977
  * @deprecated
966
978
  */
967
979
  prependOnceListener(event: 'abort', listener: () => void): this;
968
- prependOnceListener(
969
- event: 'connect',
970
- listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
971
- ): this;
980
+ prependOnceListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
972
981
  prependOnceListener(event: 'continue', listener: () => void): this;
973
982
  prependOnceListener(event: 'information', listener: (info: InformationEvent) => void): this;
974
983
  prependOnceListener(event: 'response', listener: (response: IncomingMessage) => void): this;
975
984
  prependOnceListener(event: 'socket', listener: (socket: Socket) => void): this;
976
985
  prependOnceListener(event: 'timeout', listener: () => void): this;
977
- prependOnceListener(
978
- event: 'upgrade',
979
- listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
980
- ): this;
986
+ prependOnceListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
981
987
  prependOnceListener(event: 'close', listener: () => void): this;
982
988
  prependOnceListener(event: 'drain', listener: () => void): this;
983
989
  prependOnceListener(event: 'error', listener: (err: Error) => void): this;
@@ -989,7 +995,7 @@ declare module 'http' {
989
995
  /**
990
996
  * An `IncomingMessage` object is created by {@link Server} or {@link ClientRequest} and passed as the first argument to the `'request'` and `'response'` event respectively. It may be used to
991
997
  * access response
992
- * status, headers and data.
998
+ * status, headers, and data.
993
999
  *
994
1000
  * Different from its `socket` value which is a subclass of `stream.Duplex`, the`IncomingMessage` itself extends `stream.Readable` and is created separately to
995
1001
  * parse and emit the incoming HTTP headers and payload, as the underlying socket
@@ -1027,7 +1033,7 @@ declare module 'http' {
1027
1033
  * const req = http.request({
1028
1034
  * host: '127.0.0.1',
1029
1035
  * port: 8080,
1030
- * method: 'POST'
1036
+ * method: 'POST',
1031
1037
  * }, (res) => {
1032
1038
  * res.resume();
1033
1039
  * res.on('end', () => {
@@ -1069,7 +1075,7 @@ declare module 'http' {
1069
1075
  * // { 'user-agent': 'curl/7.22.0',
1070
1076
  * // host: '127.0.0.1:8000',
1071
1077
  * // accept: '*' }
1072
- * console.log(request.getHeaders());
1078
+ * console.log(request.headers);
1073
1079
  * ```
1074
1080
  *
1075
1081
  * Duplicates in raw headers are handled in the following ways, depending on the
@@ -1077,12 +1083,30 @@ declare module 'http' {
1077
1083
  *
1078
1084
  * * Duplicates of `age`, `authorization`, `content-length`, `content-type`,`etag`, `expires`, `from`, `host`, `if-modified-since`, `if-unmodified-since`,`last-modified`, `location`,
1079
1085
  * `max-forwards`, `proxy-authorization`, `referer`,`retry-after`, `server`, or `user-agent` are discarded.
1086
+ * To allow duplicate values of the headers listed above to be joined,
1087
+ * use the option `joinDuplicateHeaders` in {@link request} and {@link createServer}. See RFC 9110 Section 5.3 for more
1088
+ * information.
1080
1089
  * * `set-cookie` is always an array. Duplicates are added to the array.
1081
- * * For duplicate `cookie` headers, the values are joined together with '; '.
1082
- * * For all other headers, the values are joined together with ', '.
1090
+ * * For duplicate `cookie` headers, the values are joined together with `; `.
1091
+ * * For all other headers, the values are joined together with `, `.
1083
1092
  * @since v0.1.5
1084
1093
  */
1085
1094
  headers: IncomingHttpHeaders;
1095
+ /**
1096
+ * Similar to `message.headers`, but there is no join logic and the values are
1097
+ * always arrays of strings, even for headers received just once.
1098
+ *
1099
+ * ```js
1100
+ * // Prints something like:
1101
+ * //
1102
+ * // { 'user-agent': ['curl/7.22.0'],
1103
+ * // host: ['127.0.0.1:8000'],
1104
+ * // accept: ['*'] }
1105
+ * console.log(request.headersDistinct);
1106
+ * ```
1107
+ * @since v18.3.0, v16.17.0
1108
+ */
1109
+ headersDistinct: NodeJS.Dict<string[]>;
1086
1110
  /**
1087
1111
  * The raw request/response headers list exactly as they were received.
1088
1112
  *
@@ -1113,6 +1137,13 @@ declare module 'http' {
1113
1137
  * @since v0.3.0
1114
1138
  */
1115
1139
  trailers: NodeJS.Dict<string>;
1140
+ /**
1141
+ * Similar to `message.trailers`, but there is no join logic and the values are
1142
+ * always arrays of strings, even for headers received just once.
1143
+ * Only populated at the `'end'` event.
1144
+ * @since v18.3.0, v16.17.0
1145
+ */
1146
+ trailersDistinct: NodeJS.Dict<string[]>;
1116
1147
  /**
1117
1148
  * The raw request/response trailer keys and values exactly as they were
1118
1149
  * received. Only populated at the `'end'` event.
@@ -1145,14 +1176,14 @@ declare module 'http' {
1145
1176
  * To parse the URL into its parts:
1146
1177
  *
1147
1178
  * ```js
1148
- * new URL(request.url, `http://${request.getHeaders().host}`);
1179
+ * new URL(request.url, `http://${request.headers.host}`);
1149
1180
  * ```
1150
1181
  *
1151
- * When `request.url` is `'/status?name=ryan'` and`request.getHeaders().host` is `'localhost:3000'`:
1182
+ * When `request.url` is `'/status?name=ryan'` and `request.headers.host` is`'localhost:3000'`:
1152
1183
  *
1153
1184
  * ```console
1154
1185
  * $ node
1155
- * > new URL(request.url, `http://${request.getHeaders().host}`)
1186
+ * > new URL(request.url, `http://${request.headers.host}`)
1156
1187
  * URL {
1157
1188
  * href: 'http://localhost:3000/status?name=ryan',
1158
1189
  * origin: 'http://localhost:3000',
@@ -1272,7 +1303,7 @@ declare module 'http' {
1272
1303
  * hostname: 'localhost',
1273
1304
  * port: 80,
1274
1305
  * path: '/',
1275
- * agent: false // Create a new agent just for this one request
1306
+ * agent: false, // Create a new agent just for this one request
1276
1307
  * }, (res) => {
1277
1308
  * // Do stuff with response
1278
1309
  * });
@@ -1377,10 +1408,10 @@ declare module 'http' {
1377
1408
  * upload a file with a POST request, then write to the `ClientRequest` object.
1378
1409
  *
1379
1410
  * ```js
1380
- * const http = require('http');
1411
+ * const http = require('node:http');
1381
1412
  *
1382
1413
  * const postData = JSON.stringify({
1383
- * 'msg': 'Hello World!'
1414
+ * 'msg': 'Hello World!',
1384
1415
  * });
1385
1416
  *
1386
1417
  * const options = {
@@ -1390,8 +1421,8 @@ declare module 'http' {
1390
1421
  * method: 'POST',
1391
1422
  * headers: {
1392
1423
  * 'Content-Type': 'application/json',
1393
- * 'Content-Length': Buffer.byteLength(postData)
1394
- * }
1424
+ * 'Content-Length': Buffer.byteLength(postData),
1425
+ * },
1395
1426
  * };
1396
1427
  *
1397
1428
  * const req = http.request(options, (res) => {
@@ -1478,7 +1509,7 @@ declare module 'http' {
1478
1509
  * * `'data'` any number of times, on the `res` object
1479
1510
  * * (connection closed here)
1480
1511
  * * `'aborted'` on the `res` object
1481
- * * `'error'` on the `res` object with an error with message`'Error: aborted'` and code `'ECONNRESET'`.
1512
+ * * `'error'` on the `res` object with an error with message`'Error: aborted'` and code `'ECONNRESET'`
1482
1513
  * * `'close'`
1483
1514
  * * `'close'` on the `res` object
1484
1515
  *
@@ -1486,7 +1517,7 @@ declare module 'http' {
1486
1517
  * events will be emitted in the following order:
1487
1518
  *
1488
1519
  * * (`req.destroy()` called here)
1489
- * * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`
1520
+ * * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`, or the error with which `req.destroy()` was called
1490
1521
  * * `'close'`
1491
1522
  *
1492
1523
  * If `req.destroy()` is called before the connection succeeds, the following
@@ -1494,7 +1525,7 @@ declare module 'http' {
1494
1525
  *
1495
1526
  * * `'socket'`
1496
1527
  * * (`req.destroy()` called here)
1497
- * * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`
1528
+ * * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`, or the error with which `req.destroy()` was called
1498
1529
  * * `'close'`
1499
1530
  *
1500
1531
  * If `req.destroy()` is called after the response is received, the following
@@ -1505,7 +1536,7 @@ declare module 'http' {
1505
1536
  * * `'data'` any number of times, on the `res` object
1506
1537
  * * (`req.destroy()` called here)
1507
1538
  * * `'aborted'` on the `res` object
1508
- * * `'error'` on the `res` object with an error with message`'Error: aborted'` and code `'ECONNRESET'`.
1539
+ * * `'error'` on the `res` object with an error with message `'Error: aborted'`and code `'ECONNRESET'`, or the error with which `req.destroy()` was called
1509
1540
  * * `'close'`
1510
1541
  * * `'close'` on the `res` object
1511
1542
  *
@@ -1541,16 +1572,13 @@ declare module 'http' {
1541
1572
  * Setting the `timeout` option or using the `setTimeout()` function will
1542
1573
  * not abort the request or do anything besides add a `'timeout'` event.
1543
1574
  *
1544
- * Passing an `AbortSignal` and then calling `abort` on the corresponding`AbortController` will behave the same way as calling `.destroy()` on the
1545
- * request itself.
1575
+ * Passing an `AbortSignal` and then calling `abort()` on the corresponding`AbortController` will behave the same way as calling `.destroy()` on the
1576
+ * request. Specifically, the `'error'` event will be emitted with an error with
1577
+ * the message `'AbortError: The operation was aborted'`, the code `'ABORT_ERR'`and the `cause`, if one was provided.
1546
1578
  * @since v0.3.6
1547
1579
  */
1548
1580
  function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
1549
- function request(
1550
- url: string | URL,
1551
- options: RequestOptions,
1552
- callback?: (res: IncomingMessage) => void,
1553
- ): ClientRequest;
1581
+ function request(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
1554
1582
  /**
1555
1583
  * Since most requests are GET requests without bodies, Node.js provides this
1556
1584
  * 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
@@ -1602,7 +1630,7 @@ declare module 'http' {
1602
1630
  * const server = http.createServer((req, res) => {
1603
1631
  * res.writeHead(200, { 'Content-Type': 'application/json' });
1604
1632
  * res.end(JSON.stringify({
1605
- * data: 'Hello World!'
1633
+ * data: 'Hello World!',
1606
1634
  * }));
1607
1635
  * });
1608
1636
  *
@@ -1613,32 +1641,76 @@ declare module 'http' {
1613
1641
  */
1614
1642
  function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
1615
1643
  function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
1616
-
1617
1644
  /**
1618
- * Performs the low-level validations on the provided name that are done when `res.setHeader(name, value)` is called.
1619
- * Passing illegal value as name will result in a TypeError being thrown, identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
1620
- * @param name Header name
1645
+ * Performs the low-level validations on the provided `name` that are done when`res.setHeader(name, value)` is called.
1646
+ *
1647
+ * Passing illegal value as `name` will result in a `TypeError` being thrown,
1648
+ * identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
1649
+ *
1650
+ * It is not necessary to use this method before passing headers to an HTTP request
1651
+ * or response. The HTTP module will automatically validate such headers.
1652
+ * Examples:
1653
+ *
1654
+ * Example:
1655
+ *
1656
+ * ```js
1657
+ * const { validateHeaderName } = require('node:http');
1658
+ *
1659
+ * try {
1660
+ * validateHeaderName('');
1661
+ * } catch (err) {
1662
+ * console.error(err instanceof TypeError); // --> true
1663
+ * console.error(err.code); // --> 'ERR_INVALID_HTTP_TOKEN'
1664
+ * console.error(err.message); // --> 'Header name must be a valid HTTP token [""]'
1665
+ * }
1666
+ * ```
1621
1667
  * @since v14.3.0
1668
+ * @param [label='Header name'] Label for error message.
1622
1669
  */
1623
1670
  function validateHeaderName(name: string): void;
1624
1671
  /**
1625
- * Performs the low-level validations on the provided value that are done when `res.setHeader(name, value)` is called.
1626
- * Passing illegal value as value will result in a TypeError being thrown.
1627
- * - Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
1628
- * - Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
1672
+ * Performs the low-level validations on the provided `value` that are done when`res.setHeader(name, value)` is called.
1673
+ *
1674
+ * Passing illegal value as `value` will result in a `TypeError` being thrown.
1675
+ *
1676
+ * * Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
1677
+ * * Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
1678
+ *
1679
+ * It is not necessary to use this method before passing headers to an HTTP request
1680
+ * or response. The HTTP module will automatically validate such headers.
1681
+ *
1682
+ * Examples:
1683
+ *
1684
+ * ```js
1685
+ * const { validateHeaderValue } = require('node:http');
1686
+ *
1687
+ * try {
1688
+ * validateHeaderValue('x-my-header', undefined);
1689
+ * } catch (err) {
1690
+ * console.error(err instanceof TypeError); // --> true
1691
+ * console.error(err.code === 'ERR_HTTP_INVALID_HEADER_VALUE'); // --> true
1692
+ * console.error(err.message); // --> 'Invalid value "undefined" for header "x-my-header"'
1693
+ * }
1694
+ *
1695
+ * try {
1696
+ * validateHeaderValue('x-my-header', 'oʊmɪɡə');
1697
+ * } catch (err) {
1698
+ * console.error(err instanceof TypeError); // --> true
1699
+ * console.error(err.code === 'ERR_INVALID_CHAR'); // --> true
1700
+ * console.error(err.message); // --> 'Invalid character in header content ["x-my-header"]'
1701
+ * }
1702
+ * ```
1703
+ * @since v14.3.0
1629
1704
  * @param name Header name
1630
1705
  * @param value Header value
1631
- * @since v14.3.0
1632
1706
  */
1633
1707
  function validateHeaderValue(name: string, value: string): void;
1634
-
1635
1708
  /**
1636
- * Set the maximum number of idle HTTP parsers. Default: 1000.
1637
- * @param count
1709
+ * Set the maximum number of idle HTTP parsers.
1638
1710
  * @since v18.8.0, v16.18.0
1711
+ * @param [max=1000]
1639
1712
  */
1640
- function setMaxIdleHTTPParsers(count: number): void;
1641
-
1713
+ function setMaxIdleHTTPParsers(max: number): void;
1642
1714
  let globalAgent: Agent;
1643
1715
  /**
1644
1716
  * Read-only property specifying the maximum allowed size of HTTP headers in bytes.