@node-red/editor-client 3.1.8 → 4.0.0-beta.2

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