@types/node 18.16.5 → 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.
- node v18.16/README.md → node/README.md +2 -2
- node v18.16/ts4.8/assert.d.ts → node/assert.d.ts +71 -75
- node v18.16/async_hooks.d.ts → node/async_hooks.d.ts +62 -42
- node v18.16/buffer.d.ts → node/buffer.d.ts +127 -99
- node v18.16/child_process.d.ts → node/child_process.d.ts +50 -54
- node v18.16/ts4.8/cluster.d.ts → node/cluster.d.ts +12 -12
- node v18.16/ts4.8/console.d.ts → node/console.d.ts +5 -5
- node v18.16/crypto.d.ts → node/crypto.d.ts +209 -220
- node v18.16/ts4.8/dgram.d.ts → node/dgram.d.ts +15 -15
- node v18.16/diagnostics_channel.d.ts → node/diagnostics_channel.d.ts +25 -26
- node v18.16/dns/promises.d.ts → node/dns/promises.d.ts +6 -6
- node v18.16/ts4.8/dns.d.ts → node/dns.d.ts +24 -16
- node v18.16/domain.d.ts → node/domain.d.ts +4 -4
- node v18.16/events.d.ts → node/events.d.ts +60 -60
- node v18.16/fs/promises.d.ts → node/fs/promises.d.ts +78 -48
- node v18.16/fs.d.ts → node/fs.d.ts +117 -81
- node v18.16/http.d.ts → node/http.d.ts +155 -145
- node v18.16/ts4.8/http2.d.ts → node/http2.d.ts +42 -46
- node v18.16/https.d.ts → node/https.d.ts +52 -153
- node v18.16/index.d.ts → node/index.d.ts +1 -1
- node v18.16/ts4.8/inspector.d.ts → node/inspector.d.ts +10 -3
- node v18.16/ts4.8/module.d.ts → node/module.d.ts +5 -4
- node v18.16/ts4.8/net.d.ts → node/net.d.ts +24 -21
- node v18.16/ts4.8/os.d.ts → node/os.d.ts +22 -18
- node v18.16/package.json → node/package.json +2 -2
- node v18.16/ts4.8/path.d.ts → node/path.d.ts +4 -4
- node v18.16/perf_hooks.d.ts → node/perf_hooks.d.ts +28 -15
- node v18.16/process.d.ts → node/process.d.ts +43 -46
- node v18.16/ts4.8/punycode.d.ts → node/punycode.d.ts +1 -1
- node v18.16/ts4.8/querystring.d.ts → node/querystring.d.ts +5 -5
- node v18.16/readline/promises.d.ts → node/readline/promises.d.ts +6 -4
- node v18.16/readline.d.ts → node/readline.d.ts +15 -15
- node v18.16/repl.d.ts → node/repl.d.ts +9 -9
- node v18.16/stream/consumers.d.ts → node/stream/consumers.d.ts +1 -1
- node v18.16/stream.d.ts → node/stream.d.ts +88 -136
- node v18.16/ts4.8/string_decoder.d.ts → node/string_decoder.d.ts +6 -6
- node v18.16/ts4.8/test.d.ts → node/test.d.ts +423 -186
- node v18.16/timers/promises.d.ts → node/timers/promises.d.ts +3 -3
- node v18.16/timers.d.ts → node/timers.d.ts +2 -2
- node v18.16/ts4.8/tls.d.ts → node/tls.d.ts +24 -16
- node v18.16/ts4.8/trace_events.d.ts → node/trace_events.d.ts +20 -9
- node v18.16/assert.d.ts → node/ts4.8/assert.d.ts +71 -75
- node v18.16/ts4.8/async_hooks.d.ts → node/ts4.8/async_hooks.d.ts +62 -42
- node v18.16/ts4.8/buffer.d.ts → node/ts4.8/buffer.d.ts +127 -99
- node v18.16/ts4.8/child_process.d.ts → node/ts4.8/child_process.d.ts +50 -54
- node v18.16/cluster.d.ts → node/ts4.8/cluster.d.ts +12 -12
- node v18.16/console.d.ts → node/ts4.8/console.d.ts +5 -5
- node v18.16/ts4.8/crypto.d.ts → node/ts4.8/crypto.d.ts +209 -220
- node v18.16/dgram.d.ts → node/ts4.8/dgram.d.ts +15 -15
- node v18.16/ts4.8/diagnostics_channel.d.ts → node/ts4.8/diagnostics_channel.d.ts +25 -26
- node v18.16/ts4.8/dns/promises.d.ts → node/ts4.8/dns/promises.d.ts +6 -6
- node v18.16/dns.d.ts → node/ts4.8/dns.d.ts +24 -16
- node v18.16/ts4.8/domain.d.ts → node/ts4.8/domain.d.ts +4 -4
- node v18.16/ts4.8/events.d.ts → node/ts4.8/events.d.ts +60 -60
- node v18.16/ts4.8/fs/promises.d.ts → node/ts4.8/fs/promises.d.ts +96 -45
- node v18.16/ts4.8/fs.d.ts → node/ts4.8/fs.d.ts +203 -67
- node v18.16/ts4.8/globals.d.ts → node/ts4.8/globals.d.ts +29 -28
- node v18.16/ts4.8/http.d.ts → node/ts4.8/http.d.ts +198 -126
- node v18.16/http2.d.ts → node/ts4.8/http2.d.ts +42 -46
- node v18.16/ts4.8/https.d.ts → node/ts4.8/https.d.ts +52 -153
- node v18.16/inspector.d.ts → node/ts4.8/inspector.d.ts +10 -3
- node v18.16/module.d.ts → node/ts4.8/module.d.ts +5 -4
- node v18.16/net.d.ts → node/ts4.8/net.d.ts +21 -18
- node v18.16/os.d.ts → node/ts4.8/os.d.ts +22 -18
- node v18.16/path.d.ts → node/ts4.8/path.d.ts +4 -4
- node v18.16/ts4.8/perf_hooks.d.ts → node/ts4.8/perf_hooks.d.ts +28 -15
- node v18.16/ts4.8/process.d.ts → node/ts4.8/process.d.ts +43 -46
- node v18.16/punycode.d.ts → node/ts4.8/punycode.d.ts +1 -1
- node v18.16/querystring.d.ts → node/ts4.8/querystring.d.ts +5 -5
- node v18.16/ts4.8/readline/promises.d.ts → node/ts4.8/readline/promises.d.ts +6 -4
- node v18.16/ts4.8/readline.d.ts → node/ts4.8/readline.d.ts +15 -15
- node v18.16/ts4.8/repl.d.ts → node/ts4.8/repl.d.ts +9 -9
- node v18.16/ts4.8/stream/consumers.d.ts → node/ts4.8/stream/consumers.d.ts +1 -1
- node v18.16/ts4.8/stream.d.ts → node/ts4.8/stream.d.ts +91 -139
- node v18.16/string_decoder.d.ts → node/ts4.8/string_decoder.d.ts +6 -6
- node v18.16/test.d.ts → node/ts4.8/test.d.ts +423 -186
- node v18.16/ts4.8/timers/promises.d.ts → node/ts4.8/timers/promises.d.ts +3 -3
- node v18.16/ts4.8/timers.d.ts → node/ts4.8/timers.d.ts +9 -2
- node v18.16/tls.d.ts → node/ts4.8/tls.d.ts +24 -16
- node v18.16/trace_events.d.ts → node/ts4.8/trace_events.d.ts +20 -9
- node v18.16/tty.d.ts → node/ts4.8/tty.d.ts +4 -5
- node v18.16/ts4.8/url.d.ts → node/ts4.8/url.d.ts +26 -36
- node v18.16/ts4.8/util.d.ts → node/ts4.8/util.d.ts +143 -116
- node v18.16/ts4.8/v8.d.ts → node/ts4.8/v8.d.ts +110 -16
- node v18.16/vm.d.ts → node/ts4.8/vm.d.ts +292 -42
- node v18.16/wasi.d.ts → node/ts4.8/wasi.d.ts +13 -19
- node v18.16/ts4.8/worker_threads.d.ts → node/ts4.8/worker_threads.d.ts +32 -34
- node v18.16/zlib.d.ts → node/ts4.8/zlib.d.ts +11 -11
- node v18.16/ts4.8/tty.d.ts → node/tty.d.ts +4 -5
- node v18.16/url.d.ts → node/url.d.ts +26 -36
- node v18.16/util.d.ts → node/util.d.ts +146 -111
- node v18.16/v8.d.ts → node/v8.d.ts +110 -16
- node v18.16/ts4.8/vm.d.ts → node/vm.d.ts +292 -42
- node v18.16/ts4.8/wasi.d.ts → node/wasi.d.ts +13 -19
- node v18.16/worker_threads.d.ts → node/worker_threads.d.ts +32 -34
- node v18.16/ts4.8/zlib.d.ts → node/zlib.d.ts +11 -11
- {node v18.16 → node}/LICENSE +0 -0
- {node v18.16 → node}/assert/strict.d.ts +0 -0
- {node v18.16 → node}/constants.d.ts +0 -0
- {node v18.16 → node}/dom-events.d.ts +0 -0
- {node v18.16 → node}/globals.d.ts +0 -0
- {node v18.16 → node}/globals.global.d.ts +0 -0
- {node v18.16 → node}/stream/promises.d.ts +0 -0
- {node v18.16 → node}/stream/web.d.ts +0 -0
- {node v18.16 → node}/ts4.8/assert/strict.d.ts +0 -0
- {node v18.16 → node}/ts4.8/constants.d.ts +0 -0
- {node v18.16 → node}/ts4.8/dom-events.d.ts +0 -0
- {node v18.16 → node}/ts4.8/globals.global.d.ts +0 -0
- {node v18.16 → node}/ts4.8/index.d.ts +0 -0
- {node v18.16 → node}/ts4.8/stream/promises.d.ts +0 -0
- {node v18.16 → node}/ts4.8/stream/web.d.ts +0 -0
|
@@ -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,13 +37,13 @@
|
|
|
37
37
|
* 'Host', 'example.com',
|
|
38
38
|
* 'accepT', '*' ]
|
|
39
39
|
* ```
|
|
40
|
-
* @see [source](https://github.com/nodejs/node/blob/
|
|
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';
|
|
44
44
|
import { URL } from 'node:url';
|
|
45
|
-
import { EventEmitter } from 'node:events';
|
|
46
45
|
import { LookupOptions } from 'node:dns';
|
|
46
|
+
import { EventEmitter } from 'node:events';
|
|
47
47
|
import { TcpSocketConnectOpts, Socket, Server as NetServer, LookupFunction } from 'node:net';
|
|
48
48
|
// incoming headers will never contain number
|
|
49
49
|
interface IncomingHttpHeaders extends NodeJS.Dict<string | string[]> {
|
|
@@ -185,6 +185,13 @@ declare module 'http' {
|
|
|
185
185
|
* @default 30000
|
|
186
186
|
*/
|
|
187
187
|
connectionsCheckingInterval?: number | undefined;
|
|
188
|
+
/**
|
|
189
|
+
* Optionally overrides all `socket`s' `readableHighWaterMark` and `writableHighWaterMark`.
|
|
190
|
+
* This affects `highWaterMark` property of both `IncomingMessage` and `ServerResponse`.
|
|
191
|
+
* Default: @see stream.getDefaultHighWaterMark().
|
|
192
|
+
* @since v20.1.0
|
|
193
|
+
*/
|
|
194
|
+
highWaterMark?: number | undefined;
|
|
188
195
|
/**
|
|
189
196
|
* Use an insecure HTTP parser that accepts invalid HTTP headers when `true`.
|
|
190
197
|
* Using the insecure parser should be avoided.
|
|
@@ -330,7 +337,8 @@ declare module 'http' {
|
|
|
330
337
|
*/
|
|
331
338
|
closeAllConnections(): void;
|
|
332
339
|
/**
|
|
333
|
-
* Closes all connections connected to this server which are not sending a request
|
|
340
|
+
* Closes all connections connected to this server which are not sending a request
|
|
341
|
+
* or waiting for a response.
|
|
334
342
|
* @since v18.2.0
|
|
335
343
|
*/
|
|
336
344
|
closeIdleConnections(): void;
|
|
@@ -342,16 +350,10 @@ declare module 'http' {
|
|
|
342
350
|
addListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
|
|
343
351
|
addListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
|
|
344
352
|
addListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
|
|
345
|
-
addListener(
|
|
346
|
-
event: 'connect',
|
|
347
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
348
|
-
): this;
|
|
353
|
+
addListener(event: 'connect', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
349
354
|
addListener(event: 'dropRequest', listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
|
|
350
355
|
addListener(event: 'request', listener: RequestListener<Request, Response>): this;
|
|
351
|
-
addListener(
|
|
352
|
-
event: 'upgrade',
|
|
353
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
354
|
-
): this;
|
|
356
|
+
addListener(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
355
357
|
emit(event: string, ...args: any[]): boolean;
|
|
356
358
|
emit(event: 'close'): boolean;
|
|
357
359
|
emit(event: 'connection', socket: Socket): boolean;
|
|
@@ -396,16 +398,10 @@ declare module 'http' {
|
|
|
396
398
|
once(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
|
|
397
399
|
once(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
|
|
398
400
|
once(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
|
|
399
|
-
once(
|
|
400
|
-
event: 'connect',
|
|
401
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
402
|
-
): this;
|
|
401
|
+
once(event: 'connect', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
403
402
|
once(event: 'dropRequest', listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
|
|
404
403
|
once(event: 'request', listener: RequestListener<Request, Response>): this;
|
|
405
|
-
once(
|
|
406
|
-
event: 'upgrade',
|
|
407
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
408
|
-
): this;
|
|
404
|
+
once(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
409
405
|
prependListener(event: string, listener: (...args: any[]) => void): this;
|
|
410
406
|
prependListener(event: 'close', listener: () => void): this;
|
|
411
407
|
prependListener(event: 'connection', listener: (socket: Socket) => void): this;
|
|
@@ -414,19 +410,10 @@ declare module 'http' {
|
|
|
414
410
|
prependListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
|
|
415
411
|
prependListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
|
|
416
412
|
prependListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
|
|
417
|
-
prependListener(
|
|
418
|
-
|
|
419
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
420
|
-
): this;
|
|
421
|
-
prependListener(
|
|
422
|
-
event: 'dropRequest',
|
|
423
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex) => void,
|
|
424
|
-
): this;
|
|
413
|
+
prependListener(event: 'connect', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
414
|
+
prependListener(event: 'dropRequest', listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
|
|
425
415
|
prependListener(event: 'request', listener: RequestListener<Request, Response>): this;
|
|
426
|
-
prependListener(
|
|
427
|
-
event: 'upgrade',
|
|
428
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
429
|
-
): this;
|
|
416
|
+
prependListener(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
430
417
|
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
|
431
418
|
prependOnceListener(event: 'close', listener: () => void): this;
|
|
432
419
|
prependOnceListener(event: 'connection', listener: (socket: Socket) => void): this;
|
|
@@ -435,23 +422,14 @@ declare module 'http' {
|
|
|
435
422
|
prependOnceListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
|
|
436
423
|
prependOnceListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
|
|
437
424
|
prependOnceListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
|
|
438
|
-
prependOnceListener(
|
|
439
|
-
|
|
440
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
441
|
-
): this;
|
|
442
|
-
prependOnceListener(
|
|
443
|
-
event: 'dropRequest',
|
|
444
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex) => void,
|
|
445
|
-
): this;
|
|
425
|
+
prependOnceListener(event: 'connect', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
426
|
+
prependOnceListener(event: 'dropRequest', listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
|
|
446
427
|
prependOnceListener(event: 'request', listener: RequestListener<Request, Response>): this;
|
|
447
|
-
prependOnceListener(
|
|
448
|
-
event: 'upgrade',
|
|
449
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
450
|
-
): this;
|
|
428
|
+
prependOnceListener(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
451
429
|
}
|
|
452
430
|
/**
|
|
453
|
-
* This class serves as the parent class of {@link ClientRequest} and {@link ServerResponse}. It is an abstract
|
|
454
|
-
* the perspective of the participants of HTTP transaction.
|
|
431
|
+
* This class serves as the parent class of {@link ClientRequest} and {@link ServerResponse}. It is an abstract outgoing message from
|
|
432
|
+
* the perspective of the participants of an HTTP transaction.
|
|
455
433
|
* @since v0.1.17
|
|
456
434
|
*/
|
|
457
435
|
class OutgoingMessage<Request extends IncomingMessage = IncomingMessage> extends stream.Writable {
|
|
@@ -470,7 +448,7 @@ declare module 'http' {
|
|
|
470
448
|
*/
|
|
471
449
|
readonly headersSent: boolean;
|
|
472
450
|
/**
|
|
473
|
-
*
|
|
451
|
+
* Alias of `outgoingMessage.socket`.
|
|
474
452
|
* @since v0.3.0
|
|
475
453
|
* @deprecated Since v15.12.0,v14.17.1 - Use `socket` instead.
|
|
476
454
|
*/
|
|
@@ -491,8 +469,9 @@ declare module 'http' {
|
|
|
491
469
|
*/
|
|
492
470
|
setTimeout(msecs: number, callback?: () => void): this;
|
|
493
471
|
/**
|
|
494
|
-
* Sets a single header value
|
|
495
|
-
*
|
|
472
|
+
* Sets a single header value. If the header already exists in the to-be-sent
|
|
473
|
+
* headers, its value will be replaced. Use an array of strings to send multiple
|
|
474
|
+
* headers with the same name.
|
|
496
475
|
* @since v0.4.0
|
|
497
476
|
* @param name Header name
|
|
498
477
|
* @param value Header value
|
|
@@ -501,20 +480,22 @@ declare module 'http' {
|
|
|
501
480
|
/**
|
|
502
481
|
* Append a single header value for the header object.
|
|
503
482
|
*
|
|
504
|
-
* If the value is an array, this is equivalent of calling this method multiple
|
|
483
|
+
* If the value is an array, this is equivalent of calling this method multiple
|
|
484
|
+
* times.
|
|
505
485
|
*
|
|
506
486
|
* If there were no previous value for the header, this is equivalent of calling `outgoingMessage.setHeader(name, value)`.
|
|
507
487
|
*
|
|
508
|
-
* Depending of the value of `options.uniqueHeaders` when the client request or the
|
|
509
|
-
* this will end up in the header being sent multiple times or
|
|
488
|
+
* Depending of the value of `options.uniqueHeaders` when the client request or the
|
|
489
|
+
* server were created, this will end up in the header being sent multiple times or
|
|
490
|
+
* a single time with values joined using `; `.
|
|
510
491
|
* @since v18.3.0, v16.17.0
|
|
511
492
|
* @param name Header name
|
|
512
493
|
* @param value Header value
|
|
513
494
|
*/
|
|
514
495
|
appendHeader(name: string, value: string | ReadonlyArray<string>): this;
|
|
515
496
|
/**
|
|
516
|
-
* Gets the value of HTTP header with the given name. If
|
|
517
|
-
*
|
|
497
|
+
* Gets the value of the HTTP header with the given name. If that header is not
|
|
498
|
+
* set, the returned value will be `undefined`.
|
|
518
499
|
* @since v0.4.0
|
|
519
500
|
* @param name Name of header
|
|
520
501
|
*/
|
|
@@ -527,8 +508,8 @@ declare module 'http' {
|
|
|
527
508
|
* values. All header names are lowercase.
|
|
528
509
|
*
|
|
529
510
|
* The object returned by the `outgoingMessage.getHeaders()` method does
|
|
530
|
-
* not prototypically inherit from the JavaScript Object
|
|
531
|
-
* typical Object methods such as `obj.toString()`, `obj.hasOwnProperty()`,
|
|
511
|
+
* not prototypically inherit from the JavaScript `Object`. This means that
|
|
512
|
+
* typical `Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`,
|
|
532
513
|
* and others are not defined and will not work.
|
|
533
514
|
*
|
|
534
515
|
* ```js
|
|
@@ -542,8 +523,8 @@ declare module 'http' {
|
|
|
542
523
|
*/
|
|
543
524
|
getHeaders(): OutgoingHttpHeaders;
|
|
544
525
|
/**
|
|
545
|
-
* Returns an array
|
|
546
|
-
* names are lowercase.
|
|
526
|
+
* Returns an array containing the unique names of the current outgoing headers.
|
|
527
|
+
* All names are lowercase.
|
|
547
528
|
* @since v7.7.0
|
|
548
529
|
*/
|
|
549
530
|
getHeaderNames(): string[];
|
|
@@ -570,11 +551,11 @@ declare module 'http' {
|
|
|
570
551
|
/**
|
|
571
552
|
* Adds HTTP trailers (headers but at the end of the message) to the message.
|
|
572
553
|
*
|
|
573
|
-
* Trailers
|
|
574
|
-
* the
|
|
554
|
+
* Trailers will **only** be emitted if the message is chunked encoded. If not,
|
|
555
|
+
* the trailers will be silently discarded.
|
|
575
556
|
*
|
|
576
557
|
* HTTP requires the `Trailer` header to be sent to emit trailers,
|
|
577
|
-
* with a list of header
|
|
558
|
+
* with a list of header field names in its value, e.g.
|
|
578
559
|
*
|
|
579
560
|
* ```js
|
|
580
561
|
* message.writeHead(200, { 'Content-Type': 'text/plain',
|
|
@@ -590,7 +571,7 @@ declare module 'http' {
|
|
|
590
571
|
*/
|
|
591
572
|
addTrailers(headers: OutgoingHttpHeaders | ReadonlyArray<[string, string]>): void;
|
|
592
573
|
/**
|
|
593
|
-
*
|
|
574
|
+
* Flushes the message headers.
|
|
594
575
|
*
|
|
595
576
|
* For efficiency reason, Node.js normally buffers the message headers
|
|
596
577
|
* until `outgoingMessage.end()` is called or the first chunk of message data
|
|
@@ -598,7 +579,7 @@ declare module 'http' {
|
|
|
598
579
|
* packet.
|
|
599
580
|
*
|
|
600
581
|
* It is usually desired (it saves a TCP round-trip), but not when the first
|
|
601
|
-
* data is not sent until possibly much later. `outgoingMessage.flushHeaders()`bypasses the optimization and kickstarts the
|
|
582
|
+
* data is not sent until possibly much later. `outgoingMessage.flushHeaders()`bypasses the optimization and kickstarts the message.
|
|
602
583
|
* @since v1.6.0
|
|
603
584
|
*/
|
|
604
585
|
flushHeaders(): void;
|
|
@@ -639,10 +620,9 @@ declare module 'http' {
|
|
|
639
620
|
*/
|
|
640
621
|
statusMessage: string;
|
|
641
622
|
/**
|
|
642
|
-
* If set to `true`, Node.js will check whether the `Content-Length`
|
|
643
|
-
*
|
|
644
|
-
*
|
|
645
|
-
* identified by `code: 'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.
|
|
623
|
+
* If set to `true`, Node.js will check whether the `Content-Length`header value and the size of the body, in bytes, are equal.
|
|
624
|
+
* Mismatching the `Content-Length` header value will result
|
|
625
|
+
* in an `Error` being thrown, identified by `code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.
|
|
646
626
|
* @since v18.10.0, v16.18.0
|
|
647
627
|
*/
|
|
648
628
|
strictContentLength: boolean;
|
|
@@ -662,7 +642,7 @@ declare module 'http' {
|
|
|
662
642
|
* early hints message. The optional `callback` argument will be called when
|
|
663
643
|
* the response message has been written.
|
|
664
644
|
*
|
|
665
|
-
* Example
|
|
645
|
+
* **Example**
|
|
666
646
|
*
|
|
667
647
|
* ```js
|
|
668
648
|
* const earlyHintsLink = '</styles.css>; rel=preload; as=style';
|
|
@@ -676,15 +656,14 @@ declare module 'http' {
|
|
|
676
656
|
* ];
|
|
677
657
|
* response.writeEarlyHints({
|
|
678
658
|
* 'link': earlyHintsLinks,
|
|
679
|
-
* 'x-trace-id': 'id for diagnostics'
|
|
659
|
+
* 'x-trace-id': 'id for diagnostics',
|
|
680
660
|
* });
|
|
681
661
|
*
|
|
682
662
|
* const earlyHintsCallback = () => console.log('early hints message sent');
|
|
683
663
|
* response.writeEarlyHints({
|
|
684
|
-
* 'link': earlyHintsLinks
|
|
664
|
+
* 'link': earlyHintsLinks,
|
|
685
665
|
* }, earlyHintsCallback);
|
|
686
666
|
* ```
|
|
687
|
-
*
|
|
688
667
|
* @since v18.11.0
|
|
689
668
|
* @param hints An object containing the values of headers
|
|
690
669
|
* @param callback Will be called when the response message has been written
|
|
@@ -708,7 +687,7 @@ declare module 'http' {
|
|
|
708
687
|
* response
|
|
709
688
|
* .writeHead(200, {
|
|
710
689
|
* 'Content-Length': Buffer.byteLength(body),
|
|
711
|
-
* 'Content-Type': 'text/plain'
|
|
690
|
+
* 'Content-Type': 'text/plain',
|
|
712
691
|
* })
|
|
713
692
|
* .end(body);
|
|
714
693
|
* ```
|
|
@@ -739,12 +718,12 @@ declare module 'http' {
|
|
|
739
718
|
* });
|
|
740
719
|
* ```
|
|
741
720
|
*
|
|
742
|
-
* `Content-Length` is
|
|
743
|
-
*
|
|
721
|
+
* `Content-Length` is read in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes. Node.js
|
|
722
|
+
* will check whether `Content-Length` and the length of the body which has
|
|
744
723
|
* been transmitted are equal or not.
|
|
745
724
|
*
|
|
746
725
|
* Attempting to set a header field name or value that contains invalid characters
|
|
747
|
-
* will result in a `
|
|
726
|
+
* will result in a \[`Error`\]\[\] being thrown.
|
|
748
727
|
* @since v0.1.30
|
|
749
728
|
*/
|
|
750
729
|
writeHead(
|
|
@@ -754,7 +733,7 @@ declare module 'http' {
|
|
|
754
733
|
): this;
|
|
755
734
|
writeHead(statusCode: number, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[]): this;
|
|
756
735
|
/**
|
|
757
|
-
* Sends
|
|
736
|
+
* Sends a HTTP/1.1 102 Processing message to the client, indicating that
|
|
758
737
|
* the request body should be sent.
|
|
759
738
|
* @since v10.0.0
|
|
760
739
|
*/
|
|
@@ -793,8 +772,11 @@ declare module 'http' {
|
|
|
793
772
|
*
|
|
794
773
|
* For backward compatibility, `res` will only emit `'error'` if there is an`'error'` listener registered.
|
|
795
774
|
*
|
|
796
|
-
*
|
|
797
|
-
*
|
|
775
|
+
* Set `Content-Length` header to limit the response body size.
|
|
776
|
+
* If `response.strictContentLength` is set to `true`, mismatching the`Content-Length` header value will result in an `Error` being thrown,
|
|
777
|
+
* identified by `code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.
|
|
778
|
+
*
|
|
779
|
+
* `Content-Length` value should be in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes.
|
|
798
780
|
* @since v0.1.17
|
|
799
781
|
*/
|
|
800
782
|
class ClientRequest extends OutgoingMessage {
|
|
@@ -821,7 +803,7 @@ declare module 'http' {
|
|
|
821
803
|
* may run into a 'ECONNRESET' error.
|
|
822
804
|
*
|
|
823
805
|
* ```js
|
|
824
|
-
* const http = require('http');
|
|
806
|
+
* const http = require('node:http');
|
|
825
807
|
*
|
|
826
808
|
* // Server has a 5 seconds keep-alive timeout by default
|
|
827
809
|
* http
|
|
@@ -845,7 +827,7 @@ declare module 'http' {
|
|
|
845
827
|
* automatic error retry base on it.
|
|
846
828
|
*
|
|
847
829
|
* ```js
|
|
848
|
-
* const http = require('http');
|
|
830
|
+
* const http = require('node:http');
|
|
849
831
|
* const agent = new http.Agent({ keepAlive: true });
|
|
850
832
|
*
|
|
851
833
|
* function retriableRequest() {
|
|
@@ -924,19 +906,13 @@ declare module 'http' {
|
|
|
924
906
|
* @deprecated
|
|
925
907
|
*/
|
|
926
908
|
addListener(event: 'abort', listener: () => void): this;
|
|
927
|
-
addListener(
|
|
928
|
-
event: 'connect',
|
|
929
|
-
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
|
930
|
-
): this;
|
|
909
|
+
addListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
|
931
910
|
addListener(event: 'continue', listener: () => void): this;
|
|
932
911
|
addListener(event: 'information', listener: (info: InformationEvent) => void): this;
|
|
933
912
|
addListener(event: 'response', listener: (response: IncomingMessage) => void): this;
|
|
934
913
|
addListener(event: 'socket', listener: (socket: Socket) => void): this;
|
|
935
914
|
addListener(event: 'timeout', listener: () => void): this;
|
|
936
|
-
addListener(
|
|
937
|
-
event: 'upgrade',
|
|
938
|
-
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
|
939
|
-
): this;
|
|
915
|
+
addListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
|
940
916
|
addListener(event: 'close', listener: () => void): this;
|
|
941
917
|
addListener(event: 'drain', listener: () => void): this;
|
|
942
918
|
addListener(event: 'error', listener: (err: Error) => void): this;
|
|
@@ -984,19 +960,13 @@ declare module 'http' {
|
|
|
984
960
|
* @deprecated
|
|
985
961
|
*/
|
|
986
962
|
prependListener(event: 'abort', listener: () => void): this;
|
|
987
|
-
prependListener(
|
|
988
|
-
event: 'connect',
|
|
989
|
-
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
|
990
|
-
): this;
|
|
963
|
+
prependListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
|
991
964
|
prependListener(event: 'continue', listener: () => void): this;
|
|
992
965
|
prependListener(event: 'information', listener: (info: InformationEvent) => void): this;
|
|
993
966
|
prependListener(event: 'response', listener: (response: IncomingMessage) => void): this;
|
|
994
967
|
prependListener(event: 'socket', listener: (socket: Socket) => void): this;
|
|
995
968
|
prependListener(event: 'timeout', listener: () => void): this;
|
|
996
|
-
prependListener(
|
|
997
|
-
event: 'upgrade',
|
|
998
|
-
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
|
999
|
-
): this;
|
|
969
|
+
prependListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
|
1000
970
|
prependListener(event: 'close', listener: () => void): this;
|
|
1001
971
|
prependListener(event: 'drain', listener: () => void): this;
|
|
1002
972
|
prependListener(event: 'error', listener: (err: Error) => void): this;
|
|
@@ -1008,19 +978,13 @@ declare module 'http' {
|
|
|
1008
978
|
* @deprecated
|
|
1009
979
|
*/
|
|
1010
980
|
prependOnceListener(event: 'abort', listener: () => void): this;
|
|
1011
|
-
prependOnceListener(
|
|
1012
|
-
event: 'connect',
|
|
1013
|
-
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
|
1014
|
-
): this;
|
|
981
|
+
prependOnceListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
|
1015
982
|
prependOnceListener(event: 'continue', listener: () => void): this;
|
|
1016
983
|
prependOnceListener(event: 'information', listener: (info: InformationEvent) => void): this;
|
|
1017
984
|
prependOnceListener(event: 'response', listener: (response: IncomingMessage) => void): this;
|
|
1018
985
|
prependOnceListener(event: 'socket', listener: (socket: Socket) => void): this;
|
|
1019
986
|
prependOnceListener(event: 'timeout', listener: () => void): this;
|
|
1020
|
-
prependOnceListener(
|
|
1021
|
-
event: 'upgrade',
|
|
1022
|
-
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
|
1023
|
-
): this;
|
|
987
|
+
prependOnceListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
|
1024
988
|
prependOnceListener(event: 'close', listener: () => void): this;
|
|
1025
989
|
prependOnceListener(event: 'drain', listener: () => void): this;
|
|
1026
990
|
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
|
@@ -1032,7 +996,7 @@ declare module 'http' {
|
|
|
1032
996
|
/**
|
|
1033
997
|
* 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
|
|
1034
998
|
* access response
|
|
1035
|
-
* status, headers and data.
|
|
999
|
+
* status, headers, and data.
|
|
1036
1000
|
*
|
|
1037
1001
|
* Different from its `socket` value which is a subclass of `stream.Duplex`, the`IncomingMessage` itself extends `stream.Readable` and is created separately to
|
|
1038
1002
|
* parse and emit the incoming HTTP headers and payload, as the underlying socket
|
|
@@ -1070,7 +1034,7 @@ declare module 'http' {
|
|
|
1070
1034
|
* const req = http.request({
|
|
1071
1035
|
* host: '127.0.0.1',
|
|
1072
1036
|
* port: 8080,
|
|
1073
|
-
* method: 'POST'
|
|
1037
|
+
* method: 'POST',
|
|
1074
1038
|
* }, (res) => {
|
|
1075
1039
|
* res.resume();
|
|
1076
1040
|
* res.on('end', () => {
|
|
@@ -1112,7 +1076,7 @@ declare module 'http' {
|
|
|
1112
1076
|
* // { 'user-agent': 'curl/7.22.0',
|
|
1113
1077
|
* // host: '127.0.0.1:8000',
|
|
1114
1078
|
* // accept: '*' }
|
|
1115
|
-
* console.log(request.
|
|
1079
|
+
* console.log(request.headers);
|
|
1116
1080
|
* ```
|
|
1117
1081
|
*
|
|
1118
1082
|
* Duplicates in raw headers are handled in the following ways, depending on the
|
|
@@ -1120,14 +1084,18 @@ declare module 'http' {
|
|
|
1120
1084
|
*
|
|
1121
1085
|
* * Duplicates of `age`, `authorization`, `content-length`, `content-type`,`etag`, `expires`, `from`, `host`, `if-modified-since`, `if-unmodified-since`,`last-modified`, `location`,
|
|
1122
1086
|
* `max-forwards`, `proxy-authorization`, `referer`,`retry-after`, `server`, or `user-agent` are discarded.
|
|
1087
|
+
* To allow duplicate values of the headers listed above to be joined,
|
|
1088
|
+
* use the option `joinDuplicateHeaders` in {@link request} and {@link createServer}. See RFC 9110 Section 5.3 for more
|
|
1089
|
+
* information.
|
|
1123
1090
|
* * `set-cookie` is always an array. Duplicates are added to the array.
|
|
1124
|
-
* * For duplicate `cookie` headers, the values are joined together with
|
|
1125
|
-
* * For all other headers, the values are joined together with
|
|
1091
|
+
* * For duplicate `cookie` headers, the values are joined together with `; `.
|
|
1092
|
+
* * For all other headers, the values are joined together with `, `.
|
|
1126
1093
|
* @since v0.1.5
|
|
1127
1094
|
*/
|
|
1128
1095
|
headers: IncomingHttpHeaders;
|
|
1129
1096
|
/**
|
|
1130
|
-
* Similar to `message.headers`, but there is no join logic and the values are
|
|
1097
|
+
* Similar to `message.headers`, but there is no join logic and the values are
|
|
1098
|
+
* always arrays of strings, even for headers received just once.
|
|
1131
1099
|
*
|
|
1132
1100
|
* ```js
|
|
1133
1101
|
* // Prints something like:
|
|
@@ -1171,7 +1139,8 @@ declare module 'http' {
|
|
|
1171
1139
|
*/
|
|
1172
1140
|
trailers: NodeJS.Dict<string>;
|
|
1173
1141
|
/**
|
|
1174
|
-
* Similar to `message.trailers`, but there is no join logic and the values are
|
|
1142
|
+
* Similar to `message.trailers`, but there is no join logic and the values are
|
|
1143
|
+
* always arrays of strings, even for headers received just once.
|
|
1175
1144
|
* Only populated at the `'end'` event.
|
|
1176
1145
|
* @since v18.3.0, v16.17.0
|
|
1177
1146
|
*/
|
|
@@ -1208,14 +1177,14 @@ declare module 'http' {
|
|
|
1208
1177
|
* To parse the URL into its parts:
|
|
1209
1178
|
*
|
|
1210
1179
|
* ```js
|
|
1211
|
-
* new URL(request.url, `http://${request.
|
|
1180
|
+
* new URL(request.url, `http://${request.headers.host}`);
|
|
1212
1181
|
* ```
|
|
1213
1182
|
*
|
|
1214
|
-
* When `request.url` is `'/status?name=ryan'` and`request.
|
|
1183
|
+
* When `request.url` is `'/status?name=ryan'` and `request.headers.host` is`'localhost:3000'`:
|
|
1215
1184
|
*
|
|
1216
1185
|
* ```console
|
|
1217
1186
|
* $ node
|
|
1218
|
-
* > new URL(request.url, `http://${request.
|
|
1187
|
+
* > new URL(request.url, `http://${request.headers.host}`)
|
|
1219
1188
|
* URL {
|
|
1220
1189
|
* href: 'http://localhost:3000/status?name=ryan',
|
|
1221
1190
|
* origin: 'http://localhost:3000',
|
|
@@ -1335,7 +1304,7 @@ declare module 'http' {
|
|
|
1335
1304
|
* hostname: 'localhost',
|
|
1336
1305
|
* port: 80,
|
|
1337
1306
|
* path: '/',
|
|
1338
|
-
* agent: false // Create a new agent just for this one request
|
|
1307
|
+
* agent: false, // Create a new agent just for this one request
|
|
1339
1308
|
* }, (res) => {
|
|
1340
1309
|
* // Do stuff with response
|
|
1341
1310
|
* });
|
|
@@ -1440,10 +1409,10 @@ declare module 'http' {
|
|
|
1440
1409
|
* upload a file with a POST request, then write to the `ClientRequest` object.
|
|
1441
1410
|
*
|
|
1442
1411
|
* ```js
|
|
1443
|
-
* const http = require('http');
|
|
1412
|
+
* const http = require('node:http');
|
|
1444
1413
|
*
|
|
1445
1414
|
* const postData = JSON.stringify({
|
|
1446
|
-
* 'msg': 'Hello World!'
|
|
1415
|
+
* 'msg': 'Hello World!',
|
|
1447
1416
|
* });
|
|
1448
1417
|
*
|
|
1449
1418
|
* const options = {
|
|
@@ -1453,8 +1422,8 @@ declare module 'http' {
|
|
|
1453
1422
|
* method: 'POST',
|
|
1454
1423
|
* headers: {
|
|
1455
1424
|
* 'Content-Type': 'application/json',
|
|
1456
|
-
* 'Content-Length': Buffer.byteLength(postData)
|
|
1457
|
-
* }
|
|
1425
|
+
* 'Content-Length': Buffer.byteLength(postData),
|
|
1426
|
+
* },
|
|
1458
1427
|
* };
|
|
1459
1428
|
*
|
|
1460
1429
|
* const req = http.request(options, (res) => {
|
|
@@ -1541,7 +1510,7 @@ declare module 'http' {
|
|
|
1541
1510
|
* * `'data'` any number of times, on the `res` object
|
|
1542
1511
|
* * (connection closed here)
|
|
1543
1512
|
* * `'aborted'` on the `res` object
|
|
1544
|
-
* * `'error'` on the `res` object with an error with message`'Error: aborted'` and code `'ECONNRESET'
|
|
1513
|
+
* * `'error'` on the `res` object with an error with message`'Error: aborted'` and code `'ECONNRESET'`
|
|
1545
1514
|
* * `'close'`
|
|
1546
1515
|
* * `'close'` on the `res` object
|
|
1547
1516
|
*
|
|
@@ -1549,7 +1518,7 @@ declare module 'http' {
|
|
|
1549
1518
|
* events will be emitted in the following order:
|
|
1550
1519
|
*
|
|
1551
1520
|
* * (`req.destroy()` called here)
|
|
1552
|
-
* * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`
|
|
1521
|
+
* * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`, or the error with which `req.destroy()` was called
|
|
1553
1522
|
* * `'close'`
|
|
1554
1523
|
*
|
|
1555
1524
|
* If `req.destroy()` is called before the connection succeeds, the following
|
|
@@ -1557,7 +1526,7 @@ declare module 'http' {
|
|
|
1557
1526
|
*
|
|
1558
1527
|
* * `'socket'`
|
|
1559
1528
|
* * (`req.destroy()` called here)
|
|
1560
|
-
* * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`
|
|
1529
|
+
* * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`, or the error with which `req.destroy()` was called
|
|
1561
1530
|
* * `'close'`
|
|
1562
1531
|
*
|
|
1563
1532
|
* If `req.destroy()` is called after the response is received, the following
|
|
@@ -1568,7 +1537,7 @@ declare module 'http' {
|
|
|
1568
1537
|
* * `'data'` any number of times, on the `res` object
|
|
1569
1538
|
* * (`req.destroy()` called here)
|
|
1570
1539
|
* * `'aborted'` on the `res` object
|
|
1571
|
-
* * `'error'` on the `res` object with an error with message`'Error: aborted'`
|
|
1540
|
+
* * `'error'` on the `res` object with an error with message `'Error: aborted'`and code `'ECONNRESET'`, or the error with which `req.destroy()` was called
|
|
1572
1541
|
* * `'close'`
|
|
1573
1542
|
* * `'close'` on the `res` object
|
|
1574
1543
|
*
|
|
@@ -1604,16 +1573,13 @@ declare module 'http' {
|
|
|
1604
1573
|
* Setting the `timeout` option or using the `setTimeout()` function will
|
|
1605
1574
|
* not abort the request or do anything besides add a `'timeout'` event.
|
|
1606
1575
|
*
|
|
1607
|
-
* Passing an `AbortSignal` and then calling `abort` on the corresponding`AbortController` will behave the same way as calling `.destroy()` on the
|
|
1608
|
-
* request
|
|
1576
|
+
* Passing an `AbortSignal` and then calling `abort()` on the corresponding`AbortController` will behave the same way as calling `.destroy()` on the
|
|
1577
|
+
* request. Specifically, the `'error'` event will be emitted with an error with
|
|
1578
|
+
* the message `'AbortError: The operation was aborted'`, the code `'ABORT_ERR'`and the `cause`, if one was provided.
|
|
1609
1579
|
* @since v0.3.6
|
|
1610
1580
|
*/
|
|
1611
1581
|
function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
|
|
1612
|
-
function request(
|
|
1613
|
-
url: string | URL,
|
|
1614
|
-
options: RequestOptions,
|
|
1615
|
-
callback?: (res: IncomingMessage) => void,
|
|
1616
|
-
): ClientRequest;
|
|
1582
|
+
function request(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
|
|
1617
1583
|
/**
|
|
1618
1584
|
* Since most requests are GET requests without bodies, Node.js provides this
|
|
1619
1585
|
* 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
|
|
@@ -1665,7 +1631,7 @@ declare module 'http' {
|
|
|
1665
1631
|
* const server = http.createServer((req, res) => {
|
|
1666
1632
|
* res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1667
1633
|
* res.end(JSON.stringify({
|
|
1668
|
-
* data: 'Hello World!'
|
|
1634
|
+
* data: 'Hello World!',
|
|
1669
1635
|
* }));
|
|
1670
1636
|
* });
|
|
1671
1637
|
*
|
|
@@ -1676,32 +1642,76 @@ declare module 'http' {
|
|
|
1676
1642
|
*/
|
|
1677
1643
|
function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
|
|
1678
1644
|
function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
|
|
1679
|
-
|
|
1680
1645
|
/**
|
|
1681
|
-
* Performs the low-level validations on the provided name that are done when
|
|
1682
|
-
*
|
|
1683
|
-
*
|
|
1646
|
+
* Performs the low-level validations on the provided `name` that are done when`res.setHeader(name, value)` is called.
|
|
1647
|
+
*
|
|
1648
|
+
* Passing illegal value as `name` will result in a `TypeError` being thrown,
|
|
1649
|
+
* identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
|
|
1650
|
+
*
|
|
1651
|
+
* It is not necessary to use this method before passing headers to an HTTP request
|
|
1652
|
+
* or response. The HTTP module will automatically validate such headers.
|
|
1653
|
+
* Examples:
|
|
1654
|
+
*
|
|
1655
|
+
* Example:
|
|
1656
|
+
*
|
|
1657
|
+
* ```js
|
|
1658
|
+
* const { validateHeaderName } = require('node:http');
|
|
1659
|
+
*
|
|
1660
|
+
* try {
|
|
1661
|
+
* validateHeaderName('');
|
|
1662
|
+
* } catch (err) {
|
|
1663
|
+
* console.error(err instanceof TypeError); // --> true
|
|
1664
|
+
* console.error(err.code); // --> 'ERR_INVALID_HTTP_TOKEN'
|
|
1665
|
+
* console.error(err.message); // --> 'Header name must be a valid HTTP token [""]'
|
|
1666
|
+
* }
|
|
1667
|
+
* ```
|
|
1684
1668
|
* @since v14.3.0
|
|
1669
|
+
* @param [label='Header name'] Label for error message.
|
|
1685
1670
|
*/
|
|
1686
1671
|
function validateHeaderName(name: string): void;
|
|
1687
1672
|
/**
|
|
1688
|
-
* Performs the low-level validations on the provided value that are done when
|
|
1689
|
-
*
|
|
1690
|
-
*
|
|
1691
|
-
*
|
|
1673
|
+
* Performs the low-level validations on the provided `value` that are done when`res.setHeader(name, value)` is called.
|
|
1674
|
+
*
|
|
1675
|
+
* Passing illegal value as `value` will result in a `TypeError` being thrown.
|
|
1676
|
+
*
|
|
1677
|
+
* * Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
|
|
1678
|
+
* * Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
|
|
1679
|
+
*
|
|
1680
|
+
* It is not necessary to use this method before passing headers to an HTTP request
|
|
1681
|
+
* or response. The HTTP module will automatically validate such headers.
|
|
1682
|
+
*
|
|
1683
|
+
* Examples:
|
|
1684
|
+
*
|
|
1685
|
+
* ```js
|
|
1686
|
+
* const { validateHeaderValue } = require('node:http');
|
|
1687
|
+
*
|
|
1688
|
+
* try {
|
|
1689
|
+
* validateHeaderValue('x-my-header', undefined);
|
|
1690
|
+
* } catch (err) {
|
|
1691
|
+
* console.error(err instanceof TypeError); // --> true
|
|
1692
|
+
* console.error(err.code === 'ERR_HTTP_INVALID_HEADER_VALUE'); // --> true
|
|
1693
|
+
* console.error(err.message); // --> 'Invalid value "undefined" for header "x-my-header"'
|
|
1694
|
+
* }
|
|
1695
|
+
*
|
|
1696
|
+
* try {
|
|
1697
|
+
* validateHeaderValue('x-my-header', 'oʊmɪɡə');
|
|
1698
|
+
* } catch (err) {
|
|
1699
|
+
* console.error(err instanceof TypeError); // --> true
|
|
1700
|
+
* console.error(err.code === 'ERR_INVALID_CHAR'); // --> true
|
|
1701
|
+
* console.error(err.message); // --> 'Invalid character in header content ["x-my-header"]'
|
|
1702
|
+
* }
|
|
1703
|
+
* ```
|
|
1704
|
+
* @since v14.3.0
|
|
1692
1705
|
* @param name Header name
|
|
1693
1706
|
* @param value Header value
|
|
1694
|
-
* @since v14.3.0
|
|
1695
1707
|
*/
|
|
1696
1708
|
function validateHeaderValue(name: string, value: string): void;
|
|
1697
|
-
|
|
1698
1709
|
/**
|
|
1699
|
-
* Set the maximum number of idle HTTP parsers.
|
|
1700
|
-
* @param count
|
|
1710
|
+
* Set the maximum number of idle HTTP parsers.
|
|
1701
1711
|
* @since v18.8.0, v16.18.0
|
|
1712
|
+
* @param [max=1000]
|
|
1702
1713
|
*/
|
|
1703
|
-
function setMaxIdleHTTPParsers(
|
|
1704
|
-
|
|
1714
|
+
function setMaxIdleHTTPParsers(max: number): void;
|
|
1705
1715
|
let globalAgent: Agent;
|
|
1706
1716
|
/**
|
|
1707
1717
|
* Read-only property specifying the maximum allowed size of HTTP headers in bytes.
|