mcpbrowser 0.2.0 → 0.2.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 (134) hide show
  1. package/.mcpregistry_github_token +1 -0
  2. package/.mcpregistry_registry_token +1 -0
  3. package/README.md +68 -35
  4. package/extension/.vscodeignore +6 -0
  5. package/extension/LICENSE +21 -0
  6. package/extension/README.md +61 -0
  7. package/extension/icon.png +0 -0
  8. package/extension/icon.svg +35 -0
  9. package/extension/mcpbrowser-0.1.1.vsix +0 -0
  10. package/extension/mcpbrowser-0.1.2.vsix +0 -0
  11. package/extension/mcpbrowser-0.1.3.vsix +0 -0
  12. package/extension/mcpbrowser-0.1.4.vsix +0 -0
  13. package/extension/mcpbrowser-config-0.1.0.vsix +0 -0
  14. package/extension/node_modules/.package-lock.json +32 -0
  15. package/extension/node_modules/@types/node/LICENSE +21 -0
  16. package/extension/node_modules/@types/node/README.md +15 -0
  17. package/extension/node_modules/@types/node/assert/strict.d.ts +8 -0
  18. package/extension/node_modules/@types/node/assert.d.ts +1062 -0
  19. package/extension/node_modules/@types/node/async_hooks.d.ts +605 -0
  20. package/extension/node_modules/@types/node/buffer.buffer.d.ts +471 -0
  21. package/extension/node_modules/@types/node/buffer.d.ts +1936 -0
  22. package/extension/node_modules/@types/node/child_process.d.ts +1475 -0
  23. package/extension/node_modules/@types/node/cluster.d.ts +577 -0
  24. package/extension/node_modules/@types/node/compatibility/disposable.d.ts +16 -0
  25. package/extension/node_modules/@types/node/compatibility/index.d.ts +9 -0
  26. package/extension/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
  27. package/extension/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
  28. package/extension/node_modules/@types/node/console.d.ts +452 -0
  29. package/extension/node_modules/@types/node/constants.d.ts +21 -0
  30. package/extension/node_modules/@types/node/crypto.d.ts +4590 -0
  31. package/extension/node_modules/@types/node/dgram.d.ts +597 -0
  32. package/extension/node_modules/@types/node/diagnostics_channel.d.ts +578 -0
  33. package/extension/node_modules/@types/node/dns/promises.d.ts +479 -0
  34. package/extension/node_modules/@types/node/dns.d.ts +871 -0
  35. package/extension/node_modules/@types/node/domain.d.ts +170 -0
  36. package/extension/node_modules/@types/node/events.d.ts +977 -0
  37. package/extension/node_modules/@types/node/fs/promises.d.ts +1270 -0
  38. package/extension/node_modules/@types/node/fs.d.ts +4375 -0
  39. package/extension/node_modules/@types/node/globals.d.ts +172 -0
  40. package/extension/node_modules/@types/node/globals.typedarray.d.ts +38 -0
  41. package/extension/node_modules/@types/node/http.d.ts +2049 -0
  42. package/extension/node_modules/@types/node/http2.d.ts +2631 -0
  43. package/extension/node_modules/@types/node/https.d.ts +578 -0
  44. package/extension/node_modules/@types/node/index.d.ts +93 -0
  45. package/extension/node_modules/@types/node/inspector.generated.d.ts +3966 -0
  46. package/extension/node_modules/@types/node/module.d.ts +539 -0
  47. package/extension/node_modules/@types/node/net.d.ts +1012 -0
  48. package/extension/node_modules/@types/node/os.d.ts +506 -0
  49. package/extension/node_modules/@types/node/package.json +140 -0
  50. package/extension/node_modules/@types/node/path.d.ts +200 -0
  51. package/extension/node_modules/@types/node/perf_hooks.d.ts +961 -0
  52. package/extension/node_modules/@types/node/process.d.ts +1957 -0
  53. package/extension/node_modules/@types/node/punycode.d.ts +117 -0
  54. package/extension/node_modules/@types/node/querystring.d.ts +152 -0
  55. package/extension/node_modules/@types/node/readline/promises.d.ts +162 -0
  56. package/extension/node_modules/@types/node/readline.d.ts +589 -0
  57. package/extension/node_modules/@types/node/repl.d.ts +430 -0
  58. package/extension/node_modules/@types/node/sea.d.ts +153 -0
  59. package/extension/node_modules/@types/node/stream/consumers.d.ts +38 -0
  60. package/extension/node_modules/@types/node/stream/promises.d.ts +90 -0
  61. package/extension/node_modules/@types/node/stream/web.d.ts +533 -0
  62. package/extension/node_modules/@types/node/stream.d.ts +1675 -0
  63. package/extension/node_modules/@types/node/string_decoder.d.ts +67 -0
  64. package/extension/node_modules/@types/node/test.d.ts +1787 -0
  65. package/extension/node_modules/@types/node/timers/promises.d.ts +108 -0
  66. package/extension/node_modules/@types/node/timers.d.ts +286 -0
  67. package/extension/node_modules/@types/node/tls.d.ts +1255 -0
  68. package/extension/node_modules/@types/node/trace_events.d.ts +197 -0
  69. package/extension/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +468 -0
  70. package/extension/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +34 -0
  71. package/extension/node_modules/@types/node/ts5.6/index.d.ts +93 -0
  72. package/extension/node_modules/@types/node/tty.d.ts +208 -0
  73. package/extension/node_modules/@types/node/url.d.ts +964 -0
  74. package/extension/node_modules/@types/node/util.d.ts +2331 -0
  75. package/extension/node_modules/@types/node/v8.d.ts +809 -0
  76. package/extension/node_modules/@types/node/vm.d.ts +1001 -0
  77. package/extension/node_modules/@types/node/wasi.d.ts +181 -0
  78. package/extension/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
  79. package/extension/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
  80. package/extension/node_modules/@types/node/web-globals/events.d.ts +97 -0
  81. package/extension/node_modules/@types/node/web-globals/fetch.d.ts +46 -0
  82. package/extension/node_modules/@types/node/worker_threads.d.ts +715 -0
  83. package/extension/node_modules/@types/node/zlib.d.ts +540 -0
  84. package/extension/node_modules/@types/vscode/LICENSE +21 -0
  85. package/extension/node_modules/@types/vscode/README.md +15 -0
  86. package/extension/node_modules/@types/vscode/index.d.ts +21153 -0
  87. package/extension/node_modules/@types/vscode/package.json +26 -0
  88. package/extension/node_modules/undici-types/LICENSE +21 -0
  89. package/extension/node_modules/undici-types/README.md +6 -0
  90. package/extension/node_modules/undici-types/agent.d.ts +31 -0
  91. package/extension/node_modules/undici-types/api.d.ts +43 -0
  92. package/extension/node_modules/undici-types/balanced-pool.d.ts +29 -0
  93. package/extension/node_modules/undici-types/cache.d.ts +36 -0
  94. package/extension/node_modules/undici-types/client.d.ts +108 -0
  95. package/extension/node_modules/undici-types/connector.d.ts +34 -0
  96. package/extension/node_modules/undici-types/content-type.d.ts +21 -0
  97. package/extension/node_modules/undici-types/cookies.d.ts +28 -0
  98. package/extension/node_modules/undici-types/diagnostics-channel.d.ts +66 -0
  99. package/extension/node_modules/undici-types/dispatcher.d.ts +256 -0
  100. package/extension/node_modules/undici-types/env-http-proxy-agent.d.ts +21 -0
  101. package/extension/node_modules/undici-types/errors.d.ts +149 -0
  102. package/extension/node_modules/undici-types/eventsource.d.ts +61 -0
  103. package/extension/node_modules/undici-types/fetch.d.ts +209 -0
  104. package/extension/node_modules/undici-types/file.d.ts +39 -0
  105. package/extension/node_modules/undici-types/filereader.d.ts +54 -0
  106. package/extension/node_modules/undici-types/formdata.d.ts +108 -0
  107. package/extension/node_modules/undici-types/global-dispatcher.d.ts +9 -0
  108. package/extension/node_modules/undici-types/global-origin.d.ts +7 -0
  109. package/extension/node_modules/undici-types/handlers.d.ts +15 -0
  110. package/extension/node_modules/undici-types/header.d.ts +4 -0
  111. package/extension/node_modules/undici-types/index.d.ts +71 -0
  112. package/extension/node_modules/undici-types/interceptors.d.ts +17 -0
  113. package/extension/node_modules/undici-types/mock-agent.d.ts +50 -0
  114. package/extension/node_modules/undici-types/mock-client.d.ts +25 -0
  115. package/extension/node_modules/undici-types/mock-errors.d.ts +12 -0
  116. package/extension/node_modules/undici-types/mock-interceptor.d.ts +93 -0
  117. package/extension/node_modules/undici-types/mock-pool.d.ts +25 -0
  118. package/extension/node_modules/undici-types/package.json +55 -0
  119. package/extension/node_modules/undici-types/patch.d.ts +33 -0
  120. package/extension/node_modules/undici-types/pool-stats.d.ts +19 -0
  121. package/extension/node_modules/undici-types/pool.d.ts +39 -0
  122. package/extension/node_modules/undici-types/proxy-agent.d.ts +28 -0
  123. package/extension/node_modules/undici-types/readable.d.ts +65 -0
  124. package/extension/node_modules/undici-types/retry-agent.d.ts +8 -0
  125. package/extension/node_modules/undici-types/retry-handler.d.ts +116 -0
  126. package/extension/node_modules/undici-types/util.d.ts +18 -0
  127. package/extension/node_modules/undici-types/webidl.d.ts +228 -0
  128. package/extension/node_modules/undici-types/websocket.d.ts +150 -0
  129. package/extension/package-lock.json +44 -0
  130. package/extension/package.json +55 -0
  131. package/extension/src/extension.js +257 -0
  132. package/package.json +2 -1
  133. package/server.json +20 -0
  134. package/src/mcp-browser.js +1 -1
@@ -0,0 +1,2049 @@
1
+ /**
2
+ * To use the HTTP server and client one must import the `node:http` module.
3
+ *
4
+ * The HTTP interfaces in Node.js are designed to support many features
5
+ * of the protocol which have been traditionally difficult to use.
6
+ * In particular, large, possibly chunk-encoded, messages. The interface is
7
+ * careful to never buffer entire requests or responses, so the
8
+ * user is able to stream data.
9
+ *
10
+ * HTTP message headers are represented by an object like this:
11
+ *
12
+ * ```json
13
+ * { "content-length": "123",
14
+ * "content-type": "text/plain",
15
+ * "connection": "keep-alive",
16
+ * "host": "example.com",
17
+ * "accept": "*" }
18
+ * ```
19
+ *
20
+ * Keys are lowercased. Values are not modified.
21
+ *
22
+ * In order to support the full spectrum of possible HTTP applications, the Node.js
23
+ * HTTP API is very low-level. It deals with stream handling and message
24
+ * parsing only. It parses a message into headers and body but it does not
25
+ * parse the actual headers or the body.
26
+ *
27
+ * See `message.headers` for details on how duplicate headers are handled.
28
+ *
29
+ * The raw headers as they were received are retained in the `rawHeaders` property, which is an array of `[key, value, key2, value2, ...]`. For
30
+ * example, the previous message header object might have a `rawHeaders` list like the following:
31
+ *
32
+ * ```js
33
+ * [ 'ConTent-Length', '123456',
34
+ * 'content-LENGTH', '123',
35
+ * 'content-type', 'text/plain',
36
+ * 'CONNECTION', 'keep-alive',
37
+ * 'Host', 'example.com',
38
+ * 'accepT', '*' ]
39
+ * ```
40
+ * @see [source](https://github.com/nodejs/node/blob/v20.13.1/lib/http.js)
41
+ */
42
+ declare module "http" {
43
+ import { NonSharedBuffer } from "node:buffer";
44
+ import * as stream from "node:stream";
45
+ import { URL } from "node:url";
46
+ import { LookupOptions } from "node:dns";
47
+ import { EventEmitter } from "node:events";
48
+ import { LookupFunction, Server as NetServer, Socket, TcpSocketConnectOpts } from "node:net";
49
+ // incoming headers will never contain number
50
+ interface IncomingHttpHeaders extends NodeJS.Dict<string | string[]> {
51
+ accept?: string | undefined;
52
+ "accept-encoding"?: string | undefined;
53
+ "accept-language"?: string | undefined;
54
+ "accept-patch"?: string | undefined;
55
+ "accept-ranges"?: string | undefined;
56
+ "access-control-allow-credentials"?: string | undefined;
57
+ "access-control-allow-headers"?: string | undefined;
58
+ "access-control-allow-methods"?: string | undefined;
59
+ "access-control-allow-origin"?: string | undefined;
60
+ "access-control-expose-headers"?: string | undefined;
61
+ "access-control-max-age"?: string | undefined;
62
+ "access-control-request-headers"?: string | undefined;
63
+ "access-control-request-method"?: string | undefined;
64
+ age?: string | undefined;
65
+ allow?: string | undefined;
66
+ "alt-svc"?: string | undefined;
67
+ authorization?: string | undefined;
68
+ "cache-control"?: string | undefined;
69
+ connection?: string | undefined;
70
+ "content-disposition"?: string | undefined;
71
+ "content-encoding"?: string | undefined;
72
+ "content-language"?: string | undefined;
73
+ "content-length"?: string | undefined;
74
+ "content-location"?: string | undefined;
75
+ "content-range"?: string | undefined;
76
+ "content-type"?: string | undefined;
77
+ cookie?: string | undefined;
78
+ date?: string | undefined;
79
+ etag?: string | undefined;
80
+ expect?: string | undefined;
81
+ expires?: string | undefined;
82
+ forwarded?: string | undefined;
83
+ from?: string | undefined;
84
+ host?: string | undefined;
85
+ "if-match"?: string | undefined;
86
+ "if-modified-since"?: string | undefined;
87
+ "if-none-match"?: string | undefined;
88
+ "if-unmodified-since"?: string | undefined;
89
+ "last-modified"?: string | undefined;
90
+ location?: string | undefined;
91
+ origin?: string | undefined;
92
+ pragma?: string | undefined;
93
+ "proxy-authenticate"?: string | undefined;
94
+ "proxy-authorization"?: string | undefined;
95
+ "public-key-pins"?: string | undefined;
96
+ range?: string | undefined;
97
+ referer?: string | undefined;
98
+ "retry-after"?: string | undefined;
99
+ "sec-fetch-site"?: string | undefined;
100
+ "sec-fetch-mode"?: string | undefined;
101
+ "sec-fetch-user"?: string | undefined;
102
+ "sec-fetch-dest"?: string | undefined;
103
+ "sec-websocket-accept"?: string | undefined;
104
+ "sec-websocket-extensions"?: string | undefined;
105
+ "sec-websocket-key"?: string | undefined;
106
+ "sec-websocket-protocol"?: string | undefined;
107
+ "sec-websocket-version"?: string | undefined;
108
+ "set-cookie"?: string[] | undefined;
109
+ "strict-transport-security"?: string | undefined;
110
+ tk?: string | undefined;
111
+ trailer?: string | undefined;
112
+ "transfer-encoding"?: string | undefined;
113
+ upgrade?: string | undefined;
114
+ "user-agent"?: string | undefined;
115
+ vary?: string | undefined;
116
+ via?: string | undefined;
117
+ warning?: string | undefined;
118
+ "www-authenticate"?: string | undefined;
119
+ }
120
+ // outgoing headers allows numbers (as they are converted internally to strings)
121
+ type OutgoingHttpHeader = number | string | string[];
122
+ interface OutgoingHttpHeaders extends NodeJS.Dict<OutgoingHttpHeader> {
123
+ accept?: string | string[] | undefined;
124
+ "accept-charset"?: string | string[] | undefined;
125
+ "accept-encoding"?: string | string[] | undefined;
126
+ "accept-language"?: string | string[] | undefined;
127
+ "accept-ranges"?: string | undefined;
128
+ "access-control-allow-credentials"?: string | undefined;
129
+ "access-control-allow-headers"?: string | undefined;
130
+ "access-control-allow-methods"?: string | undefined;
131
+ "access-control-allow-origin"?: string | undefined;
132
+ "access-control-expose-headers"?: string | undefined;
133
+ "access-control-max-age"?: string | undefined;
134
+ "access-control-request-headers"?: string | undefined;
135
+ "access-control-request-method"?: string | undefined;
136
+ age?: string | undefined;
137
+ allow?: string | undefined;
138
+ authorization?: string | undefined;
139
+ "cache-control"?: string | undefined;
140
+ "cdn-cache-control"?: string | undefined;
141
+ connection?: string | string[] | undefined;
142
+ "content-disposition"?: string | undefined;
143
+ "content-encoding"?: string | undefined;
144
+ "content-language"?: string | undefined;
145
+ "content-length"?: string | number | undefined;
146
+ "content-location"?: string | undefined;
147
+ "content-range"?: string | undefined;
148
+ "content-security-policy"?: string | undefined;
149
+ "content-security-policy-report-only"?: string | undefined;
150
+ cookie?: string | string[] | undefined;
151
+ dav?: string | string[] | undefined;
152
+ dnt?: string | undefined;
153
+ date?: string | undefined;
154
+ etag?: string | undefined;
155
+ expect?: string | undefined;
156
+ expires?: string | undefined;
157
+ forwarded?: string | undefined;
158
+ from?: string | undefined;
159
+ host?: string | undefined;
160
+ "if-match"?: string | undefined;
161
+ "if-modified-since"?: string | undefined;
162
+ "if-none-match"?: string | undefined;
163
+ "if-range"?: string | undefined;
164
+ "if-unmodified-since"?: string | undefined;
165
+ "last-modified"?: string | undefined;
166
+ link?: string | string[] | undefined;
167
+ location?: string | undefined;
168
+ "max-forwards"?: string | undefined;
169
+ origin?: string | undefined;
170
+ pragma?: string | string[] | undefined;
171
+ "proxy-authenticate"?: string | string[] | undefined;
172
+ "proxy-authorization"?: string | undefined;
173
+ "public-key-pins"?: string | undefined;
174
+ "public-key-pins-report-only"?: string | undefined;
175
+ range?: string | undefined;
176
+ referer?: string | undefined;
177
+ "referrer-policy"?: string | undefined;
178
+ refresh?: string | undefined;
179
+ "retry-after"?: string | undefined;
180
+ "sec-websocket-accept"?: string | undefined;
181
+ "sec-websocket-extensions"?: string | string[] | undefined;
182
+ "sec-websocket-key"?: string | undefined;
183
+ "sec-websocket-protocol"?: string | string[] | undefined;
184
+ "sec-websocket-version"?: string | undefined;
185
+ server?: string | undefined;
186
+ "set-cookie"?: string | string[] | undefined;
187
+ "strict-transport-security"?: string | undefined;
188
+ te?: string | undefined;
189
+ trailer?: string | undefined;
190
+ "transfer-encoding"?: string | undefined;
191
+ "user-agent"?: string | undefined;
192
+ upgrade?: string | undefined;
193
+ "upgrade-insecure-requests"?: string | undefined;
194
+ vary?: string | undefined;
195
+ via?: string | string[] | undefined;
196
+ warning?: string | undefined;
197
+ "www-authenticate"?: string | string[] | undefined;
198
+ "x-content-type-options"?: string | undefined;
199
+ "x-dns-prefetch-control"?: string | undefined;
200
+ "x-frame-options"?: string | undefined;
201
+ "x-xss-protection"?: string | undefined;
202
+ }
203
+ interface ClientRequestArgs extends Pick<LookupOptions, "hints"> {
204
+ _defaultAgent?: Agent | undefined;
205
+ agent?: Agent | boolean | undefined;
206
+ auth?: string | null | undefined;
207
+ createConnection?:
208
+ | ((
209
+ options: ClientRequestArgs,
210
+ oncreate: (err: Error | null, socket: stream.Duplex) => void,
211
+ ) => stream.Duplex | null | undefined)
212
+ | undefined;
213
+ defaultPort?: number | string | undefined;
214
+ family?: number | undefined;
215
+ headers?: OutgoingHttpHeaders | readonly string[] | undefined;
216
+ host?: string | null | undefined;
217
+ hostname?: string | null | undefined;
218
+ insecureHTTPParser?: boolean | undefined;
219
+ localAddress?: string | undefined;
220
+ localPort?: number | undefined;
221
+ lookup?: LookupFunction | undefined;
222
+ /**
223
+ * @default 16384
224
+ */
225
+ maxHeaderSize?: number | undefined;
226
+ method?: string | undefined;
227
+ path?: string | null | undefined;
228
+ port?: number | string | null | undefined;
229
+ protocol?: string | null | undefined;
230
+ setHost?: boolean | undefined;
231
+ signal?: AbortSignal | undefined;
232
+ socketPath?: string | undefined;
233
+ timeout?: number | undefined;
234
+ uniqueHeaders?: Array<string | string[]> | undefined;
235
+ joinDuplicateHeaders?: boolean | undefined;
236
+ }
237
+ interface ServerOptions<
238
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
239
+ Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
240
+ > {
241
+ /**
242
+ * Specifies the `IncomingMessage` class to be used. Useful for extending the original `IncomingMessage`.
243
+ */
244
+ IncomingMessage?: Request | undefined;
245
+ /**
246
+ * Specifies the `ServerResponse` class to be used. Useful for extending the original `ServerResponse`.
247
+ */
248
+ ServerResponse?: Response | undefined;
249
+ /**
250
+ * Sets the timeout value in milliseconds for receiving the entire request from the client.
251
+ * @see Server.requestTimeout for more information.
252
+ * @default 300000
253
+ * @since v18.0.0
254
+ */
255
+ requestTimeout?: number | undefined;
256
+ /**
257
+ * It joins the field line values of multiple headers in a request with `, ` instead of discarding the duplicates.
258
+ * @default false
259
+ * @since v18.14.0
260
+ */
261
+ joinDuplicateHeaders?: boolean | undefined;
262
+ /**
263
+ * The number of milliseconds of inactivity a server needs to wait for additional incoming data,
264
+ * after it has finished writing the last response, before a socket will be destroyed.
265
+ * @see Server.keepAliveTimeout for more information.
266
+ * @default 5000
267
+ * @since v18.0.0
268
+ */
269
+ keepAliveTimeout?: number | undefined;
270
+ /**
271
+ * Sets the interval value in milliseconds to check for request and headers timeout in incomplete requests.
272
+ * @default 30000
273
+ */
274
+ connectionsCheckingInterval?: number | undefined;
275
+ /**
276
+ * Sets the timeout value in milliseconds for receiving the complete HTTP headers from the client.
277
+ * See {@link Server.headersTimeout} for more information.
278
+ * @default 60000
279
+ * @since 18.0.0
280
+ */
281
+ headersTimeout?: number | undefined;
282
+ /**
283
+ * Optionally overrides all `socket`s' `readableHighWaterMark` and `writableHighWaterMark`.
284
+ * This affects `highWaterMark` property of both `IncomingMessage` and `ServerResponse`.
285
+ * Default: @see stream.getDefaultHighWaterMark().
286
+ * @since v20.1.0
287
+ */
288
+ highWaterMark?: number | undefined;
289
+ /**
290
+ * Use an insecure HTTP parser that accepts invalid HTTP headers when `true`.
291
+ * Using the insecure parser should be avoided.
292
+ * See --insecure-http-parser for more information.
293
+ * @default false
294
+ */
295
+ insecureHTTPParser?: boolean | undefined;
296
+ /**
297
+ * Optionally overrides the value of `--max-http-header-size` for requests received by
298
+ * this server, i.e. the maximum length of request headers in bytes.
299
+ * @default 16384
300
+ * @since v13.3.0
301
+ */
302
+ maxHeaderSize?: number | undefined;
303
+ /**
304
+ * If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.
305
+ * @default true
306
+ * @since v16.5.0
307
+ */
308
+ noDelay?: boolean | undefined;
309
+ /**
310
+ * If set to `true`, it forces the server to respond with a 400 (Bad Request) status code
311
+ * to any HTTP/1.1 request message that lacks a Host header (as mandated by the specification).
312
+ * @default true
313
+ * @since 20.0.0
314
+ */
315
+ requireHostHeader?: boolean | undefined;
316
+ /**
317
+ * If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received,
318
+ * similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`.
319
+ * @default false
320
+ * @since v16.5.0
321
+ */
322
+ keepAlive?: boolean | undefined;
323
+ /**
324
+ * If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket.
325
+ * @default 0
326
+ * @since v16.5.0
327
+ */
328
+ keepAliveInitialDelay?: number | undefined;
329
+ /**
330
+ * A list of response headers that should be sent only once.
331
+ * If the header's value is an array, the items will be joined using `; `.
332
+ */
333
+ uniqueHeaders?: Array<string | string[]> | undefined;
334
+ /**
335
+ * If set to `true`, an error is thrown when writing to an HTTP response which does not have a body.
336
+ * @default false
337
+ * @since v18.17.0, v20.2.0
338
+ */
339
+ rejectNonStandardBodyWrites?: boolean | undefined;
340
+ }
341
+ type RequestListener<
342
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
343
+ Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
344
+ > = (req: InstanceType<Request>, res: InstanceType<Response> & { req: InstanceType<Request> }) => void;
345
+ /**
346
+ * @since v0.1.17
347
+ */
348
+ class Server<
349
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
350
+ Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
351
+ > extends NetServer {
352
+ constructor(requestListener?: RequestListener<Request, Response>);
353
+ constructor(options: ServerOptions<Request, Response>, requestListener?: RequestListener<Request, Response>);
354
+ /**
355
+ * Sets the timeout value for sockets, and emits a `'timeout'` event on
356
+ * the Server object, passing the socket as an argument, if a timeout
357
+ * occurs.
358
+ *
359
+ * If there is a `'timeout'` event listener on the Server object, then it
360
+ * will be called with the timed-out socket as an argument.
361
+ *
362
+ * By default, the Server does not timeout sockets. However, if a callback
363
+ * is assigned to the Server's `'timeout'` event, timeouts must be handled
364
+ * explicitly.
365
+ * @since v0.9.12
366
+ * @param [msecs=0 (no timeout)]
367
+ */
368
+ setTimeout(msecs?: number, callback?: (socket: Socket) => void): this;
369
+ setTimeout(callback: (socket: Socket) => void): this;
370
+ /**
371
+ * Limits maximum incoming headers count. If set to 0, no limit will be applied.
372
+ * @since v0.7.0
373
+ */
374
+ maxHeadersCount: number | null;
375
+ /**
376
+ * The maximum number of requests socket can handle
377
+ * before closing keep alive connection.
378
+ *
379
+ * A value of `0` will disable the limit.
380
+ *
381
+ * When the limit is reached it will set the `Connection` header value to `close`,
382
+ * but will not actually close the connection, subsequent requests sent
383
+ * after the limit is reached will get `503 Service Unavailable` as a response.
384
+ * @since v16.10.0
385
+ */
386
+ maxRequestsPerSocket: number | null;
387
+ /**
388
+ * The number of milliseconds of inactivity before a socket is presumed
389
+ * to have timed out.
390
+ *
391
+ * A value of `0` will disable the timeout behavior on incoming connections.
392
+ *
393
+ * The socket timeout logic is set up on connection, so changing this
394
+ * value only affects new connections to the server, not any existing connections.
395
+ * @since v0.9.12
396
+ */
397
+ timeout: number;
398
+ /**
399
+ * Limit the amount of time the parser will wait to receive the complete HTTP
400
+ * headers.
401
+ *
402
+ * If the timeout expires, the server responds with status 408 without
403
+ * forwarding the request to the request listener and then closes the connection.
404
+ *
405
+ * It must be set to a non-zero value (e.g. 120 seconds) to protect against
406
+ * potential Denial-of-Service attacks in case the server is deployed without a
407
+ * reverse proxy in front.
408
+ * @since v11.3.0, v10.14.0
409
+ */
410
+ headersTimeout: number;
411
+ /**
412
+ * The number of milliseconds of inactivity a server needs to wait for additional
413
+ * incoming data, after it has finished writing the last response, before a socket
414
+ * will be destroyed. If the server receives new data before the keep-alive
415
+ * timeout has fired, it will reset the regular inactivity timeout, i.e., `server.timeout`.
416
+ *
417
+ * A value of `0` will disable the keep-alive timeout behavior on incoming
418
+ * connections.
419
+ * A value of `0` makes the http server behave similarly to Node.js versions prior
420
+ * to 8.0.0, which did not have a keep-alive timeout.
421
+ *
422
+ * The socket timeout logic is set up on connection, so changing this value only
423
+ * affects new connections to the server, not any existing connections.
424
+ * @since v8.0.0
425
+ */
426
+ keepAliveTimeout: number;
427
+ /**
428
+ * Sets the timeout value in milliseconds for receiving the entire request from
429
+ * the client.
430
+ *
431
+ * If the timeout expires, the server responds with status 408 without
432
+ * forwarding the request to the request listener and then closes the connection.
433
+ *
434
+ * It must be set to a non-zero value (e.g. 120 seconds) to protect against
435
+ * potential Denial-of-Service attacks in case the server is deployed without a
436
+ * reverse proxy in front.
437
+ * @since v14.11.0
438
+ */
439
+ requestTimeout: number;
440
+ /**
441
+ * Closes all connections connected to this server.
442
+ * @since v18.2.0
443
+ */
444
+ closeAllConnections(): void;
445
+ /**
446
+ * Closes all connections connected to this server which are not sending a request
447
+ * or waiting for a response.
448
+ * @since v18.2.0
449
+ */
450
+ closeIdleConnections(): void;
451
+ addListener(event: string, listener: (...args: any[]) => void): this;
452
+ addListener(event: "close", listener: () => void): this;
453
+ addListener(event: "connection", listener: (socket: Socket) => void): this;
454
+ addListener(event: "error", listener: (err: Error) => void): this;
455
+ addListener(event: "listening", listener: () => void): this;
456
+ addListener(event: "checkContinue", listener: RequestListener<Request, Response>): this;
457
+ addListener(event: "checkExpectation", listener: RequestListener<Request, Response>): this;
458
+ addListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;
459
+ addListener(
460
+ event: "connect",
461
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: NonSharedBuffer) => void,
462
+ ): this;
463
+ addListener(event: "dropRequest", listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
464
+ addListener(event: "request", listener: RequestListener<Request, Response>): this;
465
+ addListener(
466
+ event: "upgrade",
467
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: NonSharedBuffer) => void,
468
+ ): this;
469
+ emit(event: string, ...args: any[]): boolean;
470
+ emit(event: "close"): boolean;
471
+ emit(event: "connection", socket: Socket): boolean;
472
+ emit(event: "error", err: Error): boolean;
473
+ emit(event: "listening"): boolean;
474
+ emit(
475
+ event: "checkContinue",
476
+ req: InstanceType<Request>,
477
+ res: InstanceType<Response> & { req: InstanceType<Request> },
478
+ ): boolean;
479
+ emit(
480
+ event: "checkExpectation",
481
+ req: InstanceType<Request>,
482
+ res: InstanceType<Response> & { req: InstanceType<Request> },
483
+ ): boolean;
484
+ emit(event: "clientError", err: Error, socket: stream.Duplex): boolean;
485
+ emit(event: "connect", req: InstanceType<Request>, socket: stream.Duplex, head: NonSharedBuffer): boolean;
486
+ emit(event: "dropRequest", req: InstanceType<Request>, socket: stream.Duplex): boolean;
487
+ emit(
488
+ event: "request",
489
+ req: InstanceType<Request>,
490
+ res: InstanceType<Response> & { req: InstanceType<Request> },
491
+ ): boolean;
492
+ emit(event: "upgrade", req: InstanceType<Request>, socket: stream.Duplex, head: NonSharedBuffer): boolean;
493
+ on(event: string, listener: (...args: any[]) => void): this;
494
+ on(event: "close", listener: () => void): this;
495
+ on(event: "connection", listener: (socket: Socket) => void): this;
496
+ on(event: "error", listener: (err: Error) => void): this;
497
+ on(event: "listening", listener: () => void): this;
498
+ on(event: "checkContinue", listener: RequestListener<Request, Response>): this;
499
+ on(event: "checkExpectation", listener: RequestListener<Request, Response>): this;
500
+ on(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;
501
+ on(
502
+ event: "connect",
503
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: NonSharedBuffer) => void,
504
+ ): this;
505
+ on(event: "dropRequest", listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
506
+ on(event: "request", listener: RequestListener<Request, Response>): this;
507
+ on(
508
+ event: "upgrade",
509
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: NonSharedBuffer) => void,
510
+ ): this;
511
+ once(event: string, listener: (...args: any[]) => void): this;
512
+ once(event: "close", listener: () => void): this;
513
+ once(event: "connection", listener: (socket: Socket) => void): this;
514
+ once(event: "error", listener: (err: Error) => void): this;
515
+ once(event: "listening", listener: () => void): this;
516
+ once(event: "checkContinue", listener: RequestListener<Request, Response>): this;
517
+ once(event: "checkExpectation", listener: RequestListener<Request, Response>): this;
518
+ once(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;
519
+ once(
520
+ event: "connect",
521
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: NonSharedBuffer) => void,
522
+ ): this;
523
+ once(event: "dropRequest", listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;
524
+ once(event: "request", listener: RequestListener<Request, Response>): this;
525
+ once(
526
+ event: "upgrade",
527
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: NonSharedBuffer) => void,
528
+ ): this;
529
+ prependListener(event: string, listener: (...args: any[]) => void): this;
530
+ prependListener(event: "close", listener: () => void): this;
531
+ prependListener(event: "connection", listener: (socket: Socket) => void): this;
532
+ prependListener(event: "error", listener: (err: Error) => void): this;
533
+ prependListener(event: "listening", listener: () => void): this;
534
+ prependListener(event: "checkContinue", listener: RequestListener<Request, Response>): this;
535
+ prependListener(event: "checkExpectation", listener: RequestListener<Request, Response>): this;
536
+ prependListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;
537
+ prependListener(
538
+ event: "connect",
539
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: NonSharedBuffer) => void,
540
+ ): this;
541
+ prependListener(
542
+ event: "dropRequest",
543
+ listener: (req: InstanceType<Request>, socket: stream.Duplex) => void,
544
+ ): this;
545
+ prependListener(event: "request", listener: RequestListener<Request, Response>): this;
546
+ prependListener(
547
+ event: "upgrade",
548
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: NonSharedBuffer) => void,
549
+ ): this;
550
+ prependOnceListener(event: string, listener: (...args: any[]) => void): this;
551
+ prependOnceListener(event: "close", listener: () => void): this;
552
+ prependOnceListener(event: "connection", listener: (socket: Socket) => void): this;
553
+ prependOnceListener(event: "error", listener: (err: Error) => void): this;
554
+ prependOnceListener(event: "listening", listener: () => void): this;
555
+ prependOnceListener(event: "checkContinue", listener: RequestListener<Request, Response>): this;
556
+ prependOnceListener(event: "checkExpectation", listener: RequestListener<Request, Response>): this;
557
+ prependOnceListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;
558
+ prependOnceListener(
559
+ event: "connect",
560
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: NonSharedBuffer) => void,
561
+ ): this;
562
+ prependOnceListener(
563
+ event: "dropRequest",
564
+ listener: (req: InstanceType<Request>, socket: stream.Duplex) => void,
565
+ ): this;
566
+ prependOnceListener(event: "request", listener: RequestListener<Request, Response>): this;
567
+ prependOnceListener(
568
+ event: "upgrade",
569
+ listener: (req: InstanceType<Request>, socket: stream.Duplex, head: NonSharedBuffer) => void,
570
+ ): this;
571
+ }
572
+ /**
573
+ * This class serves as the parent class of {@link ClientRequest} and {@link ServerResponse}. It is an abstract outgoing message from
574
+ * the perspective of the participants of an HTTP transaction.
575
+ * @since v0.1.17
576
+ */
577
+ class OutgoingMessage<Request extends IncomingMessage = IncomingMessage> extends stream.Writable {
578
+ readonly req: Request;
579
+ chunkedEncoding: boolean;
580
+ shouldKeepAlive: boolean;
581
+ useChunkedEncodingByDefault: boolean;
582
+ sendDate: boolean;
583
+ /**
584
+ * @deprecated Use `writableEnded` instead.
585
+ */
586
+ finished: boolean;
587
+ /**
588
+ * Read-only. `true` if the headers were sent, otherwise `false`.
589
+ * @since v0.9.3
590
+ */
591
+ readonly headersSent: boolean;
592
+ /**
593
+ * Alias of `outgoingMessage.socket`.
594
+ * @since v0.3.0
595
+ * @deprecated Since v15.12.0,v14.17.1 - Use `socket` instead.
596
+ */
597
+ readonly connection: Socket | null;
598
+ /**
599
+ * Reference to the underlying socket. Usually, users will not want to access
600
+ * this property.
601
+ *
602
+ * After calling `outgoingMessage.end()`, this property will be nulled.
603
+ * @since v0.3.0
604
+ */
605
+ readonly socket: Socket | null;
606
+ constructor();
607
+ /**
608
+ * Once a socket is associated with the message and is connected, `socket.setTimeout()` will be called with `msecs` as the first parameter.
609
+ * @since v0.9.12
610
+ * @param callback Optional function to be called when a timeout occurs. Same as binding to the `timeout` event.
611
+ */
612
+ setTimeout(msecs: number, callback?: () => void): this;
613
+ /**
614
+ * Sets a single header value. If the header already exists in the to-be-sent
615
+ * headers, its value will be replaced. Use an array of strings to send multiple
616
+ * headers with the same name.
617
+ * @since v0.4.0
618
+ * @param name Header name
619
+ * @param value Header value
620
+ */
621
+ setHeader(name: string, value: number | string | readonly string[]): this;
622
+ /**
623
+ * Sets multiple header values for implicit headers. headers must be an instance of
624
+ * `Headers` or `Map`, if a header already exists in the to-be-sent headers, its
625
+ * value will be replaced.
626
+ *
627
+ * ```js
628
+ * const headers = new Headers({ foo: 'bar' });
629
+ * outgoingMessage.setHeaders(headers);
630
+ * ```
631
+ *
632
+ * or
633
+ *
634
+ * ```js
635
+ * const headers = new Map([['foo', 'bar']]);
636
+ * outgoingMessage.setHeaders(headers);
637
+ * ```
638
+ *
639
+ * When headers have been set with `outgoingMessage.setHeaders()`, they will be
640
+ * merged with any headers passed to `response.writeHead()`, with the headers passed
641
+ * to `response.writeHead()` given precedence.
642
+ *
643
+ * ```js
644
+ * // Returns content-type = text/plain
645
+ * const server = http.createServer((req, res) => {
646
+ * const headers = new Headers({ 'Content-Type': 'text/html' });
647
+ * res.setHeaders(headers);
648
+ * res.writeHead(200, { 'Content-Type': 'text/plain' });
649
+ * res.end('ok');
650
+ * });
651
+ * ```
652
+ *
653
+ * @since v19.6.0, v18.15.0
654
+ * @param name Header name
655
+ * @param value Header value
656
+ */
657
+ setHeaders(headers: Headers | Map<string, number | string | readonly string[]>): this;
658
+ /**
659
+ * Append a single header value to the header object.
660
+ *
661
+ * If the value is an array, this is equivalent to calling this method multiple
662
+ * times.
663
+ *
664
+ * If there were no previous values for the header, this is equivalent to calling `outgoingMessage.setHeader(name, value)`.
665
+ *
666
+ * Depending of the value of `options.uniqueHeaders` when the client request or the
667
+ * server were created, this will end up in the header being sent multiple times or
668
+ * a single time with values joined using `; `.
669
+ * @since v18.3.0, v16.17.0
670
+ * @param name Header name
671
+ * @param value Header value
672
+ */
673
+ appendHeader(name: string, value: string | readonly string[]): this;
674
+ /**
675
+ * Gets the value of the HTTP header with the given name. If that header is not
676
+ * set, the returned value will be `undefined`.
677
+ * @since v0.4.0
678
+ * @param name Name of header
679
+ */
680
+ getHeader(name: string): number | string | string[] | undefined;
681
+ /**
682
+ * Returns a shallow copy of the current outgoing headers. Since a shallow
683
+ * copy is used, array values may be mutated without additional calls to
684
+ * various header-related HTTP module methods. The keys of the returned
685
+ * object are the header names and the values are the respective header
686
+ * values. All header names are lowercase.
687
+ *
688
+ * The object returned by the `outgoingMessage.getHeaders()` method does
689
+ * not prototypically inherit from the JavaScript `Object`. This means that
690
+ * typical `Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`,
691
+ * and others are not defined and will not work.
692
+ *
693
+ * ```js
694
+ * outgoingMessage.setHeader('Foo', 'bar');
695
+ * outgoingMessage.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
696
+ *
697
+ * const headers = outgoingMessage.getHeaders();
698
+ * // headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }
699
+ * ```
700
+ * @since v7.7.0
701
+ */
702
+ getHeaders(): OutgoingHttpHeaders;
703
+ /**
704
+ * Returns an array containing the unique names of the current outgoing headers.
705
+ * All names are lowercase.
706
+ * @since v7.7.0
707
+ */
708
+ getHeaderNames(): string[];
709
+ /**
710
+ * Returns `true` if the header identified by `name` is currently set in the
711
+ * outgoing headers. The header name is case-insensitive.
712
+ *
713
+ * ```js
714
+ * const hasContentType = outgoingMessage.hasHeader('content-type');
715
+ * ```
716
+ * @since v7.7.0
717
+ */
718
+ hasHeader(name: string): boolean;
719
+ /**
720
+ * Removes a header that is queued for implicit sending.
721
+ *
722
+ * ```js
723
+ * outgoingMessage.removeHeader('Content-Encoding');
724
+ * ```
725
+ * @since v0.4.0
726
+ * @param name Header name
727
+ */
728
+ removeHeader(name: string): void;
729
+ /**
730
+ * Adds HTTP trailers (headers but at the end of the message) to the message.
731
+ *
732
+ * Trailers will **only** be emitted if the message is chunked encoded. If not,
733
+ * the trailers will be silently discarded.
734
+ *
735
+ * HTTP requires the `Trailer` header to be sent to emit trailers,
736
+ * with a list of header field names in its value, e.g.
737
+ *
738
+ * ```js
739
+ * message.writeHead(200, { 'Content-Type': 'text/plain',
740
+ * 'Trailer': 'Content-MD5' });
741
+ * message.write(fileData);
742
+ * message.addTrailers({ 'Content-MD5': '7895bf4b8828b55ceaf47747b4bca667' });
743
+ * message.end();
744
+ * ```
745
+ *
746
+ * Attempting to set a header field name or value that contains invalid characters
747
+ * will result in a `TypeError` being thrown.
748
+ * @since v0.3.0
749
+ */
750
+ addTrailers(headers: OutgoingHttpHeaders | ReadonlyArray<[string, string]>): void;
751
+ /**
752
+ * Flushes the message headers.
753
+ *
754
+ * For efficiency reason, Node.js normally buffers the message headers
755
+ * until `outgoingMessage.end()` is called or the first chunk of message data
756
+ * is written. It then tries to pack the headers and data into a single TCP
757
+ * packet.
758
+ *
759
+ * It is usually desired (it saves a TCP round-trip), but not when the first
760
+ * data is not sent until possibly much later. `outgoingMessage.flushHeaders()` bypasses the optimization and kickstarts the message.
761
+ * @since v1.6.0
762
+ */
763
+ flushHeaders(): void;
764
+ }
765
+ /**
766
+ * This object is created internally by an HTTP server, not by the user. It is
767
+ * passed as the second parameter to the `'request'` event.
768
+ * @since v0.1.17
769
+ */
770
+ class ServerResponse<Request extends IncomingMessage = IncomingMessage> extends OutgoingMessage<Request> {
771
+ /**
772
+ * When using implicit headers (not calling `response.writeHead()` explicitly),
773
+ * this property controls the status code that will be sent to the client when
774
+ * the headers get flushed.
775
+ *
776
+ * ```js
777
+ * response.statusCode = 404;
778
+ * ```
779
+ *
780
+ * After response header was sent to the client, this property indicates the
781
+ * status code which was sent out.
782
+ * @since v0.4.0
783
+ */
784
+ statusCode: number;
785
+ /**
786
+ * When using implicit headers (not calling `response.writeHead()` explicitly),
787
+ * this property controls the status message that will be sent to the client when
788
+ * the headers get flushed. If this is left as `undefined` then the standard
789
+ * message for the status code will be used.
790
+ *
791
+ * ```js
792
+ * response.statusMessage = 'Not found';
793
+ * ```
794
+ *
795
+ * After response header was sent to the client, this property indicates the
796
+ * status message which was sent out.
797
+ * @since v0.11.8
798
+ */
799
+ statusMessage: string;
800
+ /**
801
+ * If set to `true`, Node.js will check whether the `Content-Length` header value and the size of the body, in bytes, are equal.
802
+ * Mismatching the `Content-Length` header value will result
803
+ * in an `Error` being thrown, identified by `code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.
804
+ * @since v18.10.0, v16.18.0
805
+ */
806
+ strictContentLength: boolean;
807
+ constructor(req: Request);
808
+ assignSocket(socket: Socket): void;
809
+ detachSocket(socket: Socket): void;
810
+ /**
811
+ * Sends an HTTP/1.1 100 Continue message to the client, indicating that
812
+ * the request body should be sent. See the `'checkContinue'` event on `Server`.
813
+ * @since v0.3.0
814
+ */
815
+ writeContinue(callback?: () => void): void;
816
+ /**
817
+ * Sends an HTTP/1.1 103 Early Hints message to the client with a Link header,
818
+ * indicating that the user agent can preload/preconnect the linked resources.
819
+ * The `hints` is an object containing the values of headers to be sent with
820
+ * early hints message. The optional `callback` argument will be called when
821
+ * the response message has been written.
822
+ *
823
+ * **Example**
824
+ *
825
+ * ```js
826
+ * const earlyHintsLink = '</styles.css>; rel=preload; as=style';
827
+ * response.writeEarlyHints({
828
+ * 'link': earlyHintsLink,
829
+ * });
830
+ *
831
+ * const earlyHintsLinks = [
832
+ * '</styles.css>; rel=preload; as=style',
833
+ * '</scripts.js>; rel=preload; as=script',
834
+ * ];
835
+ * response.writeEarlyHints({
836
+ * 'link': earlyHintsLinks,
837
+ * 'x-trace-id': 'id for diagnostics',
838
+ * });
839
+ *
840
+ * const earlyHintsCallback = () => console.log('early hints message sent');
841
+ * response.writeEarlyHints({
842
+ * 'link': earlyHintsLinks,
843
+ * }, earlyHintsCallback);
844
+ * ```
845
+ * @since v18.11.0
846
+ * @param hints An object containing the values of headers
847
+ * @param callback Will be called when the response message has been written
848
+ */
849
+ writeEarlyHints(hints: Record<string, string | string[]>, callback?: () => void): void;
850
+ /**
851
+ * Sends a response header to the request. The status code is a 3-digit HTTP
852
+ * status code, like `404`. The last argument, `headers`, are the response headers.
853
+ * Optionally one can give a human-readable `statusMessage` as the second
854
+ * argument.
855
+ *
856
+ * `headers` may be an `Array` where the keys and values are in the same list.
857
+ * It is _not_ a list of tuples. So, the even-numbered offsets are key values,
858
+ * and the odd-numbered offsets are the associated values. The array is in the same
859
+ * format as `request.rawHeaders`.
860
+ *
861
+ * Returns a reference to the `ServerResponse`, so that calls can be chained.
862
+ *
863
+ * ```js
864
+ * const body = 'hello world';
865
+ * response
866
+ * .writeHead(200, {
867
+ * 'Content-Length': Buffer.byteLength(body),
868
+ * 'Content-Type': 'text/plain',
869
+ * })
870
+ * .end(body);
871
+ * ```
872
+ *
873
+ * This method must only be called once on a message and it must
874
+ * be called before `response.end()` is called.
875
+ *
876
+ * If `response.write()` or `response.end()` are called before calling
877
+ * this, the implicit/mutable headers will be calculated and call this function.
878
+ *
879
+ * When headers have been set with `response.setHeader()`, they will be merged
880
+ * with any headers passed to `response.writeHead()`, with the headers passed
881
+ * to `response.writeHead()` given precedence.
882
+ *
883
+ * If this method is called and `response.setHeader()` has not been called,
884
+ * it will directly write the supplied header values onto the network channel
885
+ * without caching internally, and the `response.getHeader()` on the header
886
+ * will not yield the expected result. If progressive population of headers is
887
+ * desired with potential future retrieval and modification, use `response.setHeader()` instead.
888
+ *
889
+ * ```js
890
+ * // Returns content-type = text/plain
891
+ * const server = http.createServer((req, res) => {
892
+ * res.setHeader('Content-Type', 'text/html');
893
+ * res.setHeader('X-Foo', 'bar');
894
+ * res.writeHead(200, { 'Content-Type': 'text/plain' });
895
+ * res.end('ok');
896
+ * });
897
+ * ```
898
+ *
899
+ * `Content-Length` is read in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes. Node.js
900
+ * will check whether `Content-Length` and the length of the body which has
901
+ * been transmitted are equal or not.
902
+ *
903
+ * Attempting to set a header field name or value that contains invalid characters
904
+ * will result in a \[`Error`\]\[\] being thrown.
905
+ * @since v0.1.30
906
+ */
907
+ writeHead(
908
+ statusCode: number,
909
+ statusMessage?: string,
910
+ headers?: OutgoingHttpHeaders | OutgoingHttpHeader[],
911
+ ): this;
912
+ writeHead(statusCode: number, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[]): this;
913
+ /**
914
+ * Sends a HTTP/1.1 102 Processing message to the client, indicating that
915
+ * the request body should be sent.
916
+ * @since v10.0.0
917
+ */
918
+ writeProcessing(callback?: () => void): void;
919
+ }
920
+ interface InformationEvent {
921
+ statusCode: number;
922
+ statusMessage: string;
923
+ httpVersion: string;
924
+ httpVersionMajor: number;
925
+ httpVersionMinor: number;
926
+ headers: IncomingHttpHeaders;
927
+ rawHeaders: string[];
928
+ }
929
+ /**
930
+ * This object is created internally and returned from {@link request}. It
931
+ * represents an _in-progress_ request whose header has already been queued. The
932
+ * header is still mutable using the `setHeader(name, value)`, `getHeader(name)`, `removeHeader(name)` API. The actual header will
933
+ * be sent along with the first data chunk or when calling `request.end()`.
934
+ *
935
+ * To get the response, add a listener for `'response'` to the request object. `'response'` will be emitted from the request object when the response
936
+ * headers have been received. The `'response'` event is executed with one
937
+ * argument which is an instance of {@link IncomingMessage}.
938
+ *
939
+ * During the `'response'` event, one can add listeners to the
940
+ * response object; particularly to listen for the `'data'` event.
941
+ *
942
+ * If no `'response'` handler is added, then the response will be
943
+ * entirely discarded. However, if a `'response'` event handler is added,
944
+ * then the data from the response object **must** be consumed, either by
945
+ * calling `response.read()` whenever there is a `'readable'` event, or
946
+ * by adding a `'data'` handler, or by calling the `.resume()` method.
947
+ * Until the data is consumed, the `'end'` event will not fire. Also, until
948
+ * the data is read it will consume memory that can eventually lead to a
949
+ * 'process out of memory' error.
950
+ *
951
+ * For backward compatibility, `res` will only emit `'error'` if there is an `'error'` listener registered.
952
+ *
953
+ * Set `Content-Length` header to limit the response body size.
954
+ * If `response.strictContentLength` is set to `true`, mismatching the `Content-Length` header value will result in an `Error` being thrown,
955
+ * identified by `code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.
956
+ *
957
+ * `Content-Length` value should be in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes.
958
+ * @since v0.1.17
959
+ */
960
+ class ClientRequest extends OutgoingMessage {
961
+ /**
962
+ * The `request.aborted` property will be `true` if the request has
963
+ * been aborted.
964
+ * @since v0.11.14
965
+ * @deprecated Since v17.0.0, v16.12.0 - Check `destroyed` instead.
966
+ */
967
+ aborted: boolean;
968
+ /**
969
+ * The request host.
970
+ * @since v14.5.0, v12.19.0
971
+ */
972
+ host: string;
973
+ /**
974
+ * The request protocol.
975
+ * @since v14.5.0, v12.19.0
976
+ */
977
+ protocol: string;
978
+ /**
979
+ * When sending request through a keep-alive enabled agent, the underlying socket
980
+ * might be reused. But if server closes connection at unfortunate time, client
981
+ * may run into a 'ECONNRESET' error.
982
+ *
983
+ * ```js
984
+ * import http from 'node:http';
985
+ *
986
+ * // Server has a 5 seconds keep-alive timeout by default
987
+ * http
988
+ * .createServer((req, res) => {
989
+ * res.write('hello\n');
990
+ * res.end();
991
+ * })
992
+ * .listen(3000);
993
+ *
994
+ * setInterval(() => {
995
+ * // Adapting a keep-alive agent
996
+ * http.get('http://localhost:3000', { agent }, (res) => {
997
+ * res.on('data', (data) => {
998
+ * // Do nothing
999
+ * });
1000
+ * });
1001
+ * }, 5000); // Sending request on 5s interval so it's easy to hit idle timeout
1002
+ * ```
1003
+ *
1004
+ * By marking a request whether it reused socket or not, we can do
1005
+ * automatic error retry base on it.
1006
+ *
1007
+ * ```js
1008
+ * import http from 'node:http';
1009
+ * const agent = new http.Agent({ keepAlive: true });
1010
+ *
1011
+ * function retriableRequest() {
1012
+ * const req = http
1013
+ * .get('http://localhost:3000', { agent }, (res) => {
1014
+ * // ...
1015
+ * })
1016
+ * .on('error', (err) => {
1017
+ * // Check if retry is needed
1018
+ * if (req.reusedSocket &#x26;&#x26; err.code === 'ECONNRESET') {
1019
+ * retriableRequest();
1020
+ * }
1021
+ * });
1022
+ * }
1023
+ *
1024
+ * retriableRequest();
1025
+ * ```
1026
+ * @since v13.0.0, v12.16.0
1027
+ */
1028
+ reusedSocket: boolean;
1029
+ /**
1030
+ * Limits maximum response headers count. If set to 0, no limit will be applied.
1031
+ */
1032
+ maxHeadersCount: number;
1033
+ constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void);
1034
+ /**
1035
+ * The request method.
1036
+ * @since v0.1.97
1037
+ */
1038
+ method: string;
1039
+ /**
1040
+ * The request path.
1041
+ * @since v0.4.0
1042
+ */
1043
+ path: string;
1044
+ /**
1045
+ * Marks the request as aborting. Calling this will cause remaining data
1046
+ * in the response to be dropped and the socket to be destroyed.
1047
+ * @since v0.3.8
1048
+ * @deprecated Since v14.1.0,v13.14.0 - Use `destroy` instead.
1049
+ */
1050
+ abort(): void;
1051
+ onSocket(socket: Socket): void;
1052
+ /**
1053
+ * Once a socket is assigned to this request and is connected `socket.setTimeout()` will be called.
1054
+ * @since v0.5.9
1055
+ * @param timeout Milliseconds before a request times out.
1056
+ * @param callback Optional function to be called when a timeout occurs. Same as binding to the `'timeout'` event.
1057
+ */
1058
+ setTimeout(timeout: number, callback?: () => void): this;
1059
+ /**
1060
+ * Once a socket is assigned to this request and is connected `socket.setNoDelay()` will be called.
1061
+ * @since v0.5.9
1062
+ */
1063
+ setNoDelay(noDelay?: boolean): void;
1064
+ /**
1065
+ * Once a socket is assigned to this request and is connected `socket.setKeepAlive()` will be called.
1066
+ * @since v0.5.9
1067
+ */
1068
+ setSocketKeepAlive(enable?: boolean, initialDelay?: number): void;
1069
+ /**
1070
+ * Returns an array containing the unique names of the current outgoing raw
1071
+ * headers. Header names are returned with their exact casing being set.
1072
+ *
1073
+ * ```js
1074
+ * request.setHeader('Foo', 'bar');
1075
+ * request.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
1076
+ *
1077
+ * const headerNames = request.getRawHeaderNames();
1078
+ * // headerNames === ['Foo', 'Set-Cookie']
1079
+ * ```
1080
+ * @since v15.13.0, v14.17.0
1081
+ */
1082
+ getRawHeaderNames(): string[];
1083
+ /**
1084
+ * @deprecated
1085
+ */
1086
+ addListener(event: "abort", listener: () => void): this;
1087
+ addListener(
1088
+ event: "connect",
1089
+ listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void,
1090
+ ): this;
1091
+ addListener(event: "continue", listener: () => void): this;
1092
+ addListener(event: "information", listener: (info: InformationEvent) => void): this;
1093
+ addListener(event: "response", listener: (response: IncomingMessage) => void): this;
1094
+ addListener(event: "socket", listener: (socket: Socket) => void): this;
1095
+ addListener(event: "timeout", listener: () => void): this;
1096
+ addListener(
1097
+ event: "upgrade",
1098
+ listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void,
1099
+ ): this;
1100
+ addListener(event: "close", listener: () => void): this;
1101
+ addListener(event: "drain", listener: () => void): this;
1102
+ addListener(event: "error", listener: (err: Error) => void): this;
1103
+ addListener(event: "finish", listener: () => void): this;
1104
+ addListener(event: "pipe", listener: (src: stream.Readable) => void): this;
1105
+ addListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
1106
+ addListener(event: string | symbol, listener: (...args: any[]) => void): this;
1107
+ /**
1108
+ * @deprecated
1109
+ */
1110
+ on(event: "abort", listener: () => void): this;
1111
+ on(
1112
+ event: "connect",
1113
+ listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void,
1114
+ ): this;
1115
+ on(event: "continue", listener: () => void): this;
1116
+ on(event: "information", listener: (info: InformationEvent) => void): this;
1117
+ on(event: "response", listener: (response: IncomingMessage) => void): this;
1118
+ on(event: "socket", listener: (socket: Socket) => void): this;
1119
+ on(event: "timeout", listener: () => void): this;
1120
+ on(
1121
+ event: "upgrade",
1122
+ listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void,
1123
+ ): this;
1124
+ on(event: "close", listener: () => void): this;
1125
+ on(event: "drain", listener: () => void): this;
1126
+ on(event: "error", listener: (err: Error) => void): this;
1127
+ on(event: "finish", listener: () => void): this;
1128
+ on(event: "pipe", listener: (src: stream.Readable) => void): this;
1129
+ on(event: "unpipe", listener: (src: stream.Readable) => void): this;
1130
+ on(event: string | symbol, listener: (...args: any[]) => void): this;
1131
+ /**
1132
+ * @deprecated
1133
+ */
1134
+ once(event: "abort", listener: () => void): this;
1135
+ once(
1136
+ event: "connect",
1137
+ listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void,
1138
+ ): this;
1139
+ once(event: "continue", listener: () => void): this;
1140
+ once(event: "information", listener: (info: InformationEvent) => void): this;
1141
+ once(event: "response", listener: (response: IncomingMessage) => void): this;
1142
+ once(event: "socket", listener: (socket: Socket) => void): this;
1143
+ once(event: "timeout", listener: () => void): this;
1144
+ once(
1145
+ event: "upgrade",
1146
+ listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void,
1147
+ ): this;
1148
+ once(event: "close", listener: () => void): this;
1149
+ once(event: "drain", listener: () => void): this;
1150
+ once(event: "error", listener: (err: Error) => void): this;
1151
+ once(event: "finish", listener: () => void): this;
1152
+ once(event: "pipe", listener: (src: stream.Readable) => void): this;
1153
+ once(event: "unpipe", listener: (src: stream.Readable) => void): this;
1154
+ once(event: string | symbol, listener: (...args: any[]) => void): this;
1155
+ /**
1156
+ * @deprecated
1157
+ */
1158
+ prependListener(event: "abort", listener: () => void): this;
1159
+ prependListener(
1160
+ event: "connect",
1161
+ listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void,
1162
+ ): this;
1163
+ prependListener(event: "continue", listener: () => void): this;
1164
+ prependListener(event: "information", listener: (info: InformationEvent) => void): this;
1165
+ prependListener(event: "response", listener: (response: IncomingMessage) => void): this;
1166
+ prependListener(event: "socket", listener: (socket: Socket) => void): this;
1167
+ prependListener(event: "timeout", listener: () => void): this;
1168
+ prependListener(
1169
+ event: "upgrade",
1170
+ listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void,
1171
+ ): this;
1172
+ prependListener(event: "close", listener: () => void): this;
1173
+ prependListener(event: "drain", listener: () => void): this;
1174
+ prependListener(event: "error", listener: (err: Error) => void): this;
1175
+ prependListener(event: "finish", listener: () => void): this;
1176
+ prependListener(event: "pipe", listener: (src: stream.Readable) => void): this;
1177
+ prependListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
1178
+ prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
1179
+ /**
1180
+ * @deprecated
1181
+ */
1182
+ prependOnceListener(event: "abort", listener: () => void): this;
1183
+ prependOnceListener(
1184
+ event: "connect",
1185
+ listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void,
1186
+ ): this;
1187
+ prependOnceListener(event: "continue", listener: () => void): this;
1188
+ prependOnceListener(event: "information", listener: (info: InformationEvent) => void): this;
1189
+ prependOnceListener(event: "response", listener: (response: IncomingMessage) => void): this;
1190
+ prependOnceListener(event: "socket", listener: (socket: Socket) => void): this;
1191
+ prependOnceListener(event: "timeout", listener: () => void): this;
1192
+ prependOnceListener(
1193
+ event: "upgrade",
1194
+ listener: (response: IncomingMessage, socket: Socket, head: NonSharedBuffer) => void,
1195
+ ): this;
1196
+ prependOnceListener(event: "close", listener: () => void): this;
1197
+ prependOnceListener(event: "drain", listener: () => void): this;
1198
+ prependOnceListener(event: "error", listener: (err: Error) => void): this;
1199
+ prependOnceListener(event: "finish", listener: () => void): this;
1200
+ prependOnceListener(event: "pipe", listener: (src: stream.Readable) => void): this;
1201
+ prependOnceListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
1202
+ prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
1203
+ }
1204
+ /**
1205
+ * 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
1206
+ * access response
1207
+ * status, headers, and data.
1208
+ *
1209
+ * Different from its `socket` value which is a subclass of `stream.Duplex`, the `IncomingMessage` itself extends `stream.Readable` and is created separately to
1210
+ * parse and emit the incoming HTTP headers and payload, as the underlying socket
1211
+ * may be reused multiple times in case of keep-alive.
1212
+ * @since v0.1.17
1213
+ */
1214
+ class IncomingMessage extends stream.Readable {
1215
+ constructor(socket: Socket);
1216
+ /**
1217
+ * The `message.aborted` property will be `true` if the request has
1218
+ * been aborted.
1219
+ * @since v10.1.0
1220
+ * @deprecated Since v17.0.0,v16.12.0 - Check `message.destroyed` from <a href="stream.html#class-streamreadable" class="type">stream.Readable</a>.
1221
+ */
1222
+ aborted: boolean;
1223
+ /**
1224
+ * In case of server request, the HTTP version sent by the client. In the case of
1225
+ * client response, the HTTP version of the connected-to server.
1226
+ * Probably either `'1.1'` or `'1.0'`.
1227
+ *
1228
+ * Also `message.httpVersionMajor` is the first integer and `message.httpVersionMinor` is the second.
1229
+ * @since v0.1.1
1230
+ */
1231
+ httpVersion: string;
1232
+ httpVersionMajor: number;
1233
+ httpVersionMinor: number;
1234
+ /**
1235
+ * The `message.complete` property will be `true` if a complete HTTP message has
1236
+ * been received and successfully parsed.
1237
+ *
1238
+ * This property is particularly useful as a means of determining if a client or
1239
+ * server fully transmitted a message before a connection was terminated:
1240
+ *
1241
+ * ```js
1242
+ * const req = http.request({
1243
+ * host: '127.0.0.1',
1244
+ * port: 8080,
1245
+ * method: 'POST',
1246
+ * }, (res) => {
1247
+ * res.resume();
1248
+ * res.on('end', () => {
1249
+ * if (!res.complete)
1250
+ * console.error(
1251
+ * 'The connection was terminated while the message was still being sent');
1252
+ * });
1253
+ * });
1254
+ * ```
1255
+ * @since v0.3.0
1256
+ */
1257
+ complete: boolean;
1258
+ /**
1259
+ * Alias for `message.socket`.
1260
+ * @since v0.1.90
1261
+ * @deprecated Since v16.0.0 - Use `socket`.
1262
+ */
1263
+ connection: Socket;
1264
+ /**
1265
+ * The `net.Socket` object associated with the connection.
1266
+ *
1267
+ * With HTTPS support, use `request.socket.getPeerCertificate()` to obtain the
1268
+ * client's authentication details.
1269
+ *
1270
+ * This property is guaranteed to be an instance of the `net.Socket` class,
1271
+ * a subclass of `stream.Duplex`, unless the user specified a socket
1272
+ * type other than `net.Socket` or internally nulled.
1273
+ * @since v0.3.0
1274
+ */
1275
+ socket: Socket;
1276
+ /**
1277
+ * The request/response headers object.
1278
+ *
1279
+ * Key-value pairs of header names and values. Header names are lower-cased.
1280
+ *
1281
+ * ```js
1282
+ * // Prints something like:
1283
+ * //
1284
+ * // { 'user-agent': 'curl/7.22.0',
1285
+ * // host: '127.0.0.1:8000',
1286
+ * // accept: '*' }
1287
+ * console.log(request.headers);
1288
+ * ```
1289
+ *
1290
+ * Duplicates in raw headers are handled in the following ways, depending on the
1291
+ * header name:
1292
+ *
1293
+ * * Duplicates of `age`, `authorization`, `content-length`, `content-type`, `etag`, `expires`, `from`, `host`, `if-modified-since`, `if-unmodified-since`, `last-modified`, `location`,
1294
+ * `max-forwards`, `proxy-authorization`, `referer`, `retry-after`, `server`, or `user-agent` are discarded.
1295
+ * To allow duplicate values of the headers listed above to be joined,
1296
+ * use the option `joinDuplicateHeaders` in {@link request} and {@link createServer}. See RFC 9110 Section 5.3 for more
1297
+ * information.
1298
+ * * `set-cookie` is always an array. Duplicates are added to the array.
1299
+ * * For duplicate `cookie` headers, the values are joined together with `; `.
1300
+ * * For all other headers, the values are joined together with `, `.
1301
+ * @since v0.1.5
1302
+ */
1303
+ headers: IncomingHttpHeaders;
1304
+ /**
1305
+ * Similar to `message.headers`, but there is no join logic and the values are
1306
+ * always arrays of strings, even for headers received just once.
1307
+ *
1308
+ * ```js
1309
+ * // Prints something like:
1310
+ * //
1311
+ * // { 'user-agent': ['curl/7.22.0'],
1312
+ * // host: ['127.0.0.1:8000'],
1313
+ * // accept: ['*'] }
1314
+ * console.log(request.headersDistinct);
1315
+ * ```
1316
+ * @since v18.3.0, v16.17.0
1317
+ */
1318
+ headersDistinct: NodeJS.Dict<string[]>;
1319
+ /**
1320
+ * The raw request/response headers list exactly as they were received.
1321
+ *
1322
+ * The keys and values are in the same list. It is _not_ a
1323
+ * list of tuples. So, the even-numbered offsets are key values, and the
1324
+ * odd-numbered offsets are the associated values.
1325
+ *
1326
+ * Header names are not lowercased, and duplicates are not merged.
1327
+ *
1328
+ * ```js
1329
+ * // Prints something like:
1330
+ * //
1331
+ * // [ 'user-agent',
1332
+ * // 'this is invalid because there can be only one',
1333
+ * // 'User-Agent',
1334
+ * // 'curl/7.22.0',
1335
+ * // 'Host',
1336
+ * // '127.0.0.1:8000',
1337
+ * // 'ACCEPT',
1338
+ * // '*' ]
1339
+ * console.log(request.rawHeaders);
1340
+ * ```
1341
+ * @since v0.11.6
1342
+ */
1343
+ rawHeaders: string[];
1344
+ /**
1345
+ * The request/response trailers object. Only populated at the `'end'` event.
1346
+ * @since v0.3.0
1347
+ */
1348
+ trailers: NodeJS.Dict<string>;
1349
+ /**
1350
+ * Similar to `message.trailers`, but there is no join logic and the values are
1351
+ * always arrays of strings, even for headers received just once.
1352
+ * Only populated at the `'end'` event.
1353
+ * @since v18.3.0, v16.17.0
1354
+ */
1355
+ trailersDistinct: NodeJS.Dict<string[]>;
1356
+ /**
1357
+ * The raw request/response trailer keys and values exactly as they were
1358
+ * received. Only populated at the `'end'` event.
1359
+ * @since v0.11.6
1360
+ */
1361
+ rawTrailers: string[];
1362
+ /**
1363
+ * Calls `message.socket.setTimeout(msecs, callback)`.
1364
+ * @since v0.5.9
1365
+ */
1366
+ setTimeout(msecs: number, callback?: () => void): this;
1367
+ /**
1368
+ * **Only valid for request obtained from {@link Server}.**
1369
+ *
1370
+ * The request method as a string. Read only. Examples: `'GET'`, `'DELETE'`.
1371
+ * @since v0.1.1
1372
+ */
1373
+ method?: string | undefined;
1374
+ /**
1375
+ * **Only valid for request obtained from {@link Server}.**
1376
+ *
1377
+ * Request URL string. This contains only the URL that is present in the actual
1378
+ * HTTP request. Take the following request:
1379
+ *
1380
+ * ```http
1381
+ * GET /status?name=ryan HTTP/1.1
1382
+ * Accept: text/plain
1383
+ * ```
1384
+ *
1385
+ * To parse the URL into its parts:
1386
+ *
1387
+ * ```js
1388
+ * new URL(`http://${process.env.HOST ?? 'localhost'}${request.url}`);
1389
+ * ```
1390
+ *
1391
+ * When `request.url` is `'/status?name=ryan'` and `process.env.HOST` is undefined:
1392
+ *
1393
+ * ```console
1394
+ * $ node
1395
+ * > new URL(`http://${process.env.HOST ?? 'localhost'}${request.url}`);
1396
+ * URL {
1397
+ * href: 'http://localhost/status?name=ryan',
1398
+ * origin: 'http://localhost',
1399
+ * protocol: 'http:',
1400
+ * username: '',
1401
+ * password: '',
1402
+ * host: 'localhost',
1403
+ * hostname: 'localhost',
1404
+ * port: '',
1405
+ * pathname: '/status',
1406
+ * search: '?name=ryan',
1407
+ * searchParams: URLSearchParams { 'name' => 'ryan' },
1408
+ * hash: ''
1409
+ * }
1410
+ * ```
1411
+ *
1412
+ * Ensure that you set `process.env.HOST` to the server's host name, or consider replacing this part entirely. If using `req.headers.host`, ensure proper
1413
+ * validation is used, as clients may specify a custom `Host` header.
1414
+ * @since v0.1.90
1415
+ */
1416
+ url?: string | undefined;
1417
+ /**
1418
+ * **Only valid for response obtained from {@link ClientRequest}.**
1419
+ *
1420
+ * The 3-digit HTTP response status code. E.G. `404`.
1421
+ * @since v0.1.1
1422
+ */
1423
+ statusCode?: number | undefined;
1424
+ /**
1425
+ * **Only valid for response obtained from {@link ClientRequest}.**
1426
+ *
1427
+ * The HTTP response status message (reason phrase). E.G. `OK` or `Internal Server Error`.
1428
+ * @since v0.11.10
1429
+ */
1430
+ statusMessage?: string | undefined;
1431
+ /**
1432
+ * 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
1433
+ * as an argument to any listeners on the event.
1434
+ * @since v0.3.0
1435
+ */
1436
+ destroy(error?: Error): this;
1437
+ }
1438
+ interface AgentOptions extends NodeJS.PartialOptions<TcpSocketConnectOpts> {
1439
+ /**
1440
+ * Keep sockets around in a pool to be used by other requests in the future. Default = false
1441
+ */
1442
+ keepAlive?: boolean | undefined;
1443
+ /**
1444
+ * When using HTTP KeepAlive, how often to send TCP KeepAlive packets over sockets being kept alive. Default = 1000.
1445
+ * Only relevant if keepAlive is set to true.
1446
+ */
1447
+ keepAliveMsecs?: number | undefined;
1448
+ /**
1449
+ * Maximum number of sockets to allow per host. Default for Node 0.10 is 5, default for Node 0.12 is Infinity
1450
+ */
1451
+ maxSockets?: number | undefined;
1452
+ /**
1453
+ * Maximum number of sockets allowed for all hosts in total. Each request will use a new socket until the maximum is reached. Default: Infinity.
1454
+ */
1455
+ maxTotalSockets?: number | undefined;
1456
+ /**
1457
+ * Maximum number of sockets to leave open in a free state. Only relevant if keepAlive is set to true. Default = 256.
1458
+ */
1459
+ maxFreeSockets?: number | undefined;
1460
+ /**
1461
+ * Socket timeout in milliseconds. This will set the timeout after the socket is connected.
1462
+ */
1463
+ timeout?: number | undefined;
1464
+ /**
1465
+ * Scheduling strategy to apply when picking the next free socket to use.
1466
+ * @default `lifo`
1467
+ */
1468
+ scheduling?: "fifo" | "lifo" | undefined;
1469
+ }
1470
+ /**
1471
+ * An `Agent` is responsible for managing connection persistence
1472
+ * and reuse for HTTP clients. It maintains a queue of pending requests
1473
+ * for a given host and port, reusing a single socket connection for each
1474
+ * until the queue is empty, at which time the socket is either destroyed
1475
+ * or put into a pool where it is kept to be used again for requests to the
1476
+ * same host and port. Whether it is destroyed or pooled depends on the `keepAlive` `option`.
1477
+ *
1478
+ * Pooled connections have TCP Keep-Alive enabled for them, but servers may
1479
+ * still close idle connections, in which case they will be removed from the
1480
+ * pool and a new connection will be made when a new HTTP request is made for
1481
+ * that host and port. Servers may also refuse to allow multiple requests
1482
+ * over the same connection, in which case the connection will have to be
1483
+ * remade for every request and cannot be pooled. The `Agent` will still make
1484
+ * the requests to that server, but each one will occur over a new connection.
1485
+ *
1486
+ * When a connection is closed by the client or the server, it is removed
1487
+ * from the pool. Any unused sockets in the pool will be unrefed so as not
1488
+ * to keep the Node.js process running when there are no outstanding requests.
1489
+ * (see `socket.unref()`).
1490
+ *
1491
+ * It is good practice, to `destroy()` an `Agent` instance when it is no
1492
+ * longer in use, because unused sockets consume OS resources.
1493
+ *
1494
+ * Sockets are removed from an agent when the socket emits either
1495
+ * a `'close'` event or an `'agentRemove'` event. When intending to keep one
1496
+ * HTTP request open for a long time without keeping it in the agent, something
1497
+ * like the following may be done:
1498
+ *
1499
+ * ```js
1500
+ * http.get(options, (res) => {
1501
+ * // Do stuff
1502
+ * }).on('socket', (socket) => {
1503
+ * socket.emit('agentRemove');
1504
+ * });
1505
+ * ```
1506
+ *
1507
+ * 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
1508
+ * will be used
1509
+ * for the client connection.
1510
+ *
1511
+ * `agent:false`:
1512
+ *
1513
+ * ```js
1514
+ * http.get({
1515
+ * hostname: 'localhost',
1516
+ * port: 80,
1517
+ * path: '/',
1518
+ * agent: false, // Create a new agent just for this one request
1519
+ * }, (res) => {
1520
+ * // Do stuff with response
1521
+ * });
1522
+ * ```
1523
+ *
1524
+ * `options` in [`socket.connect()`](https://nodejs.org/docs/latest-v20.x/api/net.html#socketconnectoptions-connectlistener) are also supported.
1525
+ *
1526
+ * To configure any of them, a custom {@link Agent} instance must be created.
1527
+ *
1528
+ * ```js
1529
+ * import http from 'node:http';
1530
+ * const keepAliveAgent = new http.Agent({ keepAlive: true });
1531
+ * options.agent = keepAliveAgent;
1532
+ * http.request(options, onResponseCallback)
1533
+ * ```
1534
+ * @since v0.3.4
1535
+ */
1536
+ class Agent extends EventEmitter {
1537
+ /**
1538
+ * By default set to 256. For agents with `keepAlive` enabled, this
1539
+ * sets the maximum number of sockets that will be left open in the free
1540
+ * state.
1541
+ * @since v0.11.7
1542
+ */
1543
+ maxFreeSockets: number;
1544
+ /**
1545
+ * By default set to `Infinity`. Determines how many concurrent sockets the agent
1546
+ * can have open per origin. Origin is the returned value of `agent.getName()`.
1547
+ * @since v0.3.6
1548
+ */
1549
+ maxSockets: number;
1550
+ /**
1551
+ * By default set to `Infinity`. Determines how many concurrent sockets the agent
1552
+ * can have open. Unlike `maxSockets`, this parameter applies across all origins.
1553
+ * @since v14.5.0, v12.19.0
1554
+ */
1555
+ maxTotalSockets: number;
1556
+ /**
1557
+ * An object which contains arrays of sockets currently awaiting use by
1558
+ * the agent when `keepAlive` is enabled. Do not modify.
1559
+ *
1560
+ * Sockets in the `freeSockets` list will be automatically destroyed and
1561
+ * removed from the array on `'timeout'`.
1562
+ * @since v0.11.4
1563
+ */
1564
+ readonly freeSockets: NodeJS.ReadOnlyDict<Socket[]>;
1565
+ /**
1566
+ * An object which contains arrays of sockets currently in use by the
1567
+ * agent. Do not modify.
1568
+ * @since v0.3.6
1569
+ */
1570
+ readonly sockets: NodeJS.ReadOnlyDict<Socket[]>;
1571
+ /**
1572
+ * An object which contains queues of requests that have not yet been assigned to
1573
+ * sockets. Do not modify.
1574
+ * @since v0.5.9
1575
+ */
1576
+ readonly requests: NodeJS.ReadOnlyDict<IncomingMessage[]>;
1577
+ constructor(opts?: AgentOptions);
1578
+ /**
1579
+ * Destroy any sockets that are currently in use by the agent.
1580
+ *
1581
+ * It is usually not necessary to do this. However, if using an
1582
+ * agent with `keepAlive` enabled, then it is best to explicitly shut down
1583
+ * the agent when it is no longer needed. Otherwise,
1584
+ * sockets might stay open for quite a long time before the server
1585
+ * terminates them.
1586
+ * @since v0.11.4
1587
+ */
1588
+ destroy(): void;
1589
+ /**
1590
+ * Produces a socket/stream to be used for HTTP requests.
1591
+ *
1592
+ * By default, this function is the same as `net.createConnection()`. However,
1593
+ * custom agents may override this method in case greater flexibility is desired.
1594
+ *
1595
+ * A socket/stream can be supplied in one of two ways: by returning the
1596
+ * socket/stream from this function, or by passing the socket/stream to `callback`.
1597
+ *
1598
+ * This method is guaranteed to return an instance of the `net.Socket` class,
1599
+ * a subclass of `stream.Duplex`, unless the user specifies a socket
1600
+ * type other than `net.Socket`.
1601
+ *
1602
+ * `callback` has a signature of `(err, stream)`.
1603
+ * @since v0.11.4
1604
+ * @param options Options containing connection details. Check `createConnection` for the format of the options
1605
+ * @param callback Callback function that receives the created socket
1606
+ */
1607
+ createConnection(
1608
+ options: ClientRequestArgs,
1609
+ callback?: (err: Error | null, stream: stream.Duplex) => void,
1610
+ ): stream.Duplex | null | undefined;
1611
+ /**
1612
+ * Called when `socket` is detached from a request and could be persisted by the`Agent`. Default behavior is to:
1613
+ *
1614
+ * ```js
1615
+ * socket.setKeepAlive(true, this.keepAliveMsecs);
1616
+ * socket.unref();
1617
+ * return true;
1618
+ * ```
1619
+ *
1620
+ * This method can be overridden by a particular `Agent` subclass. If this
1621
+ * method returns a falsy value, the socket will be destroyed instead of persisting
1622
+ * it for use with the next request.
1623
+ *
1624
+ * The `socket` argument can be an instance of `net.Socket`, a subclass of `stream.Duplex`.
1625
+ * @since v8.1.0
1626
+ */
1627
+ keepSocketAlive(socket: stream.Duplex): void;
1628
+ /**
1629
+ * Called when `socket` is attached to `request` after being persisted because of
1630
+ * the keep-alive options. Default behavior is to:
1631
+ *
1632
+ * ```js
1633
+ * socket.ref();
1634
+ * ```
1635
+ *
1636
+ * This method can be overridden by a particular `Agent` subclass.
1637
+ *
1638
+ * The `socket` argument can be an instance of `net.Socket`, a subclass of `stream.Duplex`.
1639
+ * @since v8.1.0
1640
+ */
1641
+ reuseSocket(socket: stream.Duplex, request: ClientRequest): void;
1642
+ /**
1643
+ * Get a unique name for a set of request options, to determine whether a
1644
+ * connection can be reused. For an HTTP agent, this returns`host:port:localAddress` or `host:port:localAddress:family`. For an HTTPS agent,
1645
+ * the name includes the CA, cert, ciphers, and other HTTPS/TLS-specific options
1646
+ * that determine socket reusability.
1647
+ * @since v0.11.4
1648
+ * @param options A set of options providing information for name generation
1649
+ */
1650
+ getName(options?: ClientRequestArgs): string;
1651
+ }
1652
+ const METHODS: string[];
1653
+ const STATUS_CODES: {
1654
+ [errorCode: number]: string | undefined;
1655
+ [errorCode: string]: string | undefined;
1656
+ };
1657
+ /**
1658
+ * Returns a new instance of {@link Server}.
1659
+ *
1660
+ * The `requestListener` is a function which is automatically
1661
+ * added to the `'request'` event.
1662
+ *
1663
+ * ```js
1664
+ * import http from 'node:http';
1665
+ *
1666
+ * // Create a local server to receive data from
1667
+ * const server = http.createServer((req, res) => {
1668
+ * res.writeHead(200, { 'Content-Type': 'application/json' });
1669
+ * res.end(JSON.stringify({
1670
+ * data: 'Hello World!',
1671
+ * }));
1672
+ * });
1673
+ *
1674
+ * server.listen(8000);
1675
+ * ```
1676
+ *
1677
+ * ```js
1678
+ * import http from 'node:http';
1679
+ *
1680
+ * // Create a local server to receive data from
1681
+ * const server = http.createServer();
1682
+ *
1683
+ * // Listen to the request event
1684
+ * server.on('request', (request, res) => {
1685
+ * res.writeHead(200, { 'Content-Type': 'application/json' });
1686
+ * res.end(JSON.stringify({
1687
+ * data: 'Hello World!',
1688
+ * }));
1689
+ * });
1690
+ *
1691
+ * server.listen(8000);
1692
+ * ```
1693
+ * @since v0.1.13
1694
+ */
1695
+ function createServer<
1696
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
1697
+ Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
1698
+ >(requestListener?: RequestListener<Request, Response>): Server<Request, Response>;
1699
+ function createServer<
1700
+ Request extends typeof IncomingMessage = typeof IncomingMessage,
1701
+ Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,
1702
+ >(
1703
+ options: ServerOptions<Request, Response>,
1704
+ requestListener?: RequestListener<Request, Response>,
1705
+ ): Server<Request, Response>;
1706
+ // although RequestOptions are passed as ClientRequestArgs to ClientRequest directly,
1707
+ // create interface RequestOptions would make the naming more clear to developers
1708
+ interface RequestOptions extends ClientRequestArgs {}
1709
+ /**
1710
+ * `options` in `socket.connect()` are also supported.
1711
+ *
1712
+ * Node.js maintains several connections per server to make HTTP requests.
1713
+ * This function allows one to transparently issue requests.
1714
+ *
1715
+ * `url` can be a string or a `URL` object. If `url` is a
1716
+ * string, it is automatically parsed with `new URL()`. If it is a `URL` object, it will be automatically converted to an ordinary `options` object.
1717
+ *
1718
+ * If both `url` and `options` are specified, the objects are merged, with the `options` properties taking precedence.
1719
+ *
1720
+ * The optional `callback` parameter will be added as a one-time listener for
1721
+ * the `'response'` event.
1722
+ *
1723
+ * `http.request()` returns an instance of the {@link ClientRequest} class. The `ClientRequest` instance is a writable stream. If one needs to
1724
+ * upload a file with a POST request, then write to the `ClientRequest` object.
1725
+ *
1726
+ * ```js
1727
+ * import http from 'node:http';
1728
+ * import { Buffer } from 'node:buffer';
1729
+ *
1730
+ * const postData = JSON.stringify({
1731
+ * 'msg': 'Hello World!',
1732
+ * });
1733
+ *
1734
+ * const options = {
1735
+ * hostname: 'www.google.com',
1736
+ * port: 80,
1737
+ * path: '/upload',
1738
+ * method: 'POST',
1739
+ * headers: {
1740
+ * 'Content-Type': 'application/json',
1741
+ * 'Content-Length': Buffer.byteLength(postData),
1742
+ * },
1743
+ * };
1744
+ *
1745
+ * const req = http.request(options, (res) => {
1746
+ * console.log(`STATUS: ${res.statusCode}`);
1747
+ * console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
1748
+ * res.setEncoding('utf8');
1749
+ * res.on('data', (chunk) => {
1750
+ * console.log(`BODY: ${chunk}`);
1751
+ * });
1752
+ * res.on('end', () => {
1753
+ * console.log('No more data in response.');
1754
+ * });
1755
+ * });
1756
+ *
1757
+ * req.on('error', (e) => {
1758
+ * console.error(`problem with request: ${e.message}`);
1759
+ * });
1760
+ *
1761
+ * // Write data to request body
1762
+ * req.write(postData);
1763
+ * req.end();
1764
+ * ```
1765
+ *
1766
+ * In the example `req.end()` was called. With `http.request()` one
1767
+ * must always call `req.end()` to signify the end of the request -
1768
+ * even if there is no data being written to the request body.
1769
+ *
1770
+ * If any error is encountered during the request (be that with DNS resolution,
1771
+ * TCP level errors, or actual HTTP parse errors) an `'error'` event is emitted
1772
+ * on the returned request object. As with all `'error'` events, if no listeners
1773
+ * are registered the error will be thrown.
1774
+ *
1775
+ * There are a few special headers that should be noted.
1776
+ *
1777
+ * * Sending a 'Connection: keep-alive' will notify Node.js that the connection to
1778
+ * the server should be persisted until the next request.
1779
+ * * Sending a 'Content-Length' header will disable the default chunked encoding.
1780
+ * * Sending an 'Expect' header will immediately send the request headers.
1781
+ * Usually, when sending 'Expect: 100-continue', both a timeout and a listener
1782
+ * for the `'continue'` event should be set. See RFC 2616 Section 8.2.3 for more
1783
+ * information.
1784
+ * * Sending an Authorization header will override using the `auth` option
1785
+ * to compute basic authentication.
1786
+ *
1787
+ * Example using a `URL` as `options`:
1788
+ *
1789
+ * ```js
1790
+ * const options = new URL('http://abc:xyz@example.com');
1791
+ *
1792
+ * const req = http.request(options, (res) => {
1793
+ * // ...
1794
+ * });
1795
+ * ```
1796
+ *
1797
+ * In a successful request, the following events will be emitted in the following
1798
+ * order:
1799
+ *
1800
+ * * `'socket'`
1801
+ * * `'response'`
1802
+ * * `'data'` any number of times, on the `res` object
1803
+ * (`'data'` will not be emitted at all if the response body is empty, for
1804
+ * instance, in most redirects)
1805
+ * * `'end'` on the `res` object
1806
+ * * `'close'`
1807
+ *
1808
+ * In the case of a connection error, the following events will be emitted:
1809
+ *
1810
+ * * `'socket'`
1811
+ * * `'error'`
1812
+ * * `'close'`
1813
+ *
1814
+ * In the case of a premature connection close before the response is received,
1815
+ * the following events will be emitted in the following order:
1816
+ *
1817
+ * * `'socket'`
1818
+ * * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`
1819
+ * * `'close'`
1820
+ *
1821
+ * In the case of a premature connection close after the response is received,
1822
+ * the following events will be emitted in the following order:
1823
+ *
1824
+ * * `'socket'`
1825
+ * * `'response'`
1826
+ * * `'data'` any number of times, on the `res` object
1827
+ * * (connection closed here)
1828
+ * * `'aborted'` on the `res` object
1829
+ * * `'close'`
1830
+ * * `'error'` on the `res` object with an error with message `'Error: aborted'` and code `'ECONNRESET'`
1831
+ * * `'close'` on the `res` object
1832
+ *
1833
+ * If `req.destroy()` is called before a socket is assigned, the following
1834
+ * events will be emitted in the following order:
1835
+ *
1836
+ * * (`req.destroy()` called here)
1837
+ * * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`, or the error with which `req.destroy()` was called
1838
+ * * `'close'`
1839
+ *
1840
+ * If `req.destroy()` is called before the connection succeeds, the following
1841
+ * events will be emitted in the following order:
1842
+ *
1843
+ * * `'socket'`
1844
+ * * (`req.destroy()` called here)
1845
+ * * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`, or the error with which `req.destroy()` was called
1846
+ * * `'close'`
1847
+ *
1848
+ * If `req.destroy()` is called after the response is received, the following
1849
+ * events will be emitted in the following order:
1850
+ *
1851
+ * * `'socket'`
1852
+ * * `'response'`
1853
+ * * `'data'` any number of times, on the `res` object
1854
+ * * (`req.destroy()` called here)
1855
+ * * `'aborted'` on the `res` object
1856
+ * * `'close'`
1857
+ * * `'error'` on the `res` object with an error with message `'Error: aborted'` and code `'ECONNRESET'`, or the error with which `req.destroy()` was called
1858
+ * * `'close'` on the `res` object
1859
+ *
1860
+ * If `req.abort()` is called before a socket is assigned, the following
1861
+ * events will be emitted in the following order:
1862
+ *
1863
+ * * (`req.abort()` called here)
1864
+ * * `'abort'`
1865
+ * * `'close'`
1866
+ *
1867
+ * If `req.abort()` is called before the connection succeeds, the following
1868
+ * events will be emitted in the following order:
1869
+ *
1870
+ * * `'socket'`
1871
+ * * (`req.abort()` called here)
1872
+ * * `'abort'`
1873
+ * * `'error'` with an error with message `'Error: socket hang up'` and code `'ECONNRESET'`
1874
+ * * `'close'`
1875
+ *
1876
+ * If `req.abort()` is called after the response is received, the following
1877
+ * events will be emitted in the following order:
1878
+ *
1879
+ * * `'socket'`
1880
+ * * `'response'`
1881
+ * * `'data'` any number of times, on the `res` object
1882
+ * * (`req.abort()` called here)
1883
+ * * `'abort'`
1884
+ * * `'aborted'` on the `res` object
1885
+ * * `'error'` on the `res` object with an error with message `'Error: aborted'` and code `'ECONNRESET'`.
1886
+ * * `'close'`
1887
+ * * `'close'` on the `res` object
1888
+ *
1889
+ * Setting the `timeout` option or using the `setTimeout()` function will
1890
+ * not abort the request or do anything besides add a `'timeout'` event.
1891
+ *
1892
+ * Passing an `AbortSignal` and then calling `abort()` on the corresponding `AbortController` will behave the same way as calling `.destroy()` on the
1893
+ * request. Specifically, the `'error'` event will be emitted with an error with
1894
+ * the message `'AbortError: The operation was aborted'`, the code `'ABORT_ERR'` and the `cause`, if one was provided.
1895
+ * @since v0.3.6
1896
+ */
1897
+ function request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
1898
+ function request(
1899
+ url: string | URL,
1900
+ options: RequestOptions,
1901
+ callback?: (res: IncomingMessage) => void,
1902
+ ): ClientRequest;
1903
+ /**
1904
+ * Since most requests are GET requests without bodies, Node.js provides this
1905
+ * convenience method. The only difference between this method and {@link request} is that it sets the method to GET by default and calls `req.end()` automatically. The callback must take care to
1906
+ * consume the response
1907
+ * data for reasons stated in {@link ClientRequest} section.
1908
+ *
1909
+ * The `callback` is invoked with a single argument that is an instance of {@link IncomingMessage}.
1910
+ *
1911
+ * JSON fetching example:
1912
+ *
1913
+ * ```js
1914
+ * http.get('http://localhost:8000/', (res) => {
1915
+ * const { statusCode } = res;
1916
+ * const contentType = res.headers['content-type'];
1917
+ *
1918
+ * let error;
1919
+ * // Any 2xx status code signals a successful response but
1920
+ * // here we're only checking for 200.
1921
+ * if (statusCode !== 200) {
1922
+ * error = new Error('Request Failed.\n' +
1923
+ * `Status Code: ${statusCode}`);
1924
+ * } else if (!/^application\/json/.test(contentType)) {
1925
+ * error = new Error('Invalid content-type.\n' +
1926
+ * `Expected application/json but received ${contentType}`);
1927
+ * }
1928
+ * if (error) {
1929
+ * console.error(error.message);
1930
+ * // Consume response data to free up memory
1931
+ * res.resume();
1932
+ * return;
1933
+ * }
1934
+ *
1935
+ * res.setEncoding('utf8');
1936
+ * let rawData = '';
1937
+ * res.on('data', (chunk) => { rawData += chunk; });
1938
+ * res.on('end', () => {
1939
+ * try {
1940
+ * const parsedData = JSON.parse(rawData);
1941
+ * console.log(parsedData);
1942
+ * } catch (e) {
1943
+ * console.error(e.message);
1944
+ * }
1945
+ * });
1946
+ * }).on('error', (e) => {
1947
+ * console.error(`Got error: ${e.message}`);
1948
+ * });
1949
+ *
1950
+ * // Create a local server to receive data from
1951
+ * const server = http.createServer((req, res) => {
1952
+ * res.writeHead(200, { 'Content-Type': 'application/json' });
1953
+ * res.end(JSON.stringify({
1954
+ * data: 'Hello World!',
1955
+ * }));
1956
+ * });
1957
+ *
1958
+ * server.listen(8000);
1959
+ * ```
1960
+ * @since v0.3.6
1961
+ * @param options Accepts the same `options` as {@link request}, with the method set to GET by default.
1962
+ */
1963
+ function get(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest;
1964
+ function get(url: string | URL, options: RequestOptions, callback?: (res: IncomingMessage) => void): ClientRequest;
1965
+ /**
1966
+ * Performs the low-level validations on the provided `name` that are done when `res.setHeader(name, value)` is called.
1967
+ *
1968
+ * Passing illegal value as `name` will result in a `TypeError` being thrown,
1969
+ * identified by `code: 'ERR_INVALID_HTTP_TOKEN'`.
1970
+ *
1971
+ * It is not necessary to use this method before passing headers to an HTTP request
1972
+ * or response. The HTTP module will automatically validate such headers.
1973
+ *
1974
+ * Example:
1975
+ *
1976
+ * ```js
1977
+ * import { validateHeaderName } from 'node:http';
1978
+ *
1979
+ * try {
1980
+ * validateHeaderName('');
1981
+ * } catch (err) {
1982
+ * console.error(err instanceof TypeError); // --> true
1983
+ * console.error(err.code); // --> 'ERR_INVALID_HTTP_TOKEN'
1984
+ * console.error(err.message); // --> 'Header name must be a valid HTTP token [""]'
1985
+ * }
1986
+ * ```
1987
+ * @since v14.3.0
1988
+ * @param [label='Header name'] Label for error message.
1989
+ */
1990
+ function validateHeaderName(name: string): void;
1991
+ /**
1992
+ * Performs the low-level validations on the provided `value` that are done when `res.setHeader(name, value)` is called.
1993
+ *
1994
+ * Passing illegal value as `value` will result in a `TypeError` being thrown.
1995
+ *
1996
+ * * Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.
1997
+ * * Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.
1998
+ *
1999
+ * It is not necessary to use this method before passing headers to an HTTP request
2000
+ * or response. The HTTP module will automatically validate such headers.
2001
+ *
2002
+ * Examples:
2003
+ *
2004
+ * ```js
2005
+ * import { validateHeaderValue } from 'node:http';
2006
+ *
2007
+ * try {
2008
+ * validateHeaderValue('x-my-header', undefined);
2009
+ * } catch (err) {
2010
+ * console.error(err instanceof TypeError); // --> true
2011
+ * console.error(err.code === 'ERR_HTTP_INVALID_HEADER_VALUE'); // --> true
2012
+ * console.error(err.message); // --> 'Invalid value "undefined" for header "x-my-header"'
2013
+ * }
2014
+ *
2015
+ * try {
2016
+ * validateHeaderValue('x-my-header', 'oʊmɪɡə');
2017
+ * } catch (err) {
2018
+ * console.error(err instanceof TypeError); // --> true
2019
+ * console.error(err.code === 'ERR_INVALID_CHAR'); // --> true
2020
+ * console.error(err.message); // --> 'Invalid character in header content ["x-my-header"]'
2021
+ * }
2022
+ * ```
2023
+ * @since v14.3.0
2024
+ * @param name Header name
2025
+ * @param value Header value
2026
+ */
2027
+ function validateHeaderValue(name: string, value: string): void;
2028
+ /**
2029
+ * Set the maximum number of idle HTTP parsers.
2030
+ * @since v18.8.0, v16.18.0
2031
+ * @param [max=1000]
2032
+ */
2033
+ function setMaxIdleHTTPParsers(max: number): void;
2034
+ /**
2035
+ * Global instance of `Agent` which is used as the default for all HTTP client
2036
+ * requests. Diverges from a default `Agent` configuration by having `keepAlive`
2037
+ * enabled and a `timeout` of 5 seconds.
2038
+ * @since v0.5.9
2039
+ */
2040
+ let globalAgent: Agent;
2041
+ /**
2042
+ * Read-only property specifying the maximum allowed size of HTTP headers in bytes.
2043
+ * Defaults to 16KB. Configurable using the `--max-http-header-size` CLI option.
2044
+ */
2045
+ const maxHeaderSize: number;
2046
+ }
2047
+ declare module "node:http" {
2048
+ export * from "http";
2049
+ }