@ykdz/template 0.0.38 → 0.0.40

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