@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,7 +37,7 @@
|
|
|
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';
|
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
-
*
|
|
482
|
-
*
|
|
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
|
|
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
|
|
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
|
|
539
|
-
* the
|
|
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
|
|
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
|
-
*
|
|
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
|
|
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
|
|
700
|
-
*
|
|
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 `
|
|
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
|
|
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
|
-
*
|
|
754
|
-
*
|
|
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.
|
|
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.
|
|
1179
|
+
* new URL(request.url, `http://${request.headers.host}`);
|
|
1149
1180
|
* ```
|
|
1150
1181
|
*
|
|
1151
|
-
* When `request.url` is `'/status?name=ryan'` and`request.
|
|
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.
|
|
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'`
|
|
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
|
|
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
|
|
1619
|
-
*
|
|
1620
|
-
*
|
|
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
|
|
1626
|
-
*
|
|
1627
|
-
*
|
|
1628
|
-
*
|
|
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.
|
|
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(
|
|
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.
|