@types/node 18.11.5 → 20.2.5
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/README.md +2 -2
- node/assert.d.ts +86 -75
- node/async_hooks.d.ts +66 -37
- node/buffer.d.ts +193 -100
- node/child_process.d.ts +82 -56
- node/cluster.d.ts +12 -12
- node/console.d.ts +5 -5
- node/crypto.d.ts +233 -235
- node/dgram.d.ts +15 -15
- node/diagnostics_channel.d.ts +59 -21
- node/dns/promises.d.ts +50 -6
- node/dns.d.ts +26 -17
- node/domain.d.ts +4 -4
- node/events.d.ts +111 -65
- node/fs/promises.d.ts +99 -47
- node/fs.d.ts +244 -73
- node/globals.d.ts +6 -3
- node/http.d.ts +265 -148
- node/http2.d.ts +42 -47
- node/https.d.ts +53 -153
- node/index.d.ts +2 -1
- node/inspector.d.ts +10 -3
- node/module.d.ts +6 -4
- node/net.d.ts +32 -15
- node/os.d.ts +27 -16
- node/package.json +9 -4
- node/path.d.ts +4 -4
- node/perf_hooks.d.ts +28 -15
- node/process.d.ts +49 -46
- node/punycode.d.ts +1 -1
- node/querystring.d.ts +5 -5
- node/readline/promises.d.ts +65 -63
- node/readline.d.ts +32 -159
- node/repl.d.ts +20 -20
- node/stream/consumers.d.ts +1 -1
- node/stream.d.ts +950 -869
- node/string_decoder.d.ts +6 -6
- node/test.d.ts +877 -139
- node/timers/promises.d.ts +26 -1
- node/timers.d.ts +125 -4
- node/tls.d.ts +120 -29
- node/trace_events.d.ts +20 -9
- node/ts4.8/assert.d.ts +86 -75
- node/ts4.8/async_hooks.d.ts +66 -37
- node/ts4.8/buffer.d.ts +193 -101
- node/ts4.8/child_process.d.ts +82 -56
- node/ts4.8/cluster.d.ts +12 -12
- node/ts4.8/console.d.ts +5 -5
- node/ts4.8/crypto.d.ts +230 -233
- node/ts4.8/dgram.d.ts +15 -15
- node/ts4.8/diagnostics_channel.d.ts +59 -21
- node/ts4.8/dns/promises.d.ts +50 -6
- node/ts4.8/dns.d.ts +26 -17
- node/ts4.8/domain.d.ts +4 -4
- node/ts4.8/events.d.ts +111 -65
- node/ts4.8/fs/promises.d.ts +97 -46
- node/ts4.8/fs.d.ts +244 -73
- node/ts4.8/globals.d.ts +21 -12
- node/ts4.8/http.d.ts +265 -148
- node/ts4.8/http2.d.ts +42 -47
- node/ts4.8/https.d.ts +53 -153
- node/ts4.8/inspector.d.ts +10 -3
- node/ts4.8/module.d.ts +6 -4
- node/ts4.8/net.d.ts +33 -16
- node/ts4.8/os.d.ts +27 -16
- node/ts4.8/path.d.ts +4 -4
- node/ts4.8/perf_hooks.d.ts +28 -15
- node/ts4.8/process.d.ts +49 -46
- node/ts4.8/punycode.d.ts +1 -1
- node/ts4.8/querystring.d.ts +5 -5
- node/ts4.8/readline/promises.d.ts +65 -63
- node/ts4.8/readline.d.ts +32 -159
- node/ts4.8/repl.d.ts +20 -20
- node/ts4.8/stream/consumers.d.ts +1 -1
- node/ts4.8/stream.d.ts +192 -140
- node/ts4.8/string_decoder.d.ts +6 -6
- node/ts4.8/test.d.ts +877 -139
- node/ts4.8/timers/promises.d.ts +26 -1
- node/ts4.8/timers.d.ts +125 -4
- node/ts4.8/tls.d.ts +120 -29
- node/ts4.8/trace_events.d.ts +20 -9
- node/ts4.8/tty.d.ts +4 -5
- node/ts4.8/url.d.ts +46 -42
- node/ts4.8/util.d.ts +325 -123
- node/ts4.8/v8.d.ts +253 -14
- node/ts4.8/vm.d.ts +417 -32
- node/ts4.8/wasi.d.ts +13 -19
- node/ts4.8/worker_threads.d.ts +38 -34
- node/ts4.8/zlib.d.ts +11 -11
- node/tty.d.ts +4 -5
- node/url.d.ts +46 -42
- node/util.d.ts +325 -123
- node/v8.d.ts +253 -14
- node/vm.d.ts +417 -32
- node/wasi.d.ts +13 -19
- node/worker_threads.d.ts +38 -34
- 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,11 +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.2.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 { LookupOptions } from 'node:dns';
|
|
46
|
+
import { EventEmitter } from 'node:events';
|
|
45
47
|
import { TcpSocketConnectOpts, Socket, Server as NetServer, LookupFunction } from 'node:net';
|
|
46
48
|
// incoming headers will never contain number
|
|
47
49
|
interface IncomingHttpHeaders extends NodeJS.Dict<string | string[]> {
|
|
@@ -113,56 +115,101 @@ declare module 'http' {
|
|
|
113
115
|
type OutgoingHttpHeader = number | string | string[];
|
|
114
116
|
interface OutgoingHttpHeaders extends NodeJS.Dict<OutgoingHttpHeader> {}
|
|
115
117
|
interface ClientRequestArgs {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
+
_defaultAgent?: Agent | undefined;
|
|
119
|
+
agent?: Agent | boolean | undefined;
|
|
120
|
+
auth?: string | null | undefined;
|
|
121
|
+
// https://github.com/nodejs/node/blob/master/lib/_http_client.js#L278
|
|
122
|
+
createConnection?:
|
|
123
|
+
| ((options: ClientRequestArgs, oncreate: (err: Error, socket: Socket) => void) => Socket)
|
|
124
|
+
| undefined;
|
|
125
|
+
defaultPort?: number | string | undefined;
|
|
126
|
+
family?: number | undefined;
|
|
127
|
+
headers?: OutgoingHttpHeaders | undefined;
|
|
128
|
+
hints?: LookupOptions['hints'];
|
|
118
129
|
host?: string | null | undefined;
|
|
119
130
|
hostname?: string | null | undefined;
|
|
120
|
-
|
|
121
|
-
port?: number | string | null | undefined;
|
|
122
|
-
defaultPort?: number | string | undefined;
|
|
131
|
+
insecureHTTPParser?: boolean | undefined;
|
|
123
132
|
localAddress?: string | undefined;
|
|
124
|
-
|
|
133
|
+
localPort?: number | undefined;
|
|
134
|
+
lookup?: LookupFunction | undefined;
|
|
125
135
|
/**
|
|
126
|
-
* @default
|
|
136
|
+
* @default 16384
|
|
127
137
|
*/
|
|
128
138
|
maxHeaderSize?: number | undefined;
|
|
129
139
|
method?: string | undefined;
|
|
130
140
|
path?: string | null | undefined;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
agent?: Agent | boolean | undefined;
|
|
134
|
-
_defaultAgent?: Agent | undefined;
|
|
135
|
-
timeout?: number | undefined;
|
|
141
|
+
port?: number | string | null | undefined;
|
|
142
|
+
protocol?: string | null | undefined;
|
|
136
143
|
setHost?: boolean | undefined;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
signal?: AbortSignal | undefined;
|
|
145
|
+
socketPath?: string | undefined;
|
|
146
|
+
timeout?: number | undefined;
|
|
147
|
+
uniqueHeaders?: Array<string | string[]> | undefined;
|
|
148
|
+
joinDuplicateHeaders?: boolean;
|
|
142
149
|
}
|
|
143
150
|
interface ServerOptions<
|
|
144
151
|
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
|
145
152
|
Response extends typeof ServerResponse = typeof ServerResponse,
|
|
146
153
|
> {
|
|
154
|
+
/**
|
|
155
|
+
* Specifies the `IncomingMessage` class to be used. Useful for extending the original `IncomingMessage`.
|
|
156
|
+
*/
|
|
147
157
|
IncomingMessage?: Request | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* Specifies the `ServerResponse` class to be used. Useful for extending the original `ServerResponse`.
|
|
160
|
+
*/
|
|
148
161
|
ServerResponse?: Response | undefined;
|
|
149
162
|
/**
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* @
|
|
163
|
+
* Sets the timeout value in milliseconds for receiving the entire request from the client.
|
|
164
|
+
* @see Server.requestTimeout for more information.
|
|
165
|
+
* @default 300000
|
|
166
|
+
* @since v18.0.0
|
|
154
167
|
*/
|
|
155
|
-
|
|
168
|
+
requestTimeout?: number | undefined;
|
|
169
|
+
/**
|
|
170
|
+
* It joins the field line values of multiple headers in a request with `, ` instead of discarding the duplicates.
|
|
171
|
+
* @default false
|
|
172
|
+
* @since v18.14.0
|
|
173
|
+
*/
|
|
174
|
+
joinDuplicateHeaders?: boolean;
|
|
175
|
+
/**
|
|
176
|
+
* The number of milliseconds of inactivity a server needs to wait for additional incoming data,
|
|
177
|
+
* after it has finished writing the last response, before a socket will be destroyed.
|
|
178
|
+
* @see Server.keepAliveTimeout for more information.
|
|
179
|
+
* @default 5000
|
|
180
|
+
* @since v18.0.0
|
|
181
|
+
*/
|
|
182
|
+
keepAliveTimeout?: number | undefined;
|
|
156
183
|
/**
|
|
157
|
-
*
|
|
184
|
+
* Sets the interval value in milliseconds to check for request and headers timeout in incomplete requests.
|
|
185
|
+
* @default 30000
|
|
186
|
+
*/
|
|
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;
|
|
195
|
+
/**
|
|
196
|
+
* Use an insecure HTTP parser that accepts invalid HTTP headers when `true`.
|
|
158
197
|
* Using the insecure parser should be avoided.
|
|
159
198
|
* See --insecure-http-parser for more information.
|
|
160
199
|
* @default false
|
|
161
200
|
*/
|
|
162
201
|
insecureHTTPParser?: boolean | undefined;
|
|
202
|
+
/**
|
|
203
|
+
* Optionally overrides the value of
|
|
204
|
+
* `--max-http-header-size` for requests received by this server, i.e.
|
|
205
|
+
* the maximum length of request headers in bytes.
|
|
206
|
+
* @default 16384
|
|
207
|
+
* @since v13.3.0
|
|
208
|
+
*/
|
|
209
|
+
maxHeaderSize?: number | undefined;
|
|
163
210
|
/**
|
|
164
211
|
* If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.
|
|
165
|
-
* @default
|
|
212
|
+
* @default true
|
|
166
213
|
* @since v16.5.0
|
|
167
214
|
*/
|
|
168
215
|
noDelay?: boolean | undefined;
|
|
@@ -179,6 +226,11 @@ declare module 'http' {
|
|
|
179
226
|
* @since v16.5.0
|
|
180
227
|
*/
|
|
181
228
|
keepAliveInitialDelay?: number | undefined;
|
|
229
|
+
/**
|
|
230
|
+
* A list of response headers that should be sent only once.
|
|
231
|
+
* If the header's value is an array, the items will be joined using `; `.
|
|
232
|
+
*/
|
|
233
|
+
uniqueHeaders?: Array<string | string[]> | undefined;
|
|
182
234
|
}
|
|
183
235
|
type RequestListener<
|
|
184
236
|
Request extends typeof IncomingMessage = typeof IncomingMessage,
|
|
@@ -285,7 +337,8 @@ declare module 'http' {
|
|
|
285
337
|
*/
|
|
286
338
|
closeAllConnections(): void;
|
|
287
339
|
/**
|
|
288
|
-
* 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.
|
|
289
342
|
* @since v18.2.0
|
|
290
343
|
*/
|
|
291
344
|
closeIdleConnections(): void;
|
|
@@ -297,15 +350,10 @@ declare module 'http' {
|
|
|
297
350
|
addListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
|
|
298
351
|
addListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
|
|
299
352
|
addListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
|
|
300
|
-
addListener(
|
|
301
|
-
|
|
302
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
303
|
-
): this;
|
|
353
|
+
addListener(event: 'connect', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
354
|
+
addListener(event: 'dropRequest', listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
|
|
304
355
|
addListener(event: 'request', listener: RequestListener<Request, Response>): this;
|
|
305
|
-
addListener(
|
|
306
|
-
event: 'upgrade',
|
|
307
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
308
|
-
): this;
|
|
356
|
+
addListener(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
309
357
|
emit(event: string, ...args: any[]): boolean;
|
|
310
358
|
emit(event: 'close'): boolean;
|
|
311
359
|
emit(event: 'connection', socket: Socket): boolean;
|
|
@@ -323,6 +371,7 @@ declare module 'http' {
|
|
|
323
371
|
): boolean;
|
|
324
372
|
emit(event: 'clientError', err: Error, socket: stream.Duplex): boolean;
|
|
325
373
|
emit(event: 'connect', req: InstanceType<Request>, socket: stream.Duplex, head: Buffer): boolean;
|
|
374
|
+
emit(event: 'dropRequest', req: InstanceType<Request>, socket: stream.Duplex): boolean;
|
|
326
375
|
emit(
|
|
327
376
|
event: 'request',
|
|
328
377
|
req: InstanceType<Request>,
|
|
@@ -338,6 +387,7 @@ declare module 'http' {
|
|
|
338
387
|
on(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
|
|
339
388
|
on(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
|
|
340
389
|
on(event: 'connect', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
390
|
+
on(event: 'dropRequest', listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
|
|
341
391
|
on(event: 'request', listener: RequestListener<Request, Response>): this;
|
|
342
392
|
on(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
343
393
|
once(event: string, listener: (...args: any[]) => void): this;
|
|
@@ -348,15 +398,10 @@ declare module 'http' {
|
|
|
348
398
|
once(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
|
|
349
399
|
once(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
|
|
350
400
|
once(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
|
|
351
|
-
once(
|
|
352
|
-
|
|
353
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
354
|
-
): this;
|
|
401
|
+
once(event: 'connect', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
402
|
+
once(event: 'dropRequest', listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
|
|
355
403
|
once(event: 'request', listener: RequestListener<Request, Response>): this;
|
|
356
|
-
once(
|
|
357
|
-
event: 'upgrade',
|
|
358
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
359
|
-
): this;
|
|
404
|
+
once(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
360
405
|
prependListener(event: string, listener: (...args: any[]) => void): this;
|
|
361
406
|
prependListener(event: 'close', listener: () => void): this;
|
|
362
407
|
prependListener(event: 'connection', listener: (socket: Socket) => void): this;
|
|
@@ -365,15 +410,10 @@ declare module 'http' {
|
|
|
365
410
|
prependListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
|
|
366
411
|
prependListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
|
|
367
412
|
prependListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
|
|
368
|
-
prependListener(
|
|
369
|
-
|
|
370
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
371
|
-
): 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;
|
|
372
415
|
prependListener(event: 'request', listener: RequestListener<Request, Response>): this;
|
|
373
|
-
prependListener(
|
|
374
|
-
event: 'upgrade',
|
|
375
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
376
|
-
): this;
|
|
416
|
+
prependListener(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
377
417
|
prependOnceListener(event: string, listener: (...args: any[]) => void): this;
|
|
378
418
|
prependOnceListener(event: 'close', listener: () => void): this;
|
|
379
419
|
prependOnceListener(event: 'connection', listener: (socket: Socket) => void): this;
|
|
@@ -382,19 +422,14 @@ declare module 'http' {
|
|
|
382
422
|
prependOnceListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
|
|
383
423
|
prependOnceListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
|
|
384
424
|
prependOnceListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
|
|
385
|
-
prependOnceListener(
|
|
386
|
-
|
|
387
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
388
|
-
): 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;
|
|
389
427
|
prependOnceListener(event: 'request', listener: RequestListener<Request, Response>): this;
|
|
390
|
-
prependOnceListener(
|
|
391
|
-
event: 'upgrade',
|
|
392
|
-
listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
|
|
393
|
-
): this;
|
|
428
|
+
prependOnceListener(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
|
|
394
429
|
}
|
|
395
430
|
/**
|
|
396
|
-
* This class serves as the parent class of {@link ClientRequest} and {@link ServerResponse}. It is an abstract
|
|
397
|
-
* 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.
|
|
398
433
|
* @since v0.1.17
|
|
399
434
|
*/
|
|
400
435
|
class OutgoingMessage<Request extends IncomingMessage = IncomingMessage> extends stream.Writable {
|
|
@@ -413,7 +448,7 @@ declare module 'http' {
|
|
|
413
448
|
*/
|
|
414
449
|
readonly headersSent: boolean;
|
|
415
450
|
/**
|
|
416
|
-
*
|
|
451
|
+
* Alias of `outgoingMessage.socket`.
|
|
417
452
|
* @since v0.3.0
|
|
418
453
|
* @deprecated Since v15.12.0,v14.17.1 - Use `socket` instead.
|
|
419
454
|
*/
|
|
@@ -434,15 +469,33 @@ declare module 'http' {
|
|
|
434
469
|
*/
|
|
435
470
|
setTimeout(msecs: number, callback?: () => void): this;
|
|
436
471
|
/**
|
|
437
|
-
* Sets a single header value
|
|
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.
|
|
438
475
|
* @since v0.4.0
|
|
439
476
|
* @param name Header name
|
|
440
477
|
* @param value Header value
|
|
441
478
|
*/
|
|
442
479
|
setHeader(name: string, value: number | string | ReadonlyArray<string>): this;
|
|
443
480
|
/**
|
|
444
|
-
*
|
|
445
|
-
*
|
|
481
|
+
* Append a single header value for the header object.
|
|
482
|
+
*
|
|
483
|
+
* If the value is an array, this is equivalent of calling this method multiple
|
|
484
|
+
* times.
|
|
485
|
+
*
|
|
486
|
+
* If there were no previous value for the header, this is equivalent of calling `outgoingMessage.setHeader(name, value)`.
|
|
487
|
+
*
|
|
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 `; `.
|
|
491
|
+
* @since v18.3.0, v16.17.0
|
|
492
|
+
* @param name Header name
|
|
493
|
+
* @param value Header value
|
|
494
|
+
*/
|
|
495
|
+
appendHeader(name: string, value: string | ReadonlyArray<string>): this;
|
|
496
|
+
/**
|
|
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`.
|
|
446
499
|
* @since v0.4.0
|
|
447
500
|
* @param name Name of header
|
|
448
501
|
*/
|
|
@@ -455,8 +508,8 @@ declare module 'http' {
|
|
|
455
508
|
* values. All header names are lowercase.
|
|
456
509
|
*
|
|
457
510
|
* The object returned by the `outgoingMessage.getHeaders()` method does
|
|
458
|
-
* not prototypically inherit from the JavaScript Object
|
|
459
|
-
* 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()`,
|
|
460
513
|
* and others are not defined and will not work.
|
|
461
514
|
*
|
|
462
515
|
* ```js
|
|
@@ -470,8 +523,8 @@ declare module 'http' {
|
|
|
470
523
|
*/
|
|
471
524
|
getHeaders(): OutgoingHttpHeaders;
|
|
472
525
|
/**
|
|
473
|
-
* Returns an array
|
|
474
|
-
* names are lowercase.
|
|
526
|
+
* Returns an array containing the unique names of the current outgoing headers.
|
|
527
|
+
* All names are lowercase.
|
|
475
528
|
* @since v7.7.0
|
|
476
529
|
*/
|
|
477
530
|
getHeaderNames(): string[];
|
|
@@ -498,11 +551,11 @@ declare module 'http' {
|
|
|
498
551
|
/**
|
|
499
552
|
* Adds HTTP trailers (headers but at the end of the message) to the message.
|
|
500
553
|
*
|
|
501
|
-
* Trailers
|
|
502
|
-
* the
|
|
554
|
+
* Trailers will **only** be emitted if the message is chunked encoded. If not,
|
|
555
|
+
* the trailers will be silently discarded.
|
|
503
556
|
*
|
|
504
557
|
* HTTP requires the `Trailer` header to be sent to emit trailers,
|
|
505
|
-
* with a list of header
|
|
558
|
+
* with a list of header field names in its value, e.g.
|
|
506
559
|
*
|
|
507
560
|
* ```js
|
|
508
561
|
* message.writeHead(200, { 'Content-Type': 'text/plain',
|
|
@@ -518,7 +571,7 @@ declare module 'http' {
|
|
|
518
571
|
*/
|
|
519
572
|
addTrailers(headers: OutgoingHttpHeaders | ReadonlyArray<[string, string]>): void;
|
|
520
573
|
/**
|
|
521
|
-
*
|
|
574
|
+
* Flushes the message headers.
|
|
522
575
|
*
|
|
523
576
|
* For efficiency reason, Node.js normally buffers the message headers
|
|
524
577
|
* until `outgoingMessage.end()` is called or the first chunk of message data
|
|
@@ -526,7 +579,7 @@ declare module 'http' {
|
|
|
526
579
|
* packet.
|
|
527
580
|
*
|
|
528
581
|
* It is usually desired (it saves a TCP round-trip), but not when the first
|
|
529
|
-
* 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.
|
|
530
583
|
* @since v1.6.0
|
|
531
584
|
*/
|
|
532
585
|
flushHeaders(): void;
|
|
@@ -566,6 +619,13 @@ declare module 'http' {
|
|
|
566
619
|
* @since v0.11.8
|
|
567
620
|
*/
|
|
568
621
|
statusMessage: string;
|
|
622
|
+
/**
|
|
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'`.
|
|
626
|
+
* @since v18.10.0, v16.18.0
|
|
627
|
+
*/
|
|
628
|
+
strictContentLength: boolean;
|
|
569
629
|
constructor(req: Request);
|
|
570
630
|
assignSocket(socket: Socket): void;
|
|
571
631
|
detachSocket(socket: Socket): void;
|
|
@@ -582,7 +642,7 @@ declare module 'http' {
|
|
|
582
642
|
* early hints message. The optional `callback` argument will be called when
|
|
583
643
|
* the response message has been written.
|
|
584
644
|
*
|
|
585
|
-
* Example
|
|
645
|
+
* **Example**
|
|
586
646
|
*
|
|
587
647
|
* ```js
|
|
588
648
|
* const earlyHintsLink = '</styles.css>; rel=preload; as=style';
|
|
@@ -596,15 +656,14 @@ declare module 'http' {
|
|
|
596
656
|
* ];
|
|
597
657
|
* response.writeEarlyHints({
|
|
598
658
|
* 'link': earlyHintsLinks,
|
|
599
|
-
* 'x-trace-id': 'id for diagnostics'
|
|
659
|
+
* 'x-trace-id': 'id for diagnostics',
|
|
600
660
|
* });
|
|
601
661
|
*
|
|
602
662
|
* const earlyHintsCallback = () => console.log('early hints message sent');
|
|
603
663
|
* response.writeEarlyHints({
|
|
604
|
-
* 'link': earlyHintsLinks
|
|
664
|
+
* 'link': earlyHintsLinks,
|
|
605
665
|
* }, earlyHintsCallback);
|
|
606
666
|
* ```
|
|
607
|
-
*
|
|
608
667
|
* @since v18.11.0
|
|
609
668
|
* @param hints An object containing the values of headers
|
|
610
669
|
* @param callback Will be called when the response message has been written
|
|
@@ -628,7 +687,7 @@ declare module 'http' {
|
|
|
628
687
|
* response
|
|
629
688
|
* .writeHead(200, {
|
|
630
689
|
* 'Content-Length': Buffer.byteLength(body),
|
|
631
|
-
* 'Content-Type': 'text/plain'
|
|
690
|
+
* 'Content-Type': 'text/plain',
|
|
632
691
|
* })
|
|
633
692
|
* .end(body);
|
|
634
693
|
* ```
|
|
@@ -659,12 +718,12 @@ declare module 'http' {
|
|
|
659
718
|
* });
|
|
660
719
|
* ```
|
|
661
720
|
*
|
|
662
|
-
* `Content-Length` is
|
|
663
|
-
*
|
|
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
|
|
664
723
|
* been transmitted are equal or not.
|
|
665
724
|
*
|
|
666
725
|
* Attempting to set a header field name or value that contains invalid characters
|
|
667
|
-
* will result in a `
|
|
726
|
+
* will result in a \[`Error`\]\[\] being thrown.
|
|
668
727
|
* @since v0.1.30
|
|
669
728
|
*/
|
|
670
729
|
writeHead(
|
|
@@ -674,7 +733,7 @@ declare module 'http' {
|
|
|
674
733
|
): this;
|
|
675
734
|
writeHead(statusCode: number, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[]): this;
|
|
676
735
|
/**
|
|
677
|
-
* Sends
|
|
736
|
+
* Sends a HTTP/1.1 102 Processing message to the client, indicating that
|
|
678
737
|
* the request body should be sent.
|
|
679
738
|
* @since v10.0.0
|
|
680
739
|
*/
|
|
@@ -713,8 +772,11 @@ declare module 'http' {
|
|
|
713
772
|
*
|
|
714
773
|
* For backward compatibility, `res` will only emit `'error'` if there is an`'error'` listener registered.
|
|
715
774
|
*
|
|
716
|
-
*
|
|
717
|
-
*
|
|
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.
|
|
718
780
|
* @since v0.1.17
|
|
719
781
|
*/
|
|
720
782
|
class ClientRequest extends OutgoingMessage {
|
|
@@ -741,7 +803,7 @@ declare module 'http' {
|
|
|
741
803
|
* may run into a 'ECONNRESET' error.
|
|
742
804
|
*
|
|
743
805
|
* ```js
|
|
744
|
-
* const http = require('http');
|
|
806
|
+
* const http = require('node:http');
|
|
745
807
|
*
|
|
746
808
|
* // Server has a 5 seconds keep-alive timeout by default
|
|
747
809
|
* http
|
|
@@ -765,7 +827,7 @@ declare module 'http' {
|
|
|
765
827
|
* automatic error retry base on it.
|
|
766
828
|
*
|
|
767
829
|
* ```js
|
|
768
|
-
* const http = require('http');
|
|
830
|
+
* const http = require('node:http');
|
|
769
831
|
* const agent = new http.Agent({ keepAlive: true });
|
|
770
832
|
*
|
|
771
833
|
* function retriableRequest() {
|
|
@@ -844,19 +906,13 @@ declare module 'http' {
|
|
|
844
906
|
* @deprecated
|
|
845
907
|
*/
|
|
846
908
|
addListener(event: 'abort', listener: () => void): this;
|
|
847
|
-
addListener(
|
|
848
|
-
event: 'connect',
|
|
849
|
-
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
|
850
|
-
): this;
|
|
909
|
+
addListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
|
851
910
|
addListener(event: 'continue', listener: () => void): this;
|
|
852
911
|
addListener(event: 'information', listener: (info: InformationEvent) => void): this;
|
|
853
912
|
addListener(event: 'response', listener: (response: IncomingMessage) => void): this;
|
|
854
913
|
addListener(event: 'socket', listener: (socket: Socket) => void): this;
|
|
855
914
|
addListener(event: 'timeout', listener: () => void): this;
|
|
856
|
-
addListener(
|
|
857
|
-
event: 'upgrade',
|
|
858
|
-
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
|
859
|
-
): this;
|
|
915
|
+
addListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
|
860
916
|
addListener(event: 'close', listener: () => void): this;
|
|
861
917
|
addListener(event: 'drain', listener: () => void): this;
|
|
862
918
|
addListener(event: 'error', listener: (err: Error) => void): this;
|
|
@@ -904,19 +960,13 @@ declare module 'http' {
|
|
|
904
960
|
* @deprecated
|
|
905
961
|
*/
|
|
906
962
|
prependListener(event: 'abort', listener: () => void): this;
|
|
907
|
-
prependListener(
|
|
908
|
-
event: 'connect',
|
|
909
|
-
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
|
910
|
-
): this;
|
|
963
|
+
prependListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
|
911
964
|
prependListener(event: 'continue', listener: () => void): this;
|
|
912
965
|
prependListener(event: 'information', listener: (info: InformationEvent) => void): this;
|
|
913
966
|
prependListener(event: 'response', listener: (response: IncomingMessage) => void): this;
|
|
914
967
|
prependListener(event: 'socket', listener: (socket: Socket) => void): this;
|
|
915
968
|
prependListener(event: 'timeout', listener: () => void): this;
|
|
916
|
-
prependListener(
|
|
917
|
-
event: 'upgrade',
|
|
918
|
-
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
|
919
|
-
): this;
|
|
969
|
+
prependListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
|
920
970
|
prependListener(event: 'close', listener: () => void): this;
|
|
921
971
|
prependListener(event: 'drain', listener: () => void): this;
|
|
922
972
|
prependListener(event: 'error', listener: (err: Error) => void): this;
|
|
@@ -928,19 +978,13 @@ declare module 'http' {
|
|
|
928
978
|
* @deprecated
|
|
929
979
|
*/
|
|
930
980
|
prependOnceListener(event: 'abort', listener: () => void): this;
|
|
931
|
-
prependOnceListener(
|
|
932
|
-
event: 'connect',
|
|
933
|
-
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
|
934
|
-
): this;
|
|
981
|
+
prependOnceListener(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
|
935
982
|
prependOnceListener(event: 'continue', listener: () => void): this;
|
|
936
983
|
prependOnceListener(event: 'information', listener: (info: InformationEvent) => void): this;
|
|
937
984
|
prependOnceListener(event: 'response', listener: (response: IncomingMessage) => void): this;
|
|
938
985
|
prependOnceListener(event: 'socket', listener: (socket: Socket) => void): this;
|
|
939
986
|
prependOnceListener(event: 'timeout', listener: () => void): this;
|
|
940
|
-
prependOnceListener(
|
|
941
|
-
event: 'upgrade',
|
|
942
|
-
listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
|
|
943
|
-
): this;
|
|
987
|
+
prependOnceListener(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
|
|
944
988
|
prependOnceListener(event: 'close', listener: () => void): this;
|
|
945
989
|
prependOnceListener(event: 'drain', listener: () => void): this;
|
|
946
990
|
prependOnceListener(event: 'error', listener: (err: Error) => void): this;
|
|
@@ -952,7 +996,7 @@ declare module 'http' {
|
|
|
952
996
|
/**
|
|
953
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
|
|
954
998
|
* access response
|
|
955
|
-
* status, headers and data.
|
|
999
|
+
* status, headers, and data.
|
|
956
1000
|
*
|
|
957
1001
|
* Different from its `socket` value which is a subclass of `stream.Duplex`, the`IncomingMessage` itself extends `stream.Readable` and is created separately to
|
|
958
1002
|
* parse and emit the incoming HTTP headers and payload, as the underlying socket
|
|
@@ -990,7 +1034,7 @@ declare module 'http' {
|
|
|
990
1034
|
* const req = http.request({
|
|
991
1035
|
* host: '127.0.0.1',
|
|
992
1036
|
* port: 8080,
|
|
993
|
-
* method: 'POST'
|
|
1037
|
+
* method: 'POST',
|
|
994
1038
|
* }, (res) => {
|
|
995
1039
|
* res.resume();
|
|
996
1040
|
* res.on('end', () => {
|
|
@@ -1032,7 +1076,7 @@ declare module 'http' {
|
|
|
1032
1076
|
* // { 'user-agent': 'curl/7.22.0',
|
|
1033
1077
|
* // host: '127.0.0.1:8000',
|
|
1034
1078
|
* // accept: '*' }
|
|
1035
|
-
* console.log(request.
|
|
1079
|
+
* console.log(request.headers);
|
|
1036
1080
|
* ```
|
|
1037
1081
|
*
|
|
1038
1082
|
* Duplicates in raw headers are handled in the following ways, depending on the
|
|
@@ -1040,12 +1084,30 @@ declare module 'http' {
|
|
|
1040
1084
|
*
|
|
1041
1085
|
* * Duplicates of `age`, `authorization`, `content-length`, `content-type`,`etag`, `expires`, `from`, `host`, `if-modified-since`, `if-unmodified-since`,`last-modified`, `location`,
|
|
1042
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.
|
|
1043
1090
|
* * `set-cookie` is always an array. Duplicates are added to the array.
|
|
1044
|
-
* * For duplicate `cookie` headers, the values are joined together with
|
|
1045
|
-
* * 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 `, `.
|
|
1046
1093
|
* @since v0.1.5
|
|
1047
1094
|
*/
|
|
1048
1095
|
headers: IncomingHttpHeaders;
|
|
1096
|
+
/**
|
|
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.
|
|
1099
|
+
*
|
|
1100
|
+
* ```js
|
|
1101
|
+
* // Prints something like:
|
|
1102
|
+
* //
|
|
1103
|
+
* // { 'user-agent': ['curl/7.22.0'],
|
|
1104
|
+
* // host: ['127.0.0.1:8000'],
|
|
1105
|
+
* // accept: ['*'] }
|
|
1106
|
+
* console.log(request.headersDistinct);
|
|
1107
|
+
* ```
|
|
1108
|
+
* @since v18.3.0, v16.17.0
|
|
1109
|
+
*/
|
|
1110
|
+
headersDistinct: NodeJS.Dict<string[]>;
|
|
1049
1111
|
/**
|
|
1050
1112
|
* The raw request/response headers list exactly as they were received.
|
|
1051
1113
|
*
|
|
@@ -1076,6 +1138,13 @@ declare module 'http' {
|
|
|
1076
1138
|
* @since v0.3.0
|
|
1077
1139
|
*/
|
|
1078
1140
|
trailers: NodeJS.Dict<string>;
|
|
1141
|
+
/**
|
|
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.
|
|
1144
|
+
* Only populated at the `'end'` event.
|
|
1145
|
+
* @since v18.3.0, v16.17.0
|
|
1146
|
+
*/
|
|
1147
|
+
trailersDistinct: NodeJS.Dict<string[]>;
|
|
1079
1148
|
/**
|
|
1080
1149
|
* The raw request/response trailer keys and values exactly as they were
|
|
1081
1150
|
* received. Only populated at the `'end'` event.
|
|
@@ -1108,14 +1177,14 @@ declare module 'http' {
|
|
|
1108
1177
|
* To parse the URL into its parts:
|
|
1109
1178
|
*
|
|
1110
1179
|
* ```js
|
|
1111
|
-
* new URL(request.url, `http://${request.
|
|
1180
|
+
* new URL(request.url, `http://${request.headers.host}`);
|
|
1112
1181
|
* ```
|
|
1113
1182
|
*
|
|
1114
|
-
* When `request.url` is `'/status?name=ryan'` and`request.
|
|
1183
|
+
* When `request.url` is `'/status?name=ryan'` and `request.headers.host` is`'localhost:3000'`:
|
|
1115
1184
|
*
|
|
1116
1185
|
* ```console
|
|
1117
1186
|
* $ node
|
|
1118
|
-
* > new URL(request.url, `http://${request.
|
|
1187
|
+
* > new URL(request.url, `http://${request.headers.host}`)
|
|
1119
1188
|
* URL {
|
|
1120
1189
|
* href: 'http://localhost:3000/status?name=ryan',
|
|
1121
1190
|
* origin: 'http://localhost:3000',
|
|
@@ -1235,16 +1304,16 @@ declare module 'http' {
|
|
|
1235
1304
|
* hostname: 'localhost',
|
|
1236
1305
|
* port: 80,
|
|
1237
1306
|
* path: '/',
|
|
1238
|
-
* agent: false // Create a new agent just for this one request
|
|
1307
|
+
* agent: false, // Create a new agent just for this one request
|
|
1239
1308
|
* }, (res) => {
|
|
1240
1309
|
* // Do stuff with response
|
|
1241
1310
|
* });
|
|
1242
1311
|
* ```
|
|
1243
1312
|
* @since v0.3.4
|
|
1244
1313
|
*/
|
|
1245
|
-
class Agent {
|
|
1314
|
+
class Agent extends EventEmitter {
|
|
1246
1315
|
/**
|
|
1247
|
-
* By default set to 256
|
|
1316
|
+
* By default set to 256. For agents with `keepAlive` enabled, this
|
|
1248
1317
|
* sets the maximum number of sockets that will be left open in the free
|
|
1249
1318
|
* state.
|
|
1250
1319
|
* @since v0.11.7
|
|
@@ -1340,10 +1409,10 @@ declare module 'http' {
|
|
|
1340
1409
|
* upload a file with a POST request, then write to the `ClientRequest` object.
|
|
1341
1410
|
*
|
|
1342
1411
|
* ```js
|
|
1343
|
-
* const http = require('http');
|
|
1412
|
+
* const http = require('node:http');
|
|
1344
1413
|
*
|
|
1345
1414
|
* const postData = JSON.stringify({
|
|
1346
|
-
* 'msg': 'Hello World!'
|
|
1415
|
+
* 'msg': 'Hello World!',
|
|
1347
1416
|
* });
|
|
1348
1417
|
*
|
|
1349
1418
|
* const options = {
|
|
@@ -1353,8 +1422,8 @@ declare module 'http' {
|
|
|
1353
1422
|
* method: 'POST',
|
|
1354
1423
|
* headers: {
|
|
1355
1424
|
* 'Content-Type': 'application/json',
|
|
1356
|
-
* 'Content-Length': Buffer.byteLength(postData)
|
|
1357
|
-
* }
|
|
1425
|
+
* 'Content-Length': Buffer.byteLength(postData),
|
|
1426
|
+
* },
|
|
1358
1427
|
* };
|
|
1359
1428
|
*
|
|
1360
1429
|
* const req = http.request(options, (res) => {
|
|
@@ -1441,7 +1510,7 @@ declare module 'http' {
|
|
|
1441
1510
|
* * `'data'` any number of times, on the `res` object
|
|
1442
1511
|
* * (connection closed here)
|
|
1443
1512
|
* * `'aborted'` on the `res` object
|
|
1444
|
-
* * `'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'`
|
|
1445
1514
|
* * `'close'`
|
|
1446
1515
|
* * `'close'` on the `res` object
|
|
1447
1516
|
*
|
|
@@ -1449,7 +1518,7 @@ declare module 'http' {
|
|
|
1449
1518
|
* events will be emitted in the following order:
|
|
1450
1519
|
*
|
|
1451
1520
|
* * (`req.destroy()` called here)
|
|
1452
|
-
* * `'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
|
|
1453
1522
|
* * `'close'`
|
|
1454
1523
|
*
|
|
1455
1524
|
* If `req.destroy()` is called before the connection succeeds, the following
|
|
@@ -1457,7 +1526,7 @@ declare module 'http' {
|
|
|
1457
1526
|
*
|
|
1458
1527
|
* * `'socket'`
|
|
1459
1528
|
* * (`req.destroy()` called here)
|
|
1460
|
-
* * `'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
|
|
1461
1530
|
* * `'close'`
|
|
1462
1531
|
*
|
|
1463
1532
|
* If `req.destroy()` is called after the response is received, the following
|
|
@@ -1468,7 +1537,7 @@ declare module 'http' {
|
|
|
1468
1537
|
* * `'data'` any number of times, on the `res` object
|
|
1469
1538
|
* * (`req.destroy()` called here)
|
|
1470
1539
|
* * `'aborted'` on the `res` object
|
|
1471
|
-
* * `'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
|
|
1472
1541
|
* * `'close'`
|
|
1473
1542
|
* * `'close'` on the `res` object
|
|
1474
1543
|
*
|
|
@@ -1504,16 +1573,13 @@ declare module 'http' {
|
|
|
1504
1573
|
* Setting the `timeout` option or using the `setTimeout()` function will
|
|
1505
1574
|
* not abort the request or do anything besides add a `'timeout'` event.
|
|
1506
1575
|
*
|
|
1507
|
-
* Passing an `AbortSignal` and then calling `abort` on the corresponding`AbortController` will behave the same way as calling `.destroy()` on the
|
|
1508
|
-
* 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.
|
|
1509
1579
|
* @since v0.3.6
|
|
1510
1580
|
*/
|
|
1511
1581
|
function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
|
|
1512
|
-
function request(
|
|
1513
|
-
url: string | URL,
|
|
1514
|
-
options: RequestOptions,
|
|
1515
|
-
callback?: (res: IncomingMessage) => void,
|
|
1516
|
-
): ClientRequest;
|
|
1582
|
+
function request(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
|
|
1517
1583
|
/**
|
|
1518
1584
|
* Since most requests are GET requests without bodies, Node.js provides this
|
|
1519
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
|
|
@@ -1565,7 +1631,7 @@ declare module 'http' {
|
|
|
1565
1631
|
* const server = http.createServer((req, res) => {
|
|
1566
1632
|
* res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
1567
1633
|
* res.end(JSON.stringify({
|
|
1568
|
-
* data: 'Hello World!'
|
|
1634
|
+
* data: 'Hello World!',
|
|
1569
1635
|
* }));
|
|
1570
1636
|
* });
|
|
1571
1637
|
*
|
|
@@ -1576,25 +1642,76 @@ declare module 'http' {
|
|
|
1576
1642
|
*/
|
|
1577
1643
|
function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
|
|
1578
1644
|
function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
|
|
1579
|
-
|
|
1580
1645
|
/**
|
|
1581
|
-
* Performs the low-level validations on the provided name that are done when
|
|
1582
|
-
*
|
|
1583
|
-
*
|
|
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
|
+
* ```
|
|
1584
1668
|
* @since v14.3.0
|
|
1669
|
+
* @param [label='Header name'] Label for error message.
|
|
1585
1670
|
*/
|
|
1586
1671
|
function validateHeaderName(name: string): void;
|
|
1587
1672
|
/**
|
|
1588
|
-
* Performs the low-level validations on the provided value that are done when
|
|
1589
|
-
*
|
|
1590
|
-
*
|
|
1591
|
-
*
|
|
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
|
|
1592
1705
|
* @param name Header name
|
|
1593
1706
|
* @param value Header value
|
|
1594
|
-
* @since v14.3.0
|
|
1595
1707
|
*/
|
|
1596
1708
|
function validateHeaderValue(name: string, value: string): void;
|
|
1597
|
-
|
|
1709
|
+
/**
|
|
1710
|
+
* Set the maximum number of idle HTTP parsers.
|
|
1711
|
+
* @since v18.8.0, v16.18.0
|
|
1712
|
+
* @param [max=1000]
|
|
1713
|
+
*/
|
|
1714
|
+
function setMaxIdleHTTPParsers(max: number): void;
|
|
1598
1715
|
let globalAgent: Agent;
|
|
1599
1716
|
/**
|
|
1600
1717
|
* Read-only property specifying the maximum allowed size of HTTP headers in bytes.
|