@openclaw/slack 2026.10.1 → 2026.10.5-beta.1

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