@anthropic-ai/claude-code 0.2.29 → 0.2.30

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