zai-fca 1.0.7

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.

Potentially problematic release.


This version of zai-fca might be problematic. Click here for more details.

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