@types/node 18.7.17 → 18.7.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. node/README.md +1 -1
  2. node/globals.d.ts +1 -0
  3. node/index.d.ts +1 -1
  4. node/package.json +9 -2
  5. node/path.d.ts +2 -2
  6. node/ts4.8/assert/strict.d.ts +8 -0
  7. node/ts4.8/assert.d.ts +911 -0
  8. node/ts4.8/async_hooks.d.ts +501 -0
  9. node/ts4.8/buffer.d.ts +2238 -0
  10. node/ts4.8/child_process.d.ts +1369 -0
  11. node/ts4.8/cluster.d.ts +410 -0
  12. node/ts4.8/console.d.ts +412 -0
  13. node/ts4.8/constants.d.ts +18 -0
  14. node/ts4.8/crypto.d.ts +3961 -0
  15. node/ts4.8/dgram.d.ts +545 -0
  16. node/ts4.8/diagnostics_channel.d.ts +153 -0
  17. node/ts4.8/dns/promises.d.ts +370 -0
  18. node/ts4.8/dns.d.ts +659 -0
  19. node/ts4.8/domain.d.ts +170 -0
  20. node/ts4.8/events.d.ts +641 -0
  21. node/ts4.8/fs/promises.d.ts +1120 -0
  22. node/ts4.8/fs.d.ts +3872 -0
  23. node/ts4.8/globals.d.ts +294 -0
  24. node/ts4.8/globals.global.d.ts +1 -0
  25. node/ts4.8/http.d.ts +1553 -0
  26. node/ts4.8/http2.d.ts +2106 -0
  27. node/ts4.8/https.d.ts +541 -0
  28. node/ts4.8/index.d.ts +87 -0
  29. node/ts4.8/inspector.d.ts +2741 -0
  30. node/ts4.8/module.d.ts +114 -0
  31. node/ts4.8/net.d.ts +838 -0
  32. node/ts4.8/os.d.ts +465 -0
  33. node/ts4.8/path.d.ts +191 -0
  34. node/ts4.8/perf_hooks.d.ts +610 -0
  35. node/ts4.8/process.d.ts +1482 -0
  36. node/ts4.8/punycode.d.ts +117 -0
  37. node/ts4.8/querystring.d.ts +131 -0
  38. node/ts4.8/readline/promises.d.ts +143 -0
  39. node/ts4.8/readline.d.ts +653 -0
  40. node/ts4.8/repl.d.ts +424 -0
  41. node/ts4.8/stream/consumers.d.ts +24 -0
  42. node/ts4.8/stream/promises.d.ts +42 -0
  43. node/ts4.8/stream/web.d.ts +330 -0
  44. node/ts4.8/stream.d.ts +1339 -0
  45. node/ts4.8/string_decoder.d.ts +67 -0
  46. node/ts4.8/test.d.ts +190 -0
  47. node/ts4.8/timers/promises.d.ts +68 -0
  48. node/ts4.8/timers.d.ts +94 -0
  49. node/ts4.8/tls.d.ts +1028 -0
  50. node/ts4.8/trace_events.d.ts +171 -0
  51. node/ts4.8/tty.d.ts +206 -0
  52. node/ts4.8/url.d.ts +897 -0
  53. node/ts4.8/util.d.ts +1792 -0
  54. node/ts4.8/v8.d.ts +396 -0
  55. node/ts4.8/vm.d.ts +509 -0
  56. node/ts4.8/wasi.d.ts +158 -0
  57. node/ts4.8/worker_threads.d.ts +646 -0
  58. node/ts4.8/zlib.d.ts +517 -0
node/ts4.8/http.d.ts ADDED
@@ -0,0 +1,1553 @@
1
+ /**
2
+ * To use the HTTP server and client one must `require('http')`.
3
+ *
4
+ * The HTTP interfaces in Node.js are designed to support many features
5
+ * of the protocol which have been traditionally difficult to use.
6
+ * In particular, large, possibly chunk-encoded, messages. The interface is
7
+ * careful to never buffer entire requests or responses, so the
8
+ * user is able to stream data.
9
+ *
10
+ * HTTP message headers are represented by an object like this:
11
+ *
12
+ * ```js
13
+ * { 'content-length': '123',
14
+ * 'content-type': 'text/plain',
15
+ * 'connection': 'keep-alive',
16
+ * 'host': 'example.com',
17
+ * 'accept': '*' }
18
+ * ```
19
+ *
20
+ * Keys are lowercased. Values are not modified.
21
+ *
22
+ * In order to support the full spectrum of possible HTTP applications, the Node.js
23
+ * HTTP API is very low-level. It deals with stream handling and message
24
+ * parsing only. It parses a message into headers and body but it does not
25
+ * parse the actual headers or the body.
26
+ *
27
+ * See `message.headers` for details on how duplicate headers are handled.
28
+ *
29
+ * The raw headers as they were received are retained in the `rawHeaders`property, which is an array of `[key, value, key2, value2, ...]`. For
30
+ * example, the previous message header object might have a `rawHeaders`list like the following:
31
+ *
32
+ * ```js
33
+ * [ 'ConTent-Length', '123456',
34
+ * 'content-LENGTH', '123',
35
+ * 'content-type', 'text/plain',
36
+ * 'CONNECTION', 'keep-alive',
37
+ * 'Host', 'example.com',
38
+ * 'accepT', '*' ]
39
+ * ```
40
+ * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/http.js)
41
+ */
42
+ declare module 'http' {
43
+ import * as stream from 'node:stream';
44
+ import { URL } from 'node:url';
45
+ import { TcpSocketConnectOpts, Socket, Server as NetServer, LookupFunction } from 'node:net';
46
+ // incoming headers will never contain number
47
+ interface IncomingHttpHeaders extends NodeJS.Dict<string | string[]> {
48
+ accept?: string | undefined;
49
+ 'accept-language'?: string | undefined;
50
+ 'accept-patch'?: string | undefined;
51
+ 'accept-ranges'?: string | undefined;
52
+ 'access-control-allow-credentials'?: string | undefined;
53
+ 'access-control-allow-headers'?: string | undefined;
54
+ 'access-control-allow-methods'?: string | undefined;
55
+ 'access-control-allow-origin'?: string | undefined;
56
+ 'access-control-expose-headers'?: string | undefined;
57
+ 'access-control-max-age'?: string | undefined;
58
+ 'access-control-request-headers'?: string | undefined;
59
+ 'access-control-request-method'?: string | undefined;
60
+ age?: string | undefined;
61
+ allow?: string | undefined;
62
+ 'alt-svc'?: string | undefined;
63
+ authorization?: string | undefined;
64
+ 'cache-control'?: string | undefined;
65
+ connection?: string | undefined;
66
+ 'content-disposition'?: string | undefined;
67
+ 'content-encoding'?: string | undefined;
68
+ 'content-language'?: string | undefined;
69
+ 'content-length'?: string | undefined;
70
+ 'content-location'?: string | undefined;
71
+ 'content-range'?: string | undefined;
72
+ 'content-type'?: string | undefined;
73
+ cookie?: string | undefined;
74
+ date?: string | undefined;
75
+ etag?: string | undefined;
76
+ expect?: string | undefined;
77
+ expires?: string | undefined;
78
+ forwarded?: string | undefined;
79
+ from?: string | undefined;
80
+ host?: string | undefined;
81
+ 'if-match'?: string | undefined;
82
+ 'if-modified-since'?: string | undefined;
83
+ 'if-none-match'?: string | undefined;
84
+ 'if-unmodified-since'?: string | undefined;
85
+ 'last-modified'?: string | undefined;
86
+ location?: string | undefined;
87
+ origin?: string | undefined;
88
+ pragma?: string | undefined;
89
+ 'proxy-authenticate'?: string | undefined;
90
+ 'proxy-authorization'?: string | undefined;
91
+ 'public-key-pins'?: string | undefined;
92
+ range?: string | undefined;
93
+ referer?: string | undefined;
94
+ 'retry-after'?: string | undefined;
95
+ 'sec-websocket-accept'?: string | undefined;
96
+ 'sec-websocket-extensions'?: string | undefined;
97
+ 'sec-websocket-key'?: string | undefined;
98
+ 'sec-websocket-protocol'?: string | undefined;
99
+ 'sec-websocket-version'?: string | undefined;
100
+ 'set-cookie'?: string[] | undefined;
101
+ 'strict-transport-security'?: string | undefined;
102
+ tk?: string | undefined;
103
+ trailer?: string | undefined;
104
+ 'transfer-encoding'?: string | undefined;
105
+ upgrade?: string | undefined;
106
+ 'user-agent'?: string | undefined;
107
+ vary?: string | undefined;
108
+ via?: string | undefined;
109
+ warning?: string | undefined;
110
+ 'www-authenticate'?: string | undefined;
111
+ }
112
+ // outgoing headers allows numbers (as they are converted internally to strings)
113
+ type OutgoingHttpHeader = number | string | string[];
114
+ interface OutgoingHttpHeaders extends NodeJS.Dict<OutgoingHttpHeader> {}
115
+ interface ClientRequestArgs {
116
+ signal?: AbortSignal | undefined;
117
+ protocol?: string | null | undefined;
118
+ host?: string | null | undefined;
119
+ hostname?: string | null | undefined;
120
+ family?: number | undefined;
121
+ port?: number | string | null | undefined;
122
+ defaultPort?: number | string | undefined;
123
+ localAddress?: string | undefined;
124
+ socketPath?: string | undefined;
125
+ /**
126
+ * @default 8192
127
+ */
128
+ maxHeaderSize?: number | undefined;
129
+ method?: string | undefined;
130
+ path?: string | null | undefined;
131
+ headers?: OutgoingHttpHeaders | undefined;
132
+ auth?: string | null | undefined;
133
+ agent?: Agent | boolean | undefined;
134
+ _defaultAgent?: Agent | undefined;
135
+ timeout?: number | undefined;
136
+ setHost?: boolean | undefined;
137
+ // https://github.com/nodejs/node/blob/master/lib/_http_client.js#L278
138
+ createConnection?:
139
+ | ((options: ClientRequestArgs, oncreate: (err: Error, socket: Socket) => void) => Socket)
140
+ | undefined;
141
+ lookup?: LookupFunction | undefined;
142
+ }
143
+ interface ServerOptions<
144
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
145
+ Response extends typeof ServerResponse = typeof ServerResponse,
146
+ > {
147
+ IncomingMessage?: Request | undefined;
148
+ ServerResponse?: Response | undefined;
149
+ /**
150
+ * Optionally overrides the value of
151
+ * `--max-http-header-size` for requests received by this server, i.e.
152
+ * the maximum length of request headers in bytes.
153
+ * @default 8192
154
+ */
155
+ maxHeaderSize?: number | undefined;
156
+ /**
157
+ * Use an insecure HTTP parser that accepts invalid HTTP headers when true.
158
+ * Using the insecure parser should be avoided.
159
+ * See --insecure-http-parser for more information.
160
+ * @default false
161
+ */
162
+ insecureHTTPParser?: boolean | undefined;
163
+ /**
164
+ * If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.
165
+ * @default false
166
+ * @since v16.5.0
167
+ */
168
+ noDelay?: boolean | undefined;
169
+ /**
170
+ * If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received,
171
+ * similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`.
172
+ * @default false
173
+ * @since v16.5.0
174
+ */
175
+ keepAlive?: boolean | undefined;
176
+ /**
177
+ * If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket.
178
+ * @default 0
179
+ * @since v16.5.0
180
+ */
181
+ keepAliveInitialDelay?: number | undefined;
182
+ }
183
+ type RequestListener<
184
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
185
+ Response extends typeof ServerResponse = typeof ServerResponse,
186
+ > = (req: InstanceType<Request>, res: InstanceType<Response> & { req: InstanceType<Request> }) => void;
187
+ /**
188
+ * @since v0.1.17
189
+ */
190
+ class Server<
191
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
192
+ Response extends typeof ServerResponse = typeof ServerResponse,
193
+ > extends NetServer {
194
+ constructor(requestListener?: RequestListener<Request, Response>);
195
+ constructor(options: ServerOptions<Request, Response>, requestListener?: RequestListener<Request, Response>);
196
+ /**
197
+ * Sets the timeout value for sockets, and emits a `'timeout'` event on
198
+ * the Server object, passing the socket as an argument, if a timeout
199
+ * occurs.
200
+ *
201
+ * If there is a `'timeout'` event listener on the Server object, then it
202
+ * will be called with the timed-out socket as an argument.
203
+ *
204
+ * By default, the Server does not timeout sockets. However, if a callback
205
+ * is assigned to the Server's `'timeout'` event, timeouts must be handled
206
+ * explicitly.
207
+ * @since v0.9.12
208
+ * @param [msecs=0 (no timeout)]
209
+ */
210
+ setTimeout(msecs?: number, callback?: () => void): this;
211
+ setTimeout(callback: () => void): this;
212
+ /**
213
+ * Limits maximum incoming headers count. If set to 0, no limit will be applied.
214
+ * @since v0.7.0
215
+ */
216
+ maxHeadersCount: number | null;
217
+ /**
218
+ * The maximum number of requests socket can handle
219
+ * before closing keep alive connection.
220
+ *
221
+ * A value of `0` will disable the limit.
222
+ *
223
+ * When the limit is reached it will set the `Connection` header value to `close`,
224
+ * but will not actually close the connection, subsequent requests sent
225
+ * after the limit is reached will get `503 Service Unavailable` as a response.
226
+ * @since v16.10.0
227
+ */
228
+ maxRequestsPerSocket: number | null;
229
+ /**
230
+ * The number of milliseconds of inactivity before a socket is presumed
231
+ * to have timed out.
232
+ *
233
+ * A value of `0` will disable the timeout behavior on incoming connections.
234
+ *
235
+ * The socket timeout logic is set up on connection, so changing this
236
+ * value only affects new connections to the server, not any existing connections.
237
+ * @since v0.9.12
238
+ */
239
+ timeout: number;
240
+ /**
241
+ * Limit the amount of time the parser will wait to receive the complete HTTP
242
+ * headers.
243
+ *
244
+ * If the timeout expires, the server responds with status 408 without
245
+ * forwarding the request to the request listener and then closes the connection.
246
+ *
247
+ * It must be set to a non-zero value (e.g. 120 seconds) to protect against
248
+ * potential Denial-of-Service attacks in case the server is deployed without a
249
+ * reverse proxy in front.
250
+ * @since v11.3.0, v10.14.0
251
+ */
252
+ headersTimeout: number;
253
+ /**
254
+ * The number of milliseconds of inactivity a server needs to wait for additional
255
+ * incoming data, after it has finished writing the last response, before a socket
256
+ * will be destroyed. If the server receives new data before the keep-alive
257
+ * timeout has fired, it will reset the regular inactivity timeout, i.e.,`server.timeout`.
258
+ *
259
+ * A value of `0` will disable the keep-alive timeout behavior on incoming
260
+ * connections.
261
+ * A value of `0` makes the http server behave similarly to Node.js versions prior
262
+ * to 8.0.0, which did not have a keep-alive timeout.
263
+ *
264
+ * The socket timeout logic is set up on connection, so changing this value only
265
+ * affects new connections to the server, not any existing connections.
266
+ * @since v8.0.0
267
+ */
268
+ keepAliveTimeout: number;
269
+ /**
270
+ * Sets the timeout value in milliseconds for receiving the entire request from
271
+ * the client.
272
+ *
273
+ * If the timeout expires, the server responds with status 408 without
274
+ * forwarding the request to the request listener and then closes the connection.
275
+ *
276
+ * It must be set to a non-zero value (e.g. 120 seconds) to protect against
277
+ * potential Denial-of-Service attacks in case the server is deployed without a
278
+ * reverse proxy in front.
279
+ * @since v14.11.0
280
+ */
281
+ requestTimeout: number;
282
+ /**
283
+ * Closes all connections connected to this server.
284
+ * @since v18.2.0
285
+ */
286
+ closeAllConnections(): void;
287
+ /**
288
+ * Closes all connections connected to this server which are not sending a request or waiting for a response.
289
+ * @since v18.2.0
290
+ */
291
+ closeIdleConnections(): void;
292
+ addListener(event: string, listener: (...args: any[]) => void): this;
293
+ addListener(event: 'close', listener: () => void): this;
294
+ addListener(event: 'connection', listener: (socket: Socket) => void): this;
295
+ addListener(event: 'error', listener: (err: Error) => void): this;
296
+ addListener(event: 'listening', listener: () => void): this;
297
+ addListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
298
+ addListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
299
+ addListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
300
+ addListener(
301
+ event: 'connect',
302
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
303
+ ): this;
304
+ addListener(event: 'request', listener: RequestListener<Request, Response>): this;
305
+ addListener(
306
+ event: 'upgrade',
307
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
308
+ ): this;
309
+ emit(event: string, ...args: any[]): boolean;
310
+ emit(event: 'close'): boolean;
311
+ emit(event: 'connection', socket: Socket): boolean;
312
+ emit(event: 'error', err: Error): boolean;
313
+ emit(event: 'listening'): boolean;
314
+ emit(
315
+ event: 'checkContinue',
316
+ req: InstanceType<Request>,
317
+ res: InstanceType<Response> & { req: InstanceType<Request> },
318
+ ): boolean;
319
+ emit(
320
+ event: 'checkExpectation',
321
+ req: InstanceType<Request>,
322
+ res: InstanceType<Response> & { req: InstanceType<Request> },
323
+ ): boolean;
324
+ emit(event: 'clientError', err: Error, socket: stream.Duplex): boolean;
325
+ emit(event: 'connect', req: InstanceType<Request>, socket: stream.Duplex, head: Buffer): boolean;
326
+ emit(
327
+ event: 'request',
328
+ req: InstanceType<Request>,
329
+ res: InstanceType<Response> & { req: InstanceType<Request> },
330
+ ): boolean;
331
+ emit(event: 'upgrade', req: InstanceType<Request>, socket: stream.Duplex, head: Buffer): boolean;
332
+ on(event: string, listener: (...args: any[]) => void): this;
333
+ on(event: 'close', listener: () => void): this;
334
+ on(event: 'connection', listener: (socket: Socket) => void): this;
335
+ on(event: 'error', listener: (err: Error) => void): this;
336
+ on(event: 'listening', listener: () => void): this;
337
+ on(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
338
+ on(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
339
+ on(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
340
+ on(event: 'connect', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
341
+ on(event: 'request', listener: RequestListener<Request, Response>): this;
342
+ on(event: 'upgrade', listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;
343
+ once(event: string, listener: (...args: any[]) => void): this;
344
+ once(event: 'close', listener: () => void): this;
345
+ once(event: 'connection', listener: (socket: Socket) => void): this;
346
+ once(event: 'error', listener: (err: Error) => void): this;
347
+ once(event: 'listening', listener: () => void): this;
348
+ once(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
349
+ once(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
350
+ once(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
351
+ once(
352
+ event: 'connect',
353
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
354
+ ): this;
355
+ once(event: 'request', listener: RequestListener<Request, Response>): this;
356
+ once(
357
+ event: 'upgrade',
358
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
359
+ ): this;
360
+ prependListener(event: string, listener: (...args: any[]) => void): this;
361
+ prependListener(event: 'close', listener: () => void): this;
362
+ prependListener(event: 'connection', listener: (socket: Socket) => void): this;
363
+ prependListener(event: 'error', listener: (err: Error) => void): this;
364
+ prependListener(event: 'listening', listener: () => void): this;
365
+ prependListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
366
+ prependListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
367
+ prependListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
368
+ prependListener(
369
+ event: 'connect',
370
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
371
+ ): this;
372
+ prependListener(event: 'request', listener: RequestListener<Request, Response>): this;
373
+ prependListener(
374
+ event: 'upgrade',
375
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
376
+ ): this;
377
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
378
+ prependOnceListener(event: 'close', listener: () => void): this;
379
+ prependOnceListener(event: 'connection', listener: (socket: Socket) => void): this;
380
+ prependOnceListener(event: 'error', listener: (err: Error) => void): this;
381
+ prependOnceListener(event: 'listening', listener: () => void): this;
382
+ prependOnceListener(event: 'checkContinue', listener: RequestListener<Request, Response>): this;
383
+ prependOnceListener(event: 'checkExpectation', listener: RequestListener<Request, Response>): this;
384
+ prependOnceListener(event: 'clientError', listener: (err: Error, socket: stream.Duplex) => void): this;
385
+ prependOnceListener(
386
+ event: 'connect',
387
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
388
+ ): this;
389
+ prependOnceListener(event: 'request', listener: RequestListener<Request, Response>): this;
390
+ prependOnceListener(
391
+ event: 'upgrade',
392
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,
393
+ ): this;
394
+ }
395
+ /**
396
+ * This class serves as the parent class of {@link ClientRequest} and {@link ServerResponse}. It is an abstract of outgoing message from
397
+ * the perspective of the participants of HTTP transaction.
398
+ * @since v0.1.17
399
+ */
400
+ class OutgoingMessage<Request extends IncomingMessage = IncomingMessage> extends stream.Writable {
401
+ readonly req: Request;
402
+ chunkedEncoding: boolean;
403
+ shouldKeepAlive: boolean;
404
+ useChunkedEncodingByDefault: boolean;
405
+ sendDate: boolean;
406
+ /**
407
+ * @deprecated Use `writableEnded` instead.
408
+ */
409
+ finished: boolean;
410
+ /**
411
+ * Read-only. `true` if the headers were sent, otherwise `false`.
412
+ * @since v0.9.3
413
+ */
414
+ readonly headersSent: boolean;
415
+ /**
416
+ * Aliases of `outgoingMessage.socket`
417
+ * @since v0.3.0
418
+ * @deprecated Since v15.12.0,v14.17.1 - Use `socket` instead.
419
+ */
420
+ readonly connection: Socket | null;
421
+ /**
422
+ * Reference to the underlying socket. Usually, users will not want to access
423
+ * this property.
424
+ *
425
+ * After calling `outgoingMessage.end()`, this property will be nulled.
426
+ * @since v0.3.0
427
+ */
428
+ readonly socket: Socket | null;
429
+ constructor();
430
+ /**
431
+ * Once a socket is associated with the message and is connected,`socket.setTimeout()` will be called with `msecs` as the first parameter.
432
+ * @since v0.9.12
433
+ * @param callback Optional function to be called when a timeout occurs. Same as binding to the `timeout` event.
434
+ */
435
+ setTimeout(msecs: number, callback?: () => void): this;
436
+ /**
437
+ * Sets a single header value for the header object.
438
+ * @since v0.4.0
439
+ * @param name Header name
440
+ * @param value Header value
441
+ */
442
+ setHeader(name: string, value: number | string | ReadonlyArray<string>): this;
443
+ /**
444
+ * Gets the value of HTTP header with the given name. If such a name doesn't
445
+ * exist in message, it will be `undefined`.
446
+ * @since v0.4.0
447
+ * @param name Name of header
448
+ */
449
+ getHeader(name: string): number | string | string[] | undefined;
450
+ /**
451
+ * Returns a shallow copy of the current outgoing headers. Since a shallow
452
+ * copy is used, array values may be mutated without additional calls to
453
+ * various header-related HTTP module methods. The keys of the returned
454
+ * object are the header names and the values are the respective header
455
+ * values. All header names are lowercase.
456
+ *
457
+ * The object returned by the `outgoingMessage.getHeaders()` method does
458
+ * not prototypically inherit from the JavaScript Object. This means that
459
+ * typical Object methods such as `obj.toString()`, `obj.hasOwnProperty()`,
460
+ * and others are not defined and will not work.
461
+ *
462
+ * ```js
463
+ * outgoingMessage.setHeader('Foo', 'bar');
464
+ * outgoingMessage.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
465
+ *
466
+ * const headers = outgoingMessage.getHeaders();
467
+ * // headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }
468
+ * ```
469
+ * @since v7.7.0
470
+ */
471
+ getHeaders(): OutgoingHttpHeaders;
472
+ /**
473
+ * Returns an array of names of headers of the outgoing outgoingMessage. All
474
+ * names are lowercase.
475
+ * @since v7.7.0
476
+ */
477
+ getHeaderNames(): string[];
478
+ /**
479
+ * Returns `true` if the header identified by `name` is currently set in the
480
+ * outgoing headers. The header name is case-insensitive.
481
+ *
482
+ * ```js
483
+ * const hasContentType = outgoingMessage.hasHeader('content-type');
484
+ * ```
485
+ * @since v7.7.0
486
+ */
487
+ hasHeader(name: string): boolean;
488
+ /**
489
+ * Removes a header that is queued for implicit sending.
490
+ *
491
+ * ```js
492
+ * outgoingMessage.removeHeader('Content-Encoding');
493
+ * ```
494
+ * @since v0.4.0
495
+ * @param name Header name
496
+ */
497
+ removeHeader(name: string): void;
498
+ /**
499
+ * Adds HTTP trailers (headers but at the end of the message) to the message.
500
+ *
501
+ * Trailers are **only** be emitted if the message is chunked encoded. If not,
502
+ * the trailer will be silently discarded.
503
+ *
504
+ * HTTP requires the `Trailer` header to be sent to emit trailers,
505
+ * with a list of header fields in its value, e.g.
506
+ *
507
+ * ```js
508
+ * message.writeHead(200, { 'Content-Type': 'text/plain',
509
+ * 'Trailer': 'Content-MD5' });
510
+ * message.write(fileData);
511
+ * message.addTrailers({ 'Content-MD5': '7895bf4b8828b55ceaf47747b4bca667' });
512
+ * message.end();
513
+ * ```
514
+ *
515
+ * Attempting to set a header field name or value that contains invalid characters
516
+ * will result in a `TypeError` being thrown.
517
+ * @since v0.3.0
518
+ */
519
+ addTrailers(headers: OutgoingHttpHeaders | ReadonlyArray<[string, string]>): void;
520
+ /**
521
+ * Compulsorily flushes the message headers
522
+ *
523
+ * For efficiency reason, Node.js normally buffers the message headers
524
+ * until `outgoingMessage.end()` is called or the first chunk of message data
525
+ * is written. It then tries to pack the headers and data into a single TCP
526
+ * packet.
527
+ *
528
+ * 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 request.
530
+ * @since v1.6.0
531
+ */
532
+ flushHeaders(): void;
533
+ }
534
+ /**
535
+ * This object is created internally by an HTTP server, not by the user. It is
536
+ * passed as the second parameter to the `'request'` event.
537
+ * @since v0.1.17
538
+ */
539
+ class ServerResponse<Request extends IncomingMessage = IncomingMessage> extends OutgoingMessage<Request> {
540
+ /**
541
+ * When using implicit headers (not calling `response.writeHead()` explicitly),
542
+ * this property controls the status code that will be sent to the client when
543
+ * the headers get flushed.
544
+ *
545
+ * ```js
546
+ * response.statusCode = 404;
547
+ * ```
548
+ *
549
+ * After response header was sent to the client, this property indicates the
550
+ * status code which was sent out.
551
+ * @since v0.4.0
552
+ */
553
+ statusCode: number;
554
+ /**
555
+ * When using implicit headers (not calling `response.writeHead()` explicitly),
556
+ * this property controls the status message that will be sent to the client when
557
+ * the headers get flushed. If this is left as `undefined` then the standard
558
+ * message for the status code will be used.
559
+ *
560
+ * ```js
561
+ * response.statusMessage = 'Not found';
562
+ * ```
563
+ *
564
+ * After response header was sent to the client, this property indicates the
565
+ * status message which was sent out.
566
+ * @since v0.11.8
567
+ */
568
+ statusMessage: string;
569
+ constructor(req: Request);
570
+ assignSocket(socket: Socket): void;
571
+ detachSocket(socket: Socket): void;
572
+ /**
573
+ * Sends a HTTP/1.1 100 Continue message to the client, indicating that
574
+ * the request body should be sent. See the `'checkContinue'` event on`Server`.
575
+ * @since v0.3.0
576
+ */
577
+ writeContinue(callback?: () => void): void;
578
+ /**
579
+ * Sends a response header to the request. The status code is a 3-digit HTTP
580
+ * status code, like `404`. The last argument, `headers`, are the response headers.
581
+ * Optionally one can give a human-readable `statusMessage` as the second
582
+ * argument.
583
+ *
584
+ * `headers` may be an `Array` where the keys and values are in the same list.
585
+ * It is _not_ a list of tuples. So, the even-numbered offsets are key values,
586
+ * and the odd-numbered offsets are the associated values. The array is in the same
587
+ * format as `request.rawHeaders`.
588
+ *
589
+ * Returns a reference to the `ServerResponse`, so that calls can be chained.
590
+ *
591
+ * ```js
592
+ * const body = 'hello world';
593
+ * response
594
+ * .writeHead(200, {
595
+ * 'Content-Length': Buffer.byteLength(body),
596
+ * 'Content-Type': 'text/plain'
597
+ * })
598
+ * .end(body);
599
+ * ```
600
+ *
601
+ * This method must only be called once on a message and it must
602
+ * be called before `response.end()` is called.
603
+ *
604
+ * If `response.write()` or `response.end()` are called before calling
605
+ * this, the implicit/mutable headers will be calculated and call this function.
606
+ *
607
+ * When headers have been set with `response.setHeader()`, they will be merged
608
+ * with any headers passed to `response.writeHead()`, with the headers passed
609
+ * to `response.writeHead()` given precedence.
610
+ *
611
+ * If this method is called and `response.setHeader()` has not been called,
612
+ * it will directly write the supplied header values onto the network channel
613
+ * without caching internally, and the `response.getHeader()` on the header
614
+ * will not yield the expected result. If progressive population of headers is
615
+ * desired with potential future retrieval and modification, use `response.setHeader()` instead.
616
+ *
617
+ * ```js
618
+ * // Returns content-type = text/plain
619
+ * const server = http.createServer((req, res) => {
620
+ * res.setHeader('Content-Type', 'text/html');
621
+ * res.setHeader('X-Foo', 'bar');
622
+ * res.writeHead(200, { 'Content-Type': 'text/plain' });
623
+ * res.end('ok');
624
+ * });
625
+ * ```
626
+ *
627
+ * `Content-Length` is given in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes. Node.js
628
+ * does not check whether `Content-Length` and the length of the body which has
629
+ * been transmitted are equal or not.
630
+ *
631
+ * Attempting to set a header field name or value that contains invalid characters
632
+ * will result in a `TypeError` being thrown.
633
+ * @since v0.1.30
634
+ */
635
+ writeHead(
636
+ statusCode: number,
637
+ statusMessage?: string,
638
+ headers?: OutgoingHttpHeaders | OutgoingHttpHeader[],
639
+ ): this;
640
+ writeHead(statusCode: number, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[]): this;
641
+ /**
642
+ * Sends a HTTP/1.1 102 Processing message to the client, indicating that
643
+ * the request body should be sent.
644
+ * @since v10.0.0
645
+ */
646
+ writeProcessing(): void;
647
+ }
648
+ interface InformationEvent {
649
+ statusCode: number;
650
+ statusMessage: string;
651
+ httpVersion: string;
652
+ httpVersionMajor: number;
653
+ httpVersionMinor: number;
654
+ headers: IncomingHttpHeaders;
655
+ rawHeaders: string[];
656
+ }
657
+ /**
658
+ * This object is created internally and returned from {@link request}. It
659
+ * represents an _in-progress_ request whose header has already been queued. The
660
+ * header is still mutable using the `setHeader(name, value)`,`getHeader(name)`, `removeHeader(name)` API. The actual header will
661
+ * be sent along with the first data chunk or when calling `request.end()`.
662
+ *
663
+ * To get the response, add a listener for `'response'` to the request object.`'response'` will be emitted from the request object when the response
664
+ * headers have been received. The `'response'` event is executed with one
665
+ * argument which is an instance of {@link IncomingMessage}.
666
+ *
667
+ * During the `'response'` event, one can add listeners to the
668
+ * response object; particularly to listen for the `'data'` event.
669
+ *
670
+ * If no `'response'` handler is added, then the response will be
671
+ * entirely discarded. However, if a `'response'` event handler is added,
672
+ * then the data from the response object **must** be consumed, either by
673
+ * calling `response.read()` whenever there is a `'readable'` event, or
674
+ * by adding a `'data'` handler, or by calling the `.resume()` method.
675
+ * Until the data is consumed, the `'end'` event will not fire. Also, until
676
+ * the data is read it will consume memory that can eventually lead to a
677
+ * 'process out of memory' error.
678
+ *
679
+ * For backward compatibility, `res` will only emit `'error'` if there is an`'error'` listener registered.
680
+ *
681
+ * Node.js does not check whether Content-Length and the length of the
682
+ * body which has been transmitted are equal or not.
683
+ * @since v0.1.17
684
+ */
685
+ class ClientRequest extends OutgoingMessage {
686
+ /**
687
+ * The `request.aborted` property will be `true` if the request has
688
+ * been aborted.
689
+ * @since v0.11.14
690
+ * @deprecated Since v17.0.0,v16.12.0 - Check `destroyed` instead.
691
+ */
692
+ aborted: boolean;
693
+ /**
694
+ * The request host.
695
+ * @since v14.5.0, v12.19.0
696
+ */
697
+ host: string;
698
+ /**
699
+ * The request protocol.
700
+ * @since v14.5.0, v12.19.0
701
+ */
702
+ protocol: string;
703
+ /**
704
+ * When sending request through a keep-alive enabled agent, the underlying socket
705
+ * might be reused. But if server closes connection at unfortunate time, client
706
+ * may run into a 'ECONNRESET' error.
707
+ *
708
+ * ```js
709
+ * const http = require('http');
710
+ *
711
+ * // Server has a 5 seconds keep-alive timeout by default
712
+ * http
713
+ * .createServer((req, res) => {
714
+ * res.write('hello\n');
715
+ * res.end();
716
+ * })
717
+ * .listen(3000);
718
+ *
719
+ * setInterval(() => {
720
+ * // Adapting a keep-alive agent
721
+ * http.get('http://localhost:3000', { agent }, (res) => {
722
+ * res.on('data', (data) => {
723
+ * // Do nothing
724
+ * });
725
+ * });
726
+ * }, 5000); // Sending request on 5s interval so it's easy to hit idle timeout
727
+ * ```
728
+ *
729
+ * By marking a request whether it reused socket or not, we can do
730
+ * automatic error retry base on it.
731
+ *
732
+ * ```js
733
+ * const http = require('http');
734
+ * const agent = new http.Agent({ keepAlive: true });
735
+ *
736
+ * function retriableRequest() {
737
+ * const req = http
738
+ * .get('http://localhost:3000', { agent }, (res) => {
739
+ * // ...
740
+ * })
741
+ * .on('error', (err) => {
742
+ * // Check if retry is needed
743
+ * if (req.reusedSocket &#x26;&#x26; err.code === 'ECONNRESET') {
744
+ * retriableRequest();
745
+ * }
746
+ * });
747
+ * }
748
+ *
749
+ * retriableRequest();
750
+ * ```
751
+ * @since v13.0.0, v12.16.0
752
+ */
753
+ reusedSocket: boolean;
754
+ /**
755
+ * Limits maximum response headers count. If set to 0, no limit will be applied.
756
+ */
757
+ maxHeadersCount: number;
758
+ constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void);
759
+ /**
760
+ * The request method.
761
+ * @since v0.1.97
762
+ */
763
+ method: string;
764
+ /**
765
+ * The request path.
766
+ * @since v0.4.0
767
+ */
768
+ path: string;
769
+ /**
770
+ * Marks the request as aborting. Calling this will cause remaining data
771
+ * in the response to be dropped and the socket to be destroyed.
772
+ * @since v0.3.8
773
+ * @deprecated Since v14.1.0,v13.14.0 - Use `destroy` instead.
774
+ */
775
+ abort(): void;
776
+ onSocket(socket: Socket): void;
777
+ /**
778
+ * Once a socket is assigned to this request and is connected `socket.setTimeout()` will be called.
779
+ * @since v0.5.9
780
+ * @param timeout Milliseconds before a request times out.
781
+ * @param callback Optional function to be called when a timeout occurs. Same as binding to the `'timeout'` event.
782
+ */
783
+ setTimeout(timeout: number, callback?: () => void): this;
784
+ /**
785
+ * Once a socket is assigned to this request and is connected `socket.setNoDelay()` will be called.
786
+ * @since v0.5.9
787
+ */
788
+ setNoDelay(noDelay?: boolean): void;
789
+ /**
790
+ * Once a socket is assigned to this request and is connected `socket.setKeepAlive()` will be called.
791
+ * @since v0.5.9
792
+ */
793
+ setSocketKeepAlive(enable?: boolean, initialDelay?: number): void;
794
+ /**
795
+ * Returns an array containing the unique names of the current outgoing raw
796
+ * headers. Header names are returned with their exact casing being set.
797
+ *
798
+ * ```js
799
+ * request.setHeader('Foo', 'bar');
800
+ * request.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
801
+ *
802
+ * const headerNames = request.getRawHeaderNames();
803
+ * // headerNames === ['Foo', 'Set-Cookie']
804
+ * ```
805
+ * @since v15.13.0, v14.17.0
806
+ */
807
+ getRawHeaderNames(): string[];
808
+ /**
809
+ * @deprecated
810
+ */
811
+ addListener(event: 'abort', listener: () => void): this;
812
+ addListener(
813
+ event: 'connect',
814
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
815
+ ): this;
816
+ addListener(event: 'continue', listener: () => void): this;
817
+ addListener(event: 'information', listener: (info: InformationEvent) => void): this;
818
+ addListener(event: 'response', listener: (response: IncomingMessage) => void): this;
819
+ addListener(event: 'socket', listener: (socket: Socket) => void): this;
820
+ addListener(event: 'timeout', listener: () => void): this;
821
+ addListener(
822
+ event: 'upgrade',
823
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
824
+ ): this;
825
+ addListener(event: 'close', listener: () => void): this;
826
+ addListener(event: 'drain', listener: () => void): this;
827
+ addListener(event: 'error', listener: (err: Error) => void): this;
828
+ addListener(event: 'finish', listener: () => void): this;
829
+ addListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
830
+ addListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
831
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this;
832
+ /**
833
+ * @deprecated
834
+ */
835
+ on(event: 'abort', listener: () => void): this;
836
+ on(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
837
+ on(event: 'continue', listener: () => void): this;
838
+ on(event: 'information', listener: (info: InformationEvent) => void): this;
839
+ on(event: 'response', listener: (response: IncomingMessage) => void): this;
840
+ on(event: 'socket', listener: (socket: Socket) => void): this;
841
+ on(event: 'timeout', listener: () => void): this;
842
+ on(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
843
+ on(event: 'close', listener: () => void): this;
844
+ on(event: 'drain', listener: () => void): this;
845
+ on(event: 'error', listener: (err: Error) => void): this;
846
+ on(event: 'finish', listener: () => void): this;
847
+ on(event: 'pipe', listener: (src: stream.Readable) => void): this;
848
+ on(event: 'unpipe', listener: (src: stream.Readable) => void): this;
849
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
850
+ /**
851
+ * @deprecated
852
+ */
853
+ once(event: 'abort', listener: () => void): this;
854
+ once(event: 'connect', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
855
+ once(event: 'continue', listener: () => void): this;
856
+ once(event: 'information', listener: (info: InformationEvent) => void): this;
857
+ once(event: 'response', listener: (response: IncomingMessage) => void): this;
858
+ once(event: 'socket', listener: (socket: Socket) => void): this;
859
+ once(event: 'timeout', listener: () => void): this;
860
+ once(event: 'upgrade', listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;
861
+ once(event: 'close', listener: () => void): this;
862
+ once(event: 'drain', listener: () => void): this;
863
+ once(event: 'error', listener: (err: Error) => void): this;
864
+ once(event: 'finish', listener: () => void): this;
865
+ once(event: 'pipe', listener: (src: stream.Readable) => void): this;
866
+ once(event: 'unpipe', listener: (src: stream.Readable) => void): this;
867
+ once(event: string | symbol, listener: (...args: any[]) => void): this;
868
+ /**
869
+ * @deprecated
870
+ */
871
+ prependListener(event: 'abort', listener: () => void): this;
872
+ prependListener(
873
+ event: 'connect',
874
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
875
+ ): this;
876
+ prependListener(event: 'continue', listener: () => void): this;
877
+ prependListener(event: 'information', listener: (info: InformationEvent) => void): this;
878
+ prependListener(event: 'response', listener: (response: IncomingMessage) => void): this;
879
+ prependListener(event: 'socket', listener: (socket: Socket) => void): this;
880
+ prependListener(event: 'timeout', listener: () => void): this;
881
+ prependListener(
882
+ event: 'upgrade',
883
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
884
+ ): this;
885
+ prependListener(event: 'close', listener: () => void): this;
886
+ prependListener(event: 'drain', listener: () => void): this;
887
+ prependListener(event: 'error', listener: (err: Error) => void): this;
888
+ prependListener(event: 'finish', listener: () => void): this;
889
+ prependListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
890
+ prependListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
891
+ prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
892
+ /**
893
+ * @deprecated
894
+ */
895
+ prependOnceListener(event: 'abort', listener: () => void): this;
896
+ prependOnceListener(
897
+ event: 'connect',
898
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
899
+ ): this;
900
+ prependOnceListener(event: 'continue', listener: () => void): this;
901
+ prependOnceListener(event: 'information', listener: (info: InformationEvent) => void): this;
902
+ prependOnceListener(event: 'response', listener: (response: IncomingMessage) => void): this;
903
+ prependOnceListener(event: 'socket', listener: (socket: Socket) => void): this;
904
+ prependOnceListener(event: 'timeout', listener: () => void): this;
905
+ prependOnceListener(
906
+ event: 'upgrade',
907
+ listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,
908
+ ): this;
909
+ prependOnceListener(event: 'close', listener: () => void): this;
910
+ prependOnceListener(event: 'drain', listener: () => void): this;
911
+ prependOnceListener(event: 'error', listener: (err: Error) => void): this;
912
+ prependOnceListener(event: 'finish', listener: () => void): this;
913
+ prependOnceListener(event: 'pipe', listener: (src: stream.Readable) => void): this;
914
+ prependOnceListener(event: 'unpipe', listener: (src: stream.Readable) => void): this;
915
+ prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
916
+ }
917
+ /**
918
+ * 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
919
+ * access response
920
+ * status, headers and data.
921
+ *
922
+ * Different from its `socket` value which is a subclass of `stream.Duplex`, the`IncomingMessage` itself extends `stream.Readable` and is created separately to
923
+ * parse and emit the incoming HTTP headers and payload, as the underlying socket
924
+ * may be reused multiple times in case of keep-alive.
925
+ * @since v0.1.17
926
+ */
927
+ class IncomingMessage extends stream.Readable {
928
+ constructor(socket: Socket);
929
+ /**
930
+ * The `message.aborted` property will be `true` if the request has
931
+ * been aborted.
932
+ * @since v10.1.0
933
+ * @deprecated Since v17.0.0,v16.12.0 - Check `message.destroyed` from <a href="stream.html#class-streamreadable" class="type">stream.Readable</a>.
934
+ */
935
+ aborted: boolean;
936
+ /**
937
+ * In case of server request, the HTTP version sent by the client. In the case of
938
+ * client response, the HTTP version of the connected-to server.
939
+ * Probably either `'1.1'` or `'1.0'`.
940
+ *
941
+ * Also `message.httpVersionMajor` is the first integer and`message.httpVersionMinor` is the second.
942
+ * @since v0.1.1
943
+ */
944
+ httpVersion: string;
945
+ httpVersionMajor: number;
946
+ httpVersionMinor: number;
947
+ /**
948
+ * The `message.complete` property will be `true` if a complete HTTP message has
949
+ * been received and successfully parsed.
950
+ *
951
+ * This property is particularly useful as a means of determining if a client or
952
+ * server fully transmitted a message before a connection was terminated:
953
+ *
954
+ * ```js
955
+ * const req = http.request({
956
+ * host: '127.0.0.1',
957
+ * port: 8080,
958
+ * method: 'POST'
959
+ * }, (res) => {
960
+ * res.resume();
961
+ * res.on('end', () => {
962
+ * if (!res.complete)
963
+ * console.error(
964
+ * 'The connection was terminated while the message was still being sent');
965
+ * });
966
+ * });
967
+ * ```
968
+ * @since v0.3.0
969
+ */
970
+ complete: boolean;
971
+ /**
972
+ * Alias for `message.socket`.
973
+ * @since v0.1.90
974
+ * @deprecated Since v16.0.0 - Use `socket`.
975
+ */
976
+ connection: Socket;
977
+ /**
978
+ * The `net.Socket` object associated with the connection.
979
+ *
980
+ * With HTTPS support, use `request.socket.getPeerCertificate()` to obtain the
981
+ * client's authentication details.
982
+ *
983
+ * This property is guaranteed to be an instance of the `net.Socket` class,
984
+ * a subclass of `stream.Duplex`, unless the user specified a socket
985
+ * type other than `net.Socket` or internally nulled.
986
+ * @since v0.3.0
987
+ */
988
+ socket: Socket;
989
+ /**
990
+ * The request/response headers object.
991
+ *
992
+ * Key-value pairs of header names and values. Header names are lower-cased.
993
+ *
994
+ * ```js
995
+ * // Prints something like:
996
+ * //
997
+ * // { 'user-agent': 'curl/7.22.0',
998
+ * // host: '127.0.0.1:8000',
999
+ * // accept: '*' }
1000
+ * console.log(request.getHeaders());
1001
+ * ```
1002
+ *
1003
+ * Duplicates in raw headers are handled in the following ways, depending on the
1004
+ * header name:
1005
+ *
1006
+ * * Duplicates of `age`, `authorization`, `content-length`, `content-type`,`etag`, `expires`, `from`, `host`, `if-modified-since`, `if-unmodified-since`,`last-modified`, `location`,
1007
+ * `max-forwards`, `proxy-authorization`, `referer`,`retry-after`, `server`, or `user-agent` are discarded.
1008
+ * * `set-cookie` is always an array. Duplicates are added to the array.
1009
+ * * For duplicate `cookie` headers, the values are joined together with '; '.
1010
+ * * For all other headers, the values are joined together with ', '.
1011
+ * @since v0.1.5
1012
+ */
1013
+ headers: IncomingHttpHeaders;
1014
+ /**
1015
+ * The raw request/response headers list exactly as they were received.
1016
+ *
1017
+ * The keys and values are in the same list. It is _not_ a
1018
+ * list of tuples. So, the even-numbered offsets are key values, and the
1019
+ * odd-numbered offsets are the associated values.
1020
+ *
1021
+ * Header names are not lowercased, and duplicates are not merged.
1022
+ *
1023
+ * ```js
1024
+ * // Prints something like:
1025
+ * //
1026
+ * // [ 'user-agent',
1027
+ * // 'this is invalid because there can be only one',
1028
+ * // 'User-Agent',
1029
+ * // 'curl/7.22.0',
1030
+ * // 'Host',
1031
+ * // '127.0.0.1:8000',
1032
+ * // 'ACCEPT',
1033
+ * // '*' ]
1034
+ * console.log(request.rawHeaders);
1035
+ * ```
1036
+ * @since v0.11.6
1037
+ */
1038
+ rawHeaders: string[];
1039
+ /**
1040
+ * The request/response trailers object. Only populated at the `'end'` event.
1041
+ * @since v0.3.0
1042
+ */
1043
+ trailers: NodeJS.Dict<string>;
1044
+ /**
1045
+ * The raw request/response trailer keys and values exactly as they were
1046
+ * received. Only populated at the `'end'` event.
1047
+ * @since v0.11.6
1048
+ */
1049
+ rawTrailers: string[];
1050
+ /**
1051
+ * Calls `message.socket.setTimeout(msecs, callback)`.
1052
+ * @since v0.5.9
1053
+ */
1054
+ setTimeout(msecs: number, callback?: () => void): this;
1055
+ /**
1056
+ * **Only valid for request obtained from {@link Server}.**
1057
+ *
1058
+ * The request method as a string. Read only. Examples: `'GET'`, `'DELETE'`.
1059
+ * @since v0.1.1
1060
+ */
1061
+ method?: string | undefined;
1062
+ /**
1063
+ * **Only valid for request obtained from {@link Server}.**
1064
+ *
1065
+ * Request URL string. This contains only the URL that is present in the actual
1066
+ * HTTP request. Take the following request:
1067
+ *
1068
+ * ```http
1069
+ * GET /status?name=ryan HTTP/1.1
1070
+ * Accept: text/plain
1071
+ * ```
1072
+ *
1073
+ * To parse the URL into its parts:
1074
+ *
1075
+ * ```js
1076
+ * new URL(request.url, `http://${request.getHeaders().host}`);
1077
+ * ```
1078
+ *
1079
+ * When `request.url` is `'/status?name=ryan'` and`request.getHeaders().host` is `'localhost:3000'`:
1080
+ *
1081
+ * ```console
1082
+ * $ node
1083
+ * > new URL(request.url, `http://${request.getHeaders().host}`)
1084
+ * URL {
1085
+ * href: 'http://localhost:3000/status?name=ryan',
1086
+ * origin: 'http://localhost:3000',
1087
+ * protocol: 'http:',
1088
+ * username: '',
1089
+ * password: '',
1090
+ * host: 'localhost:3000',
1091
+ * hostname: 'localhost',
1092
+ * port: '3000',
1093
+ * pathname: '/status',
1094
+ * search: '?name=ryan',
1095
+ * searchParams: URLSearchParams { 'name' => 'ryan' },
1096
+ * hash: ''
1097
+ * }
1098
+ * ```
1099
+ * @since v0.1.90
1100
+ */
1101
+ url?: string | undefined;
1102
+ /**
1103
+ * **Only valid for response obtained from {@link ClientRequest}.**
1104
+ *
1105
+ * The 3-digit HTTP response status code. E.G. `404`.
1106
+ * @since v0.1.1
1107
+ */
1108
+ statusCode?: number | undefined;
1109
+ /**
1110
+ * **Only valid for response obtained from {@link ClientRequest}.**
1111
+ *
1112
+ * The HTTP response status message (reason phrase). E.G. `OK` or `Internal Server Error`.
1113
+ * @since v0.11.10
1114
+ */
1115
+ statusMessage?: string | undefined;
1116
+ /**
1117
+ * Calls `destroy()` on the socket that received the `IncomingMessage`. If `error`is provided, an `'error'` event is emitted on the socket and `error` is passed
1118
+ * as an argument to any listeners on the event.
1119
+ * @since v0.3.0
1120
+ */
1121
+ destroy(error?: Error): this;
1122
+ }
1123
+ interface AgentOptions extends Partial<TcpSocketConnectOpts> {
1124
+ /**
1125
+ * Keep sockets around in a pool to be used by other requests in the future. Default = false
1126
+ */
1127
+ keepAlive?: boolean | undefined;
1128
+ /**
1129
+ * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000.
1130
+ * Only relevant if keepAlive is set to true.
1131
+ */
1132
+ keepAliveMsecs?: number | undefined;
1133
+ /**
1134
+ * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity
1135
+ */
1136
+ maxSockets?: number | undefined;
1137
+ /**
1138
+ * Maximum number of sockets allowed for all hosts in total. Each request will use a new socket until the maximum is reached. Default: Infinity.
1139
+ */
1140
+ maxTotalSockets?: number | undefined;
1141
+ /**
1142
+ * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256.
1143
+ */
1144
+ maxFreeSockets?: number | undefined;
1145
+ /**
1146
+ * Socket timeout in milliseconds. This will set the timeout after the socket is connected.
1147
+ */
1148
+ timeout?: number | undefined;
1149
+ /**
1150
+ * Scheduling strategy to apply when picking the next free socket to use.
1151
+ * @default `lifo`
1152
+ */
1153
+ scheduling?: 'fifo' | 'lifo' | undefined;
1154
+ }
1155
+ /**
1156
+ * An `Agent` is responsible for managing connection persistence
1157
+ * and reuse for HTTP clients. It maintains a queue of pending requests
1158
+ * for a given host and port, reusing a single socket connection for each
1159
+ * until the queue is empty, at which time the socket is either destroyed
1160
+ * or put into a pool where it is kept to be used again for requests to the
1161
+ * same host and port. Whether it is destroyed or pooled depends on the`keepAlive` `option`.
1162
+ *
1163
+ * Pooled connections have TCP Keep-Alive enabled for them, but servers may
1164
+ * still close idle connections, in which case they will be removed from the
1165
+ * pool and a new connection will be made when a new HTTP request is made for
1166
+ * that host and port. Servers may also refuse to allow multiple requests
1167
+ * over the same connection, in which case the connection will have to be
1168
+ * remade for every request and cannot be pooled. The `Agent` will still make
1169
+ * the requests to that server, but each one will occur over a new connection.
1170
+ *
1171
+ * When a connection is closed by the client or the server, it is removed
1172
+ * from the pool. Any unused sockets in the pool will be unrefed so as not
1173
+ * to keep the Node.js process running when there are no outstanding requests.
1174
+ * (see `socket.unref()`).
1175
+ *
1176
+ * It is good practice, to `destroy()` an `Agent` instance when it is no
1177
+ * longer in use, because unused sockets consume OS resources.
1178
+ *
1179
+ * Sockets are removed from an agent when the socket emits either
1180
+ * a `'close'` event or an `'agentRemove'` event. When intending to keep one
1181
+ * HTTP request open for a long time without keeping it in the agent, something
1182
+ * like the following may be done:
1183
+ *
1184
+ * ```js
1185
+ * http.get(options, (res) => {
1186
+ * // Do stuff
1187
+ * }).on('socket', (socket) => {
1188
+ * socket.emit('agentRemove');
1189
+ * });
1190
+ * ```
1191
+ *
1192
+ * An agent may also be used for an individual request. By providing`{agent: false}` as an option to the `http.get()` or `http.request()`functions, a one-time use `Agent` with default options
1193
+ * will be used
1194
+ * for the client connection.
1195
+ *
1196
+ * `agent:false`:
1197
+ *
1198
+ * ```js
1199
+ * http.get({
1200
+ * hostname: 'localhost',
1201
+ * port: 80,
1202
+ * path: '/',
1203
+ * agent: false // Create a new agent just for this one request
1204
+ * }, (res) => {
1205
+ * // Do stuff with response
1206
+ * });
1207
+ * ```
1208
+ * @since v0.3.4
1209
+ */
1210
+ class Agent {
1211
+ /**
1212
+ * By default set to 256\. For agents with `keepAlive` enabled, this
1213
+ * sets the maximum number of sockets that will be left open in the free
1214
+ * state.
1215
+ * @since v0.11.7
1216
+ */
1217
+ maxFreeSockets: number;
1218
+ /**
1219
+ * By default set to `Infinity`. Determines how many concurrent sockets the agent
1220
+ * can have open per origin. Origin is the returned value of `agent.getName()`.
1221
+ * @since v0.3.6
1222
+ */
1223
+ maxSockets: number;
1224
+ /**
1225
+ * By default set to `Infinity`. Determines how many concurrent sockets the agent
1226
+ * can have open. Unlike `maxSockets`, this parameter applies across all origins.
1227
+ * @since v14.5.0, v12.19.0
1228
+ */
1229
+ maxTotalSockets: number;
1230
+ /**
1231
+ * An object which contains arrays of sockets currently awaiting use by
1232
+ * the agent when `keepAlive` is enabled. Do not modify.
1233
+ *
1234
+ * Sockets in the `freeSockets` list will be automatically destroyed and
1235
+ * removed from the array on `'timeout'`.
1236
+ * @since v0.11.4
1237
+ */
1238
+ readonly freeSockets: NodeJS.ReadOnlyDict<Socket[]>;
1239
+ /**
1240
+ * An object which contains arrays of sockets currently in use by the
1241
+ * agent. Do not modify.
1242
+ * @since v0.3.6
1243
+ */
1244
+ readonly sockets: NodeJS.ReadOnlyDict<Socket[]>;
1245
+ /**
1246
+ * An object which contains queues of requests that have not yet been assigned to
1247
+ * sockets. Do not modify.
1248
+ * @since v0.5.9
1249
+ */
1250
+ readonly requests: NodeJS.ReadOnlyDict<IncomingMessage[]>;
1251
+ constructor(opts?: AgentOptions);
1252
+ /**
1253
+ * Destroy any sockets that are currently in use by the agent.
1254
+ *
1255
+ * It is usually not necessary to do this. However, if using an
1256
+ * agent with `keepAlive` enabled, then it is best to explicitly shut down
1257
+ * the agent when it is no longer needed. Otherwise,
1258
+ * sockets might stay open for quite a long time before the server
1259
+ * terminates them.
1260
+ * @since v0.11.4
1261
+ */
1262
+ destroy(): void;
1263
+ }
1264
+ const METHODS: string[];
1265
+ const STATUS_CODES: {
1266
+ [errorCode: number]: string | undefined;
1267
+ [errorCode: string]: string | undefined;
1268
+ };
1269
+ /**
1270
+ * Returns a new instance of {@link Server}.
1271
+ *
1272
+ * The `requestListener` is a function which is automatically
1273
+ * added to the `'request'` event.
1274
+ * @since v0.1.13
1275
+ */
1276
+ function createServer<
1277
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
1278
+ Response extends typeof ServerResponse = typeof ServerResponse,
1279
+ >(requestListener?: RequestListener<Request, Response>): Server<Request, Response>;
1280
+ function createServer<
1281
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
1282
+ Response extends typeof ServerResponse = typeof ServerResponse,
1283
+ >(
1284
+ options: ServerOptions<Request, Response>,
1285
+ requestListener?: RequestListener<Request, Response>,
1286
+ ): Server<Request, Response>;
1287
+ // although RequestOptions are passed as ClientRequestArgs to ClientRequest directly,
1288
+ // create interface RequestOptions would make the naming more clear to developers
1289
+ interface RequestOptions extends ClientRequestArgs {}
1290
+ /**
1291
+ * `options` in `socket.connect()` are also supported.
1292
+ *
1293
+ * Node.js maintains several connections per server to make HTTP requests.
1294
+ * This function allows one to transparently issue requests.
1295
+ *
1296
+ * `url` can be a string or a `URL` object. If `url` is a
1297
+ * string, it is automatically parsed with `new URL()`. If it is a `URL` object, it will be automatically converted to an ordinary `options` object.
1298
+ *
1299
+ * If both `url` and `options` are specified, the objects are merged, with the`options` properties taking precedence.
1300
+ *
1301
+ * The optional `callback` parameter will be added as a one-time listener for
1302
+ * the `'response'` event.
1303
+ *
1304
+ * `http.request()` returns an instance of the {@link ClientRequest} class. The `ClientRequest` instance is a writable stream. If one needs to
1305
+ * upload a file with a POST request, then write to the `ClientRequest` object.
1306
+ *
1307
+ * ```js
1308
+ * const http = require('http');
1309
+ *
1310
+ * const postData = JSON.stringify({
1311
+ * 'msg': 'Hello World!'
1312
+ * });
1313
+ *
1314
+ * const options = {
1315
+ * hostname: 'www.google.com',
1316
+ * port: 80,
1317
+ * path: '/upload',
1318
+ * method: 'POST',
1319
+ * headers: {
1320
+ * 'Content-Type': 'application/json',
1321
+ * 'Content-Length': Buffer.byteLength(postData)
1322
+ * }
1323
+ * };
1324
+ *
1325
+ * const req = http.request(options, (res) => {
1326
+ * console.log(`STATUS: ${res.statusCode}`);
1327
+ * console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
1328
+ * res.setEncoding('utf8');
1329
+ * res.on('data', (chunk) => {
1330
+ * console.log(`BODY: ${chunk}`);
1331
+ * });
1332
+ * res.on('end', () => {
1333
+ * console.log('No more data in response.');
1334
+ * });
1335
+ * });
1336
+ *
1337
+ * req.on('error', (e) => {
1338
+ * console.error(`problem with request: ${e.message}`);
1339
+ * });
1340
+ *
1341
+ * // Write data to request body
1342
+ * req.write(postData);
1343
+ * req.end();
1344
+ * ```
1345
+ *
1346
+ * In the example `req.end()` was called. With `http.request()` one
1347
+ * must always call `req.end()` to signify the end of the request -
1348
+ * even if there is no data being written to the request body.
1349
+ *
1350
+ * If any error is encountered during the request (be that with DNS resolution,
1351
+ * TCP level errors, or actual HTTP parse errors) an `'error'` event is emitted
1352
+ * on the returned request object. As with all `'error'` events, if no listeners
1353
+ * are registered the error will be thrown.
1354
+ *
1355
+ * There are a few special headers that should be noted.
1356
+ *
1357
+ * * Sending a 'Connection: keep-alive' will notify Node.js that the connection to
1358
+ * the server should be persisted until the next request.
1359
+ * * Sending a 'Content-Length' header will disable the default chunked encoding.
1360
+ * * Sending an 'Expect' header will immediately send the request headers.
1361
+ * Usually, when sending 'Expect: 100-continue', both a timeout and a listener
1362
+ * for the `'continue'` event should be set. See RFC 2616 Section 8.2.3 for more
1363
+ * information.
1364
+ * * Sending an Authorization header will override using the `auth` option
1365
+ * to compute basic authentication.
1366
+ *
1367
+ * Example using a `URL` as `options`:
1368
+ *
1369
+ * ```js
1370
+ * const options = new URL('http://abc:xyz@example.com');
1371
+ *
1372
+ * const req = http.request(options, (res) => {
1373
+ * // ...
1374
+ * });
1375
+ * ```
1376
+ *
1377
+ * In a successful request, the following events will be emitted in the following
1378
+ * order:
1379
+ *
1380
+ * * `'socket'`
1381
+ * * `'response'`
1382
+ * * `'data'` any number of times, on the `res` object
1383
+ * (`'data'` will not be emitted at all if the response body is empty, for
1384
+ * instance, in most redirects)
1385
+ * * `'end'` on the `res` object
1386
+ * * `'close'`
1387
+ *
1388
+ * In the case of a connection error, the following events will be emitted:
1389
+ *
1390
+ * * `'socket'`
1391
+ * * `'error'`
1392
+ * * `'close'`
1393
+ *
1394
+ * In the case of a premature connection close before the response is received,
1395
+ * the following events will be emitted in the following order:
1396
+ *
1397
+ * * `'socket'`
1398
+ * * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`
1399
+ * * `'close'`
1400
+ *
1401
+ * In the case of a premature connection close after the response is received,
1402
+ * the following events will be emitted in the following order:
1403
+ *
1404
+ * * `'socket'`
1405
+ * * `'response'`
1406
+ * * `'data'` any number of times, on the `res` object
1407
+ * * (connection closed here)
1408
+ * * `'aborted'` on the `res` object
1409
+ * * `'error'` on the `res` object with an error with message`'Error: aborted'` and code `'ECONNRESET'`.
1410
+ * * `'close'`
1411
+ * * `'close'` on the `res` object
1412
+ *
1413
+ * If `req.destroy()` is called before a socket is assigned, the following
1414
+ * events will be emitted in the following order:
1415
+ *
1416
+ * * (`req.destroy()` called here)
1417
+ * * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`
1418
+ * * `'close'`
1419
+ *
1420
+ * If `req.destroy()` is called before the connection succeeds, the following
1421
+ * events will be emitted in the following order:
1422
+ *
1423
+ * * `'socket'`
1424
+ * * (`req.destroy()` called here)
1425
+ * * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`
1426
+ * * `'close'`
1427
+ *
1428
+ * If `req.destroy()` is called after the response is received, the following
1429
+ * events will be emitted in the following order:
1430
+ *
1431
+ * * `'socket'`
1432
+ * * `'response'`
1433
+ * * `'data'` any number of times, on the `res` object
1434
+ * * (`req.destroy()` called here)
1435
+ * * `'aborted'` on the `res` object
1436
+ * * `'error'` on the `res` object with an error with message`'Error: aborted'` and code `'ECONNRESET'`.
1437
+ * * `'close'`
1438
+ * * `'close'` on the `res` object
1439
+ *
1440
+ * If `req.abort()` is called before a socket is assigned, the following
1441
+ * events will be emitted in the following order:
1442
+ *
1443
+ * * (`req.abort()` called here)
1444
+ * * `'abort'`
1445
+ * * `'close'`
1446
+ *
1447
+ * If `req.abort()` is called before the connection succeeds, the following
1448
+ * events will be emitted in the following order:
1449
+ *
1450
+ * * `'socket'`
1451
+ * * (`req.abort()` called here)
1452
+ * * `'abort'`
1453
+ * * `'error'` with an error with message `'Error: socket hang up'` and code`'ECONNRESET'`
1454
+ * * `'close'`
1455
+ *
1456
+ * If `req.abort()` is called after the response is received, the following
1457
+ * events will be emitted in the following order:
1458
+ *
1459
+ * * `'socket'`
1460
+ * * `'response'`
1461
+ * * `'data'` any number of times, on the `res` object
1462
+ * * (`req.abort()` called here)
1463
+ * * `'abort'`
1464
+ * * `'aborted'` on the `res` object
1465
+ * * `'error'` on the `res` object with an error with message`'Error: aborted'` and code `'ECONNRESET'`.
1466
+ * * `'close'`
1467
+ * * `'close'` on the `res` object
1468
+ *
1469
+ * Setting the `timeout` option or using the `setTimeout()` function will
1470
+ * not abort the request or do anything besides add a `'timeout'` event.
1471
+ *
1472
+ * Passing an `AbortSignal` and then calling `abort` on the corresponding`AbortController` will behave the same way as calling `.destroy()` on the
1473
+ * request itself.
1474
+ * @since v0.3.6
1475
+ */
1476
+ function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
1477
+ function request(
1478
+ url: string | URL,
1479
+ options: RequestOptions,
1480
+ callback?: (res: IncomingMessage) => void,
1481
+ ): ClientRequest;
1482
+ /**
1483
+ * Since most requests are GET requests without bodies, Node.js provides this
1484
+ * 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
1485
+ * response
1486
+ * data for reasons stated in {@link ClientRequest} section.
1487
+ *
1488
+ * The `callback` is invoked with a single argument that is an instance of {@link IncomingMessage}.
1489
+ *
1490
+ * JSON fetching example:
1491
+ *
1492
+ * ```js
1493
+ * http.get('http://localhost:8000/', (res) => {
1494
+ * const { statusCode } = res;
1495
+ * const contentType = res.headers['content-type'];
1496
+ *
1497
+ * let error;
1498
+ * // Any 2xx status code signals a successful response but
1499
+ * // here we're only checking for 200.
1500
+ * if (statusCode !== 200) {
1501
+ * error = new Error('Request Failed.\n' +
1502
+ * `Status Code: ${statusCode}`);
1503
+ * } else if (!/^application\/json/.test(contentType)) {
1504
+ * error = new Error('Invalid content-type.\n' +
1505
+ * `Expected application/json but received ${contentType}`);
1506
+ * }
1507
+ * if (error) {
1508
+ * console.error(error.message);
1509
+ * // Consume response data to free up memory
1510
+ * res.resume();
1511
+ * return;
1512
+ * }
1513
+ *
1514
+ * res.setEncoding('utf8');
1515
+ * let rawData = '';
1516
+ * res.on('data', (chunk) => { rawData += chunk; });
1517
+ * res.on('end', () => {
1518
+ * try {
1519
+ * const parsedData = JSON.parse(rawData);
1520
+ * console.log(parsedData);
1521
+ * } catch (e) {
1522
+ * console.error(e.message);
1523
+ * }
1524
+ * });
1525
+ * }).on('error', (e) => {
1526
+ * console.error(`Got error: ${e.message}`);
1527
+ * });
1528
+ *
1529
+ * // Create a local server to receive data from
1530
+ * const server = http.createServer((req, res) => {
1531
+ * res.writeHead(200, { 'Content-Type': 'application/json' });
1532
+ * res.end(JSON.stringify({
1533
+ * data: 'Hello World!'
1534
+ * }));
1535
+ * });
1536
+ *
1537
+ * server.listen(8000);
1538
+ * ```
1539
+ * @since v0.3.6
1540
+ * @param options Accepts the same `options` as {@link request}, with the `method` always set to `GET`. Properties that are inherited from the prototype are ignored.
1541
+ */
1542
+ function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
1543
+ function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
1544
+ let globalAgent: Agent;
1545
+ /**
1546
+ * Read-only property specifying the maximum allowed size of HTTP headers in bytes.
1547
+ * Defaults to 16KB. Configurable using the `--max-http-header-size` CLI option.
1548
+ */
1549
+ const maxHeaderSize: number;
1550
+ }
1551
+ declare module 'node:http' {
1552
+ export * from 'http';
1553
+ }