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