@wbce/projen-d9 0.0.28 → 0.1.0

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 (421) hide show
  1. package/.jsii +184 -45
  2. package/API.md +153 -37
  3. package/CHANGELOG.md +13 -0
  4. package/README.md +10 -3
  5. package/docs/D9-plumbing.md +189 -0
  6. package/lib/cli/atlas.d.ts +10 -0
  7. package/lib/cli/atlas.js +65 -0
  8. package/lib/cli/commands/cedar/cedar-format.d.ts +7 -0
  9. package/lib/cli/commands/cedar/cedar-format.js +75 -0
  10. package/lib/cli/commands/cedar/cedar-to-d9-translations.d.ts +12 -0
  11. package/lib/cli/commands/cedar/cedar-to-d9-translations.js +130 -0
  12. package/lib/cli/commands/cedar/cedar-to-d9.d.ts +57 -0
  13. package/lib/cli/commands/cedar/cedar-to-d9.js +221 -0
  14. package/lib/cli/commands/cedar/cedar-translations.d.ts +9 -0
  15. package/lib/cli/commands/cedar/cedar-translations.js +213 -0
  16. package/lib/cli/commands/cedar/d9-permission.d.ts +27 -0
  17. package/lib/cli/commands/cedar/d9-permission.js +45 -0
  18. package/lib/cli/commands/cedar/d9-to-cedar.d.ts +33 -0
  19. package/lib/cli/commands/cedar/d9-to-cedar.js +157 -0
  20. package/lib/cli/commands/cedar/roles-table.d.ts +14 -0
  21. package/lib/cli/commands/cedar/roles-table.js +29 -0
  22. package/lib/cli/commands/save/apply-snapshot.js +39 -30
  23. package/lib/cli/commands/save/check-unsaved.d.ts +9 -0
  24. package/lib/cli/commands/save/check-unsaved.js +81 -0
  25. package/lib/cli/commands/save/env.d.ts +33 -0
  26. package/lib/cli/commands/save/env.js +109 -0
  27. package/lib/cli/commands/save/save-snapshot.d.ts +9 -0
  28. package/lib/cli/commands/save/save-snapshot.js +232 -0
  29. package/lib/cli/commands/save/sync-files.d.ts +5 -0
  30. package/lib/cli/commands/save/sync-files.js +46 -0
  31. package/lib/cli/commands/save/transfer.d.ts +18 -0
  32. package/lib/cli/commands/save/transfer.js +96 -0
  33. package/lib/cli/commands/save/utils.d.ts +5 -0
  34. package/lib/cli/commands/save/utils.js +33 -3
  35. package/lib/cli/commands/sync.js +4 -3
  36. package/lib/cli/index.js +65 -25
  37. package/lib/cli/logger.d.ts +2 -0
  38. package/lib/cli/logger.js +10 -0
  39. package/lib/cli/plumbing-config.d.ts +11 -0
  40. package/lib/cli/plumbing-config.js +13 -0
  41. package/lib/index.d.ts +44 -5
  42. package/lib/index.js +54 -41
  43. package/node_modules/@cedar-policy/cedar-wasm/README.md +181 -0
  44. package/node_modules/@cedar-policy/cedar-wasm/esm/README.md +181 -0
  45. package/node_modules/@cedar-policy/cedar-wasm/esm/cedar_wasm.d.ts +427 -0
  46. package/node_modules/@cedar-policy/cedar-wasm/esm/cedar_wasm.js +9 -0
  47. package/node_modules/@cedar-policy/cedar-wasm/esm/cedar_wasm_bg.js +434 -0
  48. package/node_modules/@cedar-policy/cedar-wasm/esm/cedar_wasm_bg.wasm +0 -0
  49. package/node_modules/@cedar-policy/cedar-wasm/esm/cedar_wasm_bg.wasm.d.ts +34 -0
  50. package/node_modules/@cedar-policy/cedar-wasm/esm/package.json +23 -0
  51. package/node_modules/@cedar-policy/cedar-wasm/nodejs/README.md +181 -0
  52. package/node_modules/@cedar-policy/cedar-wasm/nodejs/cedar_wasm.d.ts +427 -0
  53. package/node_modules/@cedar-policy/cedar-wasm/nodejs/cedar_wasm.js +463 -0
  54. package/node_modules/@cedar-policy/cedar-wasm/nodejs/cedar_wasm_bg.wasm +0 -0
  55. package/node_modules/@cedar-policy/cedar-wasm/nodejs/cedar_wasm_bg.wasm.d.ts +34 -0
  56. package/node_modules/@cedar-policy/cedar-wasm/nodejs/package.json +18 -0
  57. package/node_modules/@cedar-policy/cedar-wasm/package.json +53 -0
  58. package/node_modules/@cedar-policy/cedar-wasm/web/README.md +181 -0
  59. package/node_modules/@cedar-policy/cedar-wasm/web/cedar_wasm.d.ts +486 -0
  60. package/node_modules/@cedar-policy/cedar-wasm/web/cedar_wasm.js +534 -0
  61. package/node_modules/@cedar-policy/cedar-wasm/web/cedar_wasm_bg.wasm +0 -0
  62. package/node_modules/@cedar-policy/cedar-wasm/web/cedar_wasm_bg.wasm.d.ts +34 -0
  63. package/node_modules/@cedar-policy/cedar-wasm/web/package.json +21 -0
  64. package/node_modules/@types/node/README.md +5 -6
  65. package/node_modules/@types/node/assert/strict.d.ts +111 -0
  66. package/node_modules/@types/node/assert.d.ts +1040 -79
  67. package/node_modules/@types/node/async_hooks.d.ts +476 -119
  68. package/node_modules/@types/node/buffer.buffer.d.ts +472 -0
  69. package/node_modules/@types/node/buffer.d.ts +1925 -13
  70. package/node_modules/@types/node/child_process.d.ts +1204 -235
  71. package/node_modules/@types/node/cluster.d.ts +455 -137
  72. package/node_modules/@types/node/compatibility/disposable.d.ts +14 -0
  73. package/node_modules/@types/node/compatibility/index.d.ts +9 -0
  74. package/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
  75. package/node_modules/@types/node/compatibility/iterators.d.ts +20 -0
  76. package/node_modules/@types/node/console.d.ts +450 -1
  77. package/node_modules/@types/node/constants.d.ts +20 -447
  78. package/node_modules/@types/node/crypto.d.ts +3962 -600
  79. package/node_modules/@types/node/dgram.d.ts +515 -33
  80. package/node_modules/@types/node/diagnostics_channel.d.ts +578 -0
  81. package/node_modules/@types/node/dns/promises.d.ts +503 -0
  82. package/node_modules/@types/node/dns.d.ts +798 -247
  83. package/node_modules/@types/node/domain.d.ts +164 -10
  84. package/node_modules/@types/node/events.d.ts +954 -25
  85. package/node_modules/@types/node/fs/promises.d.ts +1295 -0
  86. package/node_modules/@types/node/fs.d.ts +3463 -1569
  87. package/node_modules/@types/node/globals.d.ts +98 -1277
  88. package/node_modules/@types/node/globals.typedarray.d.ts +38 -0
  89. package/node_modules/@types/node/http.d.ts +1933 -300
  90. package/node_modules/@types/node/http2.d.ts +1946 -254
  91. package/node_modules/@types/node/https.d.ts +557 -134
  92. package/node_modules/@types/node/index.d.ts +54 -48
  93. package/node_modules/@types/node/inspector.d.ts +227 -3014
  94. package/node_modules/@types/node/inspector.generated.d.ts +4052 -0
  95. package/node_modules/@types/node/module.d.ts +890 -2
  96. package/node_modules/@types/node/net.d.ts +872 -105
  97. package/node_modules/@types/node/os.d.ts +452 -209
  98. package/node_modules/@types/node/package.json +78 -128
  99. package/node_modules/@types/node/path.d.ts +196 -155
  100. package/node_modules/@types/node/perf_hooks.d.ts +829 -120
  101. package/node_modules/@types/node/process.d.ts +2072 -3
  102. package/node_modules/@types/node/punycode.d.ts +69 -27
  103. package/node_modules/@types/node/querystring.d.ts +132 -9
  104. package/node_modules/@types/node/readline/promises.d.ts +161 -0
  105. package/node_modules/@types/node/readline.d.ts +485 -49
  106. package/node_modules/@types/node/repl.d.ts +121 -83
  107. package/node_modules/@types/node/sea.d.ts +153 -0
  108. package/node_modules/@types/node/sqlite.d.ts +721 -0
  109. package/node_modules/@types/node/stream/consumers.d.ts +38 -0
  110. package/node_modules/@types/node/stream/promises.d.ts +90 -0
  111. package/node_modules/@types/node/stream/web.d.ts +622 -0
  112. package/node_modules/@types/node/stream.d.ts +1470 -140
  113. package/node_modules/@types/node/string_decoder.d.ts +64 -4
  114. package/node_modules/@types/node/test.d.ts +2163 -0
  115. package/node_modules/@types/node/timers/promises.d.ts +108 -0
  116. package/node_modules/@types/node/timers.d.ts +284 -13
  117. package/node_modules/@types/node/tls.d.ts +850 -244
  118. package/node_modules/@types/node/trace_events.d.ts +147 -11
  119. package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +468 -0
  120. package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +34 -0
  121. package/node_modules/@types/node/ts5.6/index.d.ts +97 -0
  122. package/node_modules/@types/node/tty.d.ts +160 -18
  123. package/node_modules/@types/node/url.d.ts +890 -53
  124. package/node_modules/@types/node/util.d.ts +2566 -160
  125. package/node_modules/@types/node/v8.d.ts +806 -83
  126. package/node_modules/@types/node/vm.d.ts +932 -44
  127. package/node_modules/@types/node/wasi.d.ts +148 -22
  128. package/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
  129. package/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
  130. package/node_modules/@types/node/web-globals/events.d.ts +97 -0
  131. package/node_modules/@types/node/web-globals/fetch.d.ts +55 -0
  132. package/node_modules/@types/node/web-globals/navigator.d.ts +22 -0
  133. package/node_modules/@types/node/web-globals/storage.d.ts +24 -0
  134. package/node_modules/@types/node/worker_threads.d.ts +657 -80
  135. package/node_modules/@types/node/zlib.d.ts +510 -119
  136. package/node_modules/pino/.nojekyll +0 -0
  137. package/node_modules/pino/.prettierignore +1 -0
  138. package/node_modules/pino/CNAME +1 -0
  139. package/node_modules/pino/CONTRIBUTING.md +34 -0
  140. package/node_modules/pino/LICENSE +21 -0
  141. package/node_modules/pino/README.md +177 -0
  142. package/node_modules/pino/SECURITY.md +103 -0
  143. package/node_modules/pino/benchmarks/basic.bench.js +95 -0
  144. package/node_modules/pino/benchmarks/child-child.bench.js +52 -0
  145. package/node_modules/pino/benchmarks/child-creation.bench.js +73 -0
  146. package/node_modules/pino/benchmarks/child.bench.js +62 -0
  147. package/node_modules/pino/benchmarks/deep-object.bench.js +88 -0
  148. package/node_modules/pino/benchmarks/formatters.bench.js +50 -0
  149. package/node_modules/pino/benchmarks/internal/custom-levels.js +67 -0
  150. package/node_modules/pino/benchmarks/internal/just-pino-heavy.bench.js +76 -0
  151. package/node_modules/pino/benchmarks/internal/just-pino.bench.js +182 -0
  152. package/node_modules/pino/benchmarks/internal/parent-vs-child.bench.js +75 -0
  153. package/node_modules/pino/benchmarks/internal/redact.bench.js +86 -0
  154. package/node_modules/pino/benchmarks/long-string.bench.js +81 -0
  155. package/node_modules/pino/benchmarks/multi-arg.bench.js +193 -0
  156. package/node_modules/pino/benchmarks/multistream.js +98 -0
  157. package/node_modules/pino/benchmarks/object.bench.js +82 -0
  158. package/node_modules/pino/benchmarks/utils/generate-benchmark-doc.js +36 -0
  159. package/node_modules/pino/benchmarks/utils/runbench.js +138 -0
  160. package/node_modules/pino/benchmarks/utils/wrap-log-level.js +55 -0
  161. package/node_modules/pino/bin.js +6 -0
  162. package/node_modules/pino/browser.js +607 -0
  163. package/node_modules/pino/build/sync-version.js +25 -0
  164. package/node_modules/pino/docs/api.md +1664 -0
  165. package/node_modules/pino/docs/asynchronous.md +55 -0
  166. package/node_modules/pino/docs/benchmarks.md +55 -0
  167. package/node_modules/pino/docs/browser.md +341 -0
  168. package/node_modules/pino/docs/bundling.md +40 -0
  169. package/node_modules/pino/docs/child-loggers.md +116 -0
  170. package/node_modules/pino/docs/diagnostics.md +16 -0
  171. package/node_modules/pino/docs/ecosystem.md +87 -0
  172. package/node_modules/pino/docs/help.md +353 -0
  173. package/node_modules/pino/docs/lts.md +93 -0
  174. package/node_modules/pino/docs/pretty.md +38 -0
  175. package/node_modules/pino/docs/redaction.md +130 -0
  176. package/node_modules/pino/docs/transports.md +1447 -0
  177. package/node_modules/pino/docs/web.md +306 -0
  178. package/node_modules/pino/eslint.config.js +36 -0
  179. package/node_modules/pino/examples/basic.js +43 -0
  180. package/node_modules/pino/examples/transport.js +68 -0
  181. package/node_modules/pino/favicon.ico +0 -0
  182. package/node_modules/pino/file.js +12 -0
  183. package/node_modules/pino/inc-version.sh +42 -0
  184. package/node_modules/pino/index.html +55 -0
  185. package/node_modules/pino/lib/caller.js +40 -0
  186. package/node_modules/pino/lib/constants.js +28 -0
  187. package/node_modules/pino/lib/deprecations.js +8 -0
  188. package/node_modules/pino/lib/levels.js +241 -0
  189. package/node_modules/pino/lib/meta.js +3 -0
  190. package/node_modules/pino/lib/multistream.js +211 -0
  191. package/node_modules/pino/lib/proto.js +256 -0
  192. package/node_modules/pino/lib/redaction.js +119 -0
  193. package/node_modules/pino/lib/symbols.js +76 -0
  194. package/node_modules/pino/lib/time.js +39 -0
  195. package/node_modules/pino/lib/tools.js +427 -0
  196. package/node_modules/pino/lib/transport-stream.js +56 -0
  197. package/node_modules/pino/lib/transport.js +302 -0
  198. package/node_modules/pino/lib/worker.js +197 -0
  199. package/node_modules/pino/package.json +112 -0
  200. package/node_modules/pino/pino.d.ts +881 -0
  201. package/node_modules/pino/pino.js +259 -0
  202. package/node_modules/pino/test/basic.test.js +952 -0
  203. package/node_modules/pino/test/broken-pipe.test.js +59 -0
  204. package/node_modules/pino/test/browser-bindings.test.js +114 -0
  205. package/node_modules/pino/test/browser-child.test.js +132 -0
  206. package/node_modules/pino/test/browser-disabled.test.js +87 -0
  207. package/node_modules/pino/test/browser-early-console-freeze.test.js +12 -0
  208. package/node_modules/pino/test/browser-is-level-enabled.test.js +101 -0
  209. package/node_modules/pino/test/browser-levels.test.js +241 -0
  210. package/node_modules/pino/test/browser-redaction.test.js +264 -0
  211. package/node_modules/pino/test/browser-serializers.test.js +352 -0
  212. package/node_modules/pino/test/browser-set-bindings.test.js +99 -0
  213. package/node_modules/pino/test/browser-timestamp.test.js +88 -0
  214. package/node_modules/pino/test/browser-transmit.test.js +417 -0
  215. package/node_modules/pino/test/browser.test.js +698 -0
  216. package/node_modules/pino/test/caller.test.js +20 -0
  217. package/node_modules/pino/test/complex-objects.test.js +36 -0
  218. package/node_modules/pino/test/crlf.test.js +34 -0
  219. package/node_modules/pino/test/custom-levels.test.js +267 -0
  220. package/node_modules/pino/test/diagnostics.test.js +107 -0
  221. package/node_modules/pino/test/error-key.test.js +37 -0
  222. package/node_modules/pino/test/error.test.js +403 -0
  223. package/node_modules/pino/test/escaping.test.js +110 -0
  224. package/node_modules/pino/test/esm/esm.mjs +14 -0
  225. package/node_modules/pino/test/esm/index.test.js +21 -0
  226. package/node_modules/pino/test/esm/named-exports.mjs +29 -0
  227. package/node_modules/pino/test/exit.test.js +79 -0
  228. package/node_modules/pino/test/fixtures/broken-pipe/basic.js +9 -0
  229. package/node_modules/pino/test/fixtures/broken-pipe/destination.js +10 -0
  230. package/node_modules/pino/test/fixtures/broken-pipe/syncfalse.js +12 -0
  231. package/node_modules/pino/test/fixtures/caller-loop.js +6 -0
  232. package/node_modules/pino/test/fixtures/console-transport.js +13 -0
  233. package/node_modules/pino/test/fixtures/crashing-transport.js +13 -0
  234. package/node_modules/pino/test/fixtures/default-exit.js +8 -0
  235. package/node_modules/pino/test/fixtures/destination-exit.js +8 -0
  236. package/node_modules/pino/test/fixtures/eval/index.js +13 -0
  237. package/node_modules/pino/test/fixtures/eval/node_modules/14-files.js +3 -0
  238. package/node_modules/pino/test/fixtures/eval/node_modules/2-files.js +3 -0
  239. package/node_modules/pino/test/fixtures/eval/node_modules/file1.js +5 -0
  240. package/node_modules/pino/test/fixtures/eval/node_modules/file10.js +5 -0
  241. package/node_modules/pino/test/fixtures/eval/node_modules/file11.js +5 -0
  242. package/node_modules/pino/test/fixtures/eval/node_modules/file12.js +5 -0
  243. package/node_modules/pino/test/fixtures/eval/node_modules/file13.js +5 -0
  244. package/node_modules/pino/test/fixtures/eval/node_modules/file14.js +11 -0
  245. package/node_modules/pino/test/fixtures/eval/node_modules/file2.js +5 -0
  246. package/node_modules/pino/test/fixtures/eval/node_modules/file3.js +5 -0
  247. package/node_modules/pino/test/fixtures/eval/node_modules/file4.js +5 -0
  248. package/node_modules/pino/test/fixtures/eval/node_modules/file5.js +5 -0
  249. package/node_modules/pino/test/fixtures/eval/node_modules/file6.js +5 -0
  250. package/node_modules/pino/test/fixtures/eval/node_modules/file7.js +5 -0
  251. package/node_modules/pino/test/fixtures/eval/node_modules/file8.js +5 -0
  252. package/node_modules/pino/test/fixtures/eval/node_modules/file9.js +5 -0
  253. package/node_modules/pino/test/fixtures/noop-transport.js +10 -0
  254. package/node_modules/pino/test/fixtures/pretty/null-prototype.js +8 -0
  255. package/node_modules/pino/test/fixtures/stdout-hack-protection.js +11 -0
  256. package/node_modules/pino/test/fixtures/syncfalse-child.js +6 -0
  257. package/node_modules/pino/test/fixtures/syncfalse-exit.js +9 -0
  258. package/node_modules/pino/test/fixtures/syncfalse-flush-exit.js +10 -0
  259. package/node_modules/pino/test/fixtures/syncfalse.js +6 -0
  260. package/node_modules/pino/test/fixtures/syntax-error-esm.mjs +2 -0
  261. package/node_modules/pino/test/fixtures/to-file-transport-with-transform.js +20 -0
  262. package/node_modules/pino/test/fixtures/to-file-transport.js +13 -0
  263. package/node_modules/pino/test/fixtures/to-file-transport.mjs +8 -0
  264. package/node_modules/pino/test/fixtures/transport/index.js +12 -0
  265. package/node_modules/pino/test/fixtures/transport/package.json +5 -0
  266. package/node_modules/pino/test/fixtures/transport-exit-immediately-with-async-dest.js +16 -0
  267. package/node_modules/pino/test/fixtures/transport-exit-immediately.js +11 -0
  268. package/node_modules/pino/test/fixtures/transport-exit-on-ready.js +12 -0
  269. package/node_modules/pino/test/fixtures/transport-invalid-node-options.js +26 -0
  270. package/node_modules/pino/test/fixtures/transport-main.js +9 -0
  271. package/node_modules/pino/test/fixtures/transport-many-lines.js +29 -0
  272. package/node_modules/pino/test/fixtures/transport-preload-main.mjs +13 -0
  273. package/node_modules/pino/test/fixtures/transport-preload.mjs +13 -0
  274. package/node_modules/pino/test/fixtures/transport-string-stdout.js +9 -0
  275. package/node_modules/pino/test/fixtures/transport-transform.js +21 -0
  276. package/node_modules/pino/test/fixtures/transport-uses-pino-config.js +33 -0
  277. package/node_modules/pino/test/fixtures/transport-with-on-exit.js +12 -0
  278. package/node_modules/pino/test/fixtures/transport-worker-data.js +19 -0
  279. package/node_modules/pino/test/fixtures/transport-worker-name.js +24 -0
  280. package/node_modules/pino/test/fixtures/transport-worker.js +15 -0
  281. package/node_modules/pino/test/fixtures/transport-wrong-export-type.js +3 -0
  282. package/node_modules/pino/test/fixtures/ts/to-file-transport-native.mts +15 -0
  283. package/node_modules/pino/test/fixtures/ts/to-file-transport-with-transform.ts +18 -0
  284. package/node_modules/pino/test/fixtures/ts/to-file-transport.ts +11 -0
  285. package/node_modules/pino/test/fixtures/ts/transpile.cjs +36 -0
  286. package/node_modules/pino/test/fixtures/ts/transport-exit-immediately-with-async-dest.ts +15 -0
  287. package/node_modules/pino/test/fixtures/ts/transport-exit-immediately.ts +10 -0
  288. package/node_modules/pino/test/fixtures/ts/transport-exit-on-ready.ts +11 -0
  289. package/node_modules/pino/test/fixtures/ts/transport-main.ts +8 -0
  290. package/node_modules/pino/test/fixtures/ts/transport-string-stdout.ts +8 -0
  291. package/node_modules/pino/test/fixtures/ts/transport-worker.ts +14 -0
  292. package/node_modules/pino/test/formatters.test.js +364 -0
  293. package/node_modules/pino/test/helper.d.ts +4 -0
  294. package/node_modules/pino/test/helper.js +159 -0
  295. package/node_modules/pino/test/hooks.test.js +114 -0
  296. package/node_modules/pino/test/http.test.js +214 -0
  297. package/node_modules/pino/test/internals/version.test.js +17 -0
  298. package/node_modules/pino/test/is-level-enabled.test.js +179 -0
  299. package/node_modules/pino/test/jest/basic.spec.js +10 -0
  300. package/node_modules/pino/test/levels.test.js +810 -0
  301. package/node_modules/pino/test/metadata.test.js +120 -0
  302. package/node_modules/pino/test/mixin-merge-strategy.test.js +57 -0
  303. package/node_modules/pino/test/mixin.test.js +241 -0
  304. package/node_modules/pino/test/multistream.test.js +793 -0
  305. package/node_modules/pino/test/redact.test.js +923 -0
  306. package/node_modules/pino/test/serializers.test.js +257 -0
  307. package/node_modules/pino/test/smoke.js +59 -0
  308. package/node_modules/pino/test/stdout-protection.test.js +41 -0
  309. package/node_modules/pino/test/syncfalse.test.js +186 -0
  310. package/node_modules/pino/test/timestamp-nano.test.js +37 -0
  311. package/node_modules/pino/test/timestamp.test.js +124 -0
  312. package/node_modules/pino/test/transport/big.test.js +42 -0
  313. package/node_modules/pino/test/transport/bundlers-support.test.js +99 -0
  314. package/node_modules/pino/test/transport/caller.test.js +24 -0
  315. package/node_modules/pino/test/transport/core.test.js +818 -0
  316. package/node_modules/pino/test/transport/core.transpiled.test.ts +114 -0
  317. package/node_modules/pino/test/transport/crash.test.js +36 -0
  318. package/node_modules/pino/test/transport/module-link.test.js +241 -0
  319. package/node_modules/pino/test/transport/native-type-stripping.test.mjs +151 -0
  320. package/node_modules/pino/test/transport/node-options.test.js +116 -0
  321. package/node_modules/pino/test/transport/pipeline.test.js +137 -0
  322. package/node_modules/pino/test/transport/preload.test.js +54 -0
  323. package/node_modules/pino/test/transport/repl.test.js +15 -0
  324. package/node_modules/pino/test/transport/sync-false.test.js +79 -0
  325. package/node_modules/pino/test/transport/sync-true.test.js +57 -0
  326. package/node_modules/pino/test/transport/targets.test.js +48 -0
  327. package/node_modules/pino/test/transport/uses-pino-config.test.js +166 -0
  328. package/node_modules/pino/test/transport-stream.test.js +40 -0
  329. package/node_modules/pino/test/types/pino-import.tst.cts +30 -0
  330. package/node_modules/pino/test/types/pino-import.tst.js +73 -0
  331. package/node_modules/pino/test/types/pino-multistream.tst.ts +49 -0
  332. package/node_modules/pino/test/types/pino-top-export.tst.ts +32 -0
  333. package/node_modules/pino/test/types/pino-transport.tst.ts +171 -0
  334. package/node_modules/pino/test/types/pino-type-only.tst.ts +77 -0
  335. package/node_modules/pino/test/types/pino.ts +98 -0
  336. package/node_modules/pino/test/types/pino.tst.ts +681 -0
  337. package/node_modules/pino/test/types/tsconfig.json +10 -0
  338. package/node_modules/pino/tsconfig.json +14 -0
  339. package/node_modules/pino-pretty/.borp.yaml +6 -0
  340. package/node_modules/pino-pretty/.editorconfig +13 -0
  341. package/node_modules/pino-pretty/.github/dependabot.yml +13 -0
  342. package/node_modules/pino-pretty/.github/workflows/ci.yml +83 -0
  343. package/node_modules/pino-pretty/LICENSE +21 -0
  344. package/node_modules/pino-pretty/Readme.md +425 -0
  345. package/node_modules/pino-pretty/SECURITY.md +146 -0
  346. package/node_modules/pino-pretty/benchmark.js +105 -0
  347. package/node_modules/pino-pretty/bin.js +113 -0
  348. package/node_modules/pino-pretty/demo.png +0 -0
  349. package/node_modules/pino-pretty/docs/help.md +24 -0
  350. package/node_modules/pino-pretty/eslint.config.js +5 -0
  351. package/node_modules/pino-pretty/help/help.txt +68 -0
  352. package/node_modules/pino-pretty/index.d.ts +227 -0
  353. package/node_modules/pino-pretty/index.js +234 -0
  354. package/node_modules/pino-pretty/lib/colors.js +134 -0
  355. package/node_modules/pino-pretty/lib/colors.test.js +132 -0
  356. package/node_modules/pino-pretty/lib/constants.js +55 -0
  357. package/node_modules/pino-pretty/lib/pretty.js +171 -0
  358. package/node_modules/pino-pretty/lib/utils/build-safe-sonic-boom.js +69 -0
  359. package/node_modules/pino-pretty/lib/utils/build-safe-sonic-boom.test.js +84 -0
  360. package/node_modules/pino-pretty/lib/utils/create-date.js +26 -0
  361. package/node_modules/pino-pretty/lib/utils/create-date.test.js +20 -0
  362. package/node_modules/pino-pretty/lib/utils/delete-log-property.js +28 -0
  363. package/node_modules/pino-pretty/lib/utils/delete-log-property.test.js +31 -0
  364. package/node_modules/pino-pretty/lib/utils/filter-log.js +99 -0
  365. package/node_modules/pino-pretty/lib/utils/filter-log.test.js +265 -0
  366. package/node_modules/pino-pretty/lib/utils/format-time.js +66 -0
  367. package/node_modules/pino-pretty/lib/utils/format-time.test.js +71 -0
  368. package/node_modules/pino-pretty/lib/utils/get-level-label-data.js +29 -0
  369. package/node_modules/pino-pretty/lib/utils/get-property-value.js +30 -0
  370. package/node_modules/pino-pretty/lib/utils/get-property-value.test.js +31 -0
  371. package/node_modules/pino-pretty/lib/utils/handle-custom-levels-names-opts.js +38 -0
  372. package/node_modules/pino-pretty/lib/utils/handle-custom-levels-names-opts.test.js +45 -0
  373. package/node_modules/pino-pretty/lib/utils/handle-custom-levels-opts.js +39 -0
  374. package/node_modules/pino-pretty/lib/utils/handle-custom-levels-opts.test.js +47 -0
  375. package/node_modules/pino-pretty/lib/utils/index.js +108 -0
  376. package/node_modules/pino-pretty/lib/utils/index.test.js +37 -0
  377. package/node_modules/pino-pretty/lib/utils/interpret-conditionals.js +41 -0
  378. package/node_modules/pino-pretty/lib/utils/interpret-conditionals.test.js +84 -0
  379. package/node_modules/pino-pretty/lib/utils/is-object.js +7 -0
  380. package/node_modules/pino-pretty/lib/utils/is-object.test.js +10 -0
  381. package/node_modules/pino-pretty/lib/utils/is-valid-date.js +14 -0
  382. package/node_modules/pino-pretty/lib/utils/is-valid-date.test.js +16 -0
  383. package/node_modules/pino-pretty/lib/utils/join-lines-with-indentation.js +29 -0
  384. package/node_modules/pino-pretty/lib/utils/join-lines-with-indentation.test.js +16 -0
  385. package/node_modules/pino-pretty/lib/utils/noop.js +3 -0
  386. package/node_modules/pino-pretty/lib/utils/noop.test.js +12 -0
  387. package/node_modules/pino-pretty/lib/utils/parse-factory-options.js +171 -0
  388. package/node_modules/pino-pretty/lib/utils/prettify-error-log.js +76 -0
  389. package/node_modules/pino-pretty/lib/utils/prettify-error-log.test.js +143 -0
  390. package/node_modules/pino-pretty/lib/utils/prettify-error.js +54 -0
  391. package/node_modules/pino-pretty/lib/utils/prettify-error.test.js +25 -0
  392. package/node_modules/pino-pretty/lib/utils/prettify-level.js +41 -0
  393. package/node_modules/pino-pretty/lib/utils/prettify-level.test.js +70 -0
  394. package/node_modules/pino-pretty/lib/utils/prettify-message.js +65 -0
  395. package/node_modules/pino-pretty/lib/utils/prettify-message.test.js +287 -0
  396. package/node_modules/pino-pretty/lib/utils/prettify-metadata.js +75 -0
  397. package/node_modules/pino-pretty/lib/utils/prettify-metadata.test.js +170 -0
  398. package/node_modules/pino-pretty/lib/utils/prettify-object.js +115 -0
  399. package/node_modules/pino-pretty/lib/utils/prettify-object.test.js +217 -0
  400. package/node_modules/pino-pretty/lib/utils/prettify-time.js +43 -0
  401. package/node_modules/pino-pretty/lib/utils/prettify-time.test.js +264 -0
  402. package/node_modules/pino-pretty/lib/utils/split-property-key.js +49 -0
  403. package/node_modules/pino-pretty/lib/utils/split-property-key.test.js +29 -0
  404. package/node_modules/pino-pretty/lib/utils/strip-unsafe-control-chars.js +18 -0
  405. package/node_modules/pino-pretty/lib/utils/strip-unsafe-control-chars.test.js +9 -0
  406. package/node_modules/pino-pretty/package.json +64 -0
  407. package/node_modules/pino-pretty/test/basic.test.js +1305 -0
  408. package/node_modules/pino-pretty/test/boolean-options.test.js +228 -0
  409. package/node_modules/pino-pretty/test/cli-rc.test.js +275 -0
  410. package/node_modules/pino-pretty/test/cli.test.js +360 -0
  411. package/node_modules/pino-pretty/test/crlf.test.js +33 -0
  412. package/node_modules/pino-pretty/test/error-objects.test.js +494 -0
  413. package/node_modules/pino-pretty/test/example/example.js +33 -0
  414. package/node_modules/pino-pretty/test/helper.js +19 -0
  415. package/node_modules/pino-pretty/test/types/exports.tst.ts +15 -0
  416. package/node_modules/pino-pretty/test/types/pino-pretty.tst.ts +140 -0
  417. package/node_modules/pino-pretty/test/types/tsconfig.json +9 -0
  418. package/package.json +12 -5
  419. package/lib/cli/commands/init.d.ts +0 -1
  420. package/lib/cli/commands/init.js +0 -8
  421. package/node_modules/@types/node/globals.global.d.ts +0 -1
@@ -1,39 +1,44 @@
1
- declare module 'http2' {
2
- import EventEmitter = require('events');
3
- import * as fs from 'fs';
4
- import * as net from 'net';
5
- import * as stream from 'stream';
6
- import * as tls from 'tls';
7
- import * as url from 'url';
8
-
1
+ /**
2
+ * The `node:http2` module provides an implementation of the [HTTP/2](https://tools.ietf.org/html/rfc7540) protocol.
3
+ * It can be accessed using:
4
+ *
5
+ * ```js
6
+ * import http2 from 'node:http2';
7
+ * ```
8
+ * @since v8.4.0
9
+ * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/http2.js)
10
+ */
11
+ declare module "http2" {
12
+ import { NonSharedBuffer } from "node:buffer";
13
+ import EventEmitter = require("node:events");
14
+ import * as fs from "node:fs";
15
+ import * as net from "node:net";
16
+ import * as stream from "node:stream";
17
+ import * as tls from "node:tls";
18
+ import * as url from "node:url";
9
19
  import {
10
20
  IncomingHttpHeaders as Http1IncomingHttpHeaders,
11
- OutgoingHttpHeaders,
12
21
  IncomingMessage,
22
+ OutgoingHttpHeaders,
13
23
  ServerResponse,
14
- } from 'http';
15
- export { OutgoingHttpHeaders } from 'http';
16
-
24
+ } from "node:http";
25
+ export { OutgoingHttpHeaders } from "node:http";
17
26
  export interface IncomingHttpStatusHeader {
18
27
  ":status"?: number | undefined;
19
28
  }
20
-
21
29
  export interface IncomingHttpHeaders extends Http1IncomingHttpHeaders {
22
30
  ":path"?: string | undefined;
23
31
  ":method"?: string | undefined;
24
32
  ":authority"?: string | undefined;
25
33
  ":scheme"?: string | undefined;
26
34
  }
27
-
28
35
  // Http2Stream
29
-
30
36
  export interface StreamPriorityOptions {
31
37
  exclusive?: boolean | undefined;
32
38
  parent?: number | undefined;
33
39
  weight?: number | undefined;
34
40
  silent?: boolean | undefined;
35
41
  }
36
-
37
42
  export interface StreamState {
38
43
  localWindowSize?: number | undefined;
39
44
  state?: number | undefined;
@@ -42,55 +47,157 @@ declare module 'http2' {
42
47
  sumDependencyWeight?: number | undefined;
43
48
  weight?: number | undefined;
44
49
  }
45
-
46
50
  export interface ServerStreamResponseOptions {
47
51
  endStream?: boolean | undefined;
48
52
  waitForTrailers?: boolean | undefined;
49
53
  }
50
-
51
54
  export interface StatOptions {
52
55
  offset: number;
53
56
  length: number;
54
57
  }
55
-
56
58
  export interface ServerStreamFileResponseOptions {
57
- statCheck?(stats: fs.Stats, headers: OutgoingHttpHeaders, statOptions: StatOptions): void | boolean;
59
+ statCheck?:
60
+ | ((stats: fs.Stats, headers: OutgoingHttpHeaders, statOptions: StatOptions) => void)
61
+ | undefined;
58
62
  waitForTrailers?: boolean | undefined;
59
63
  offset?: number | undefined;
60
64
  length?: number | undefined;
61
65
  }
62
-
63
66
  export interface ServerStreamFileResponseOptionsWithError extends ServerStreamFileResponseOptions {
64
- onError?(err: NodeJS.ErrnoException): void;
67
+ onError?: ((err: NodeJS.ErrnoException) => void) | undefined;
65
68
  }
66
-
67
69
  export interface Http2Stream extends stream.Duplex {
70
+ /**
71
+ * Set to `true` if the `Http2Stream` instance was aborted abnormally. When set,
72
+ * the `'aborted'` event will have been emitted.
73
+ * @since v8.4.0
74
+ */
68
75
  readonly aborted: boolean;
76
+ /**
77
+ * This property shows the number of characters currently buffered to be written.
78
+ * See `net.Socket.bufferSize` for details.
79
+ * @since v11.2.0, v10.16.0
80
+ */
69
81
  readonly bufferSize: number;
82
+ /**
83
+ * Set to `true` if the `Http2Stream` instance has been closed.
84
+ * @since v9.4.0
85
+ */
70
86
  readonly closed: boolean;
87
+ /**
88
+ * Set to `true` if the `Http2Stream` instance has been destroyed and is no longer
89
+ * usable.
90
+ * @since v8.4.0
91
+ */
71
92
  readonly destroyed: boolean;
72
93
  /**
73
- * Set the true if the END_STREAM flag was set in the request or response HEADERS frame received,
74
- * indicating that no additional data should be received and the readable side of the Http2Stream will be closed.
94
+ * Set to `true` if the `END_STREAM` flag was set in the request or response
95
+ * HEADERS frame received, indicating that no additional data should be received
96
+ * and the readable side of the `Http2Stream` will be closed.
97
+ * @since v10.11.0
75
98
  */
76
99
  readonly endAfterHeaders: boolean;
100
+ /**
101
+ * The numeric stream identifier of this `Http2Stream` instance. Set to `undefined` if the stream identifier has not yet been assigned.
102
+ * @since v8.4.0
103
+ */
77
104
  readonly id?: number | undefined;
105
+ /**
106
+ * Set to `true` if the `Http2Stream` instance has not yet been assigned a
107
+ * numeric stream identifier.
108
+ * @since v9.4.0
109
+ */
78
110
  readonly pending: boolean;
111
+ /**
112
+ * Set to the `RST_STREAM` `error code` reported when the `Http2Stream` is
113
+ * destroyed after either receiving an `RST_STREAM` frame from the connected peer,
114
+ * calling `http2stream.close()`, or `http2stream.destroy()`. Will be `undefined` if the `Http2Stream` has not been closed.
115
+ * @since v8.4.0
116
+ */
79
117
  readonly rstCode: number;
118
+ /**
119
+ * An object containing the outbound headers sent for this `Http2Stream`.
120
+ * @since v9.5.0
121
+ */
80
122
  readonly sentHeaders: OutgoingHttpHeaders;
123
+ /**
124
+ * An array of objects containing the outbound informational (additional) headers
125
+ * sent for this `Http2Stream`.
126
+ * @since v9.5.0
127
+ */
81
128
  readonly sentInfoHeaders?: OutgoingHttpHeaders[] | undefined;
129
+ /**
130
+ * An object containing the outbound trailers sent for this `HttpStream`.
131
+ * @since v9.5.0
132
+ */
82
133
  readonly sentTrailers?: OutgoingHttpHeaders | undefined;
83
- readonly session: Http2Session;
134
+ /**
135
+ * A reference to the `Http2Session` instance that owns this `Http2Stream`. The
136
+ * value will be `undefined` after the `Http2Stream` instance is destroyed.
137
+ * @since v8.4.0
138
+ */
139
+ readonly session: Http2Session | undefined;
140
+ /**
141
+ * Provides miscellaneous information about the current state of the `Http2Stream`.
142
+ *
143
+ * A current state of this `Http2Stream`.
144
+ * @since v8.4.0
145
+ */
84
146
  readonly state: StreamState;
85
-
147
+ /**
148
+ * Closes the `Http2Stream` instance by sending an `RST_STREAM` frame to the
149
+ * connected HTTP/2 peer.
150
+ * @since v8.4.0
151
+ * @param [code=http2.constants.NGHTTP2_NO_ERROR] Unsigned 32-bit integer identifying the error code.
152
+ * @param callback An optional function registered to listen for the `'close'` event.
153
+ */
86
154
  close(code?: number, callback?: () => void): void;
155
+ /**
156
+ * Updates the priority for this `Http2Stream` instance.
157
+ * @since v8.4.0
158
+ */
87
159
  priority(options: StreamPriorityOptions): void;
160
+ /**
161
+ * ```js
162
+ * import http2 from 'node:http2';
163
+ * const client = http2.connect('http://example.org:8000');
164
+ * const { NGHTTP2_CANCEL } = http2.constants;
165
+ * const req = client.request({ ':path': '/' });
166
+ *
167
+ * // Cancel the stream if there's no activity after 5 seconds
168
+ * req.setTimeout(5000, () => req.close(NGHTTP2_CANCEL));
169
+ * ```
170
+ * @since v8.4.0
171
+ */
88
172
  setTimeout(msecs: number, callback?: () => void): void;
173
+ /**
174
+ * Sends a trailing `HEADERS` frame to the connected HTTP/2 peer. This method
175
+ * will cause the `Http2Stream` to be immediately closed and must only be
176
+ * called after the `'wantTrailers'` event has been emitted. When sending a
177
+ * request or sending a response, the `options.waitForTrailers` option must be set
178
+ * in order to keep the `Http2Stream` open after the final `DATA` frame so that
179
+ * trailers can be sent.
180
+ *
181
+ * ```js
182
+ * import http2 from 'node:http2';
183
+ * const server = http2.createServer();
184
+ * server.on('stream', (stream) => {
185
+ * stream.respond(undefined, { waitForTrailers: true });
186
+ * stream.on('wantTrailers', () => {
187
+ * stream.sendTrailers({ xyz: 'abc' });
188
+ * });
189
+ * stream.end('Hello World');
190
+ * });
191
+ * ```
192
+ *
193
+ * The HTTP/1 specification forbids trailers from containing HTTP/2 pseudo-header
194
+ * fields (e.g. `':method'`, `':path'`, etc).
195
+ * @since v10.0.0
196
+ */
89
197
  sendTrailers(headers: OutgoingHttpHeaders): void;
90
-
91
198
  addListener(event: "aborted", listener: () => void): this;
92
199
  addListener(event: "close", listener: () => void): this;
93
- addListener(event: "data", listener: (chunk: Buffer | string) => void): this;
200
+ addListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this;
94
201
  addListener(event: "drain", listener: () => void): this;
95
202
  addListener(event: "end", listener: () => void): this;
96
203
  addListener(event: "error", listener: (err: Error) => void): this;
@@ -103,10 +210,9 @@ declare module 'http2' {
103
210
  addListener(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
104
211
  addListener(event: "wantTrailers", listener: () => void): this;
105
212
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
106
-
107
213
  emit(event: "aborted"): boolean;
108
214
  emit(event: "close"): boolean;
109
- emit(event: "data", chunk: Buffer | string): boolean;
215
+ emit(event: "data", chunk: NonSharedBuffer | string): boolean;
110
216
  emit(event: "drain"): boolean;
111
217
  emit(event: "end"): boolean;
112
218
  emit(event: "error", err: Error): boolean;
@@ -119,10 +225,9 @@ declare module 'http2' {
119
225
  emit(event: "trailers", trailers: IncomingHttpHeaders, flags: number): boolean;
120
226
  emit(event: "wantTrailers"): boolean;
121
227
  emit(event: string | symbol, ...args: any[]): boolean;
122
-
123
228
  on(event: "aborted", listener: () => void): this;
124
229
  on(event: "close", listener: () => void): this;
125
- on(event: "data", listener: (chunk: Buffer | string) => void): this;
230
+ on(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this;
126
231
  on(event: "drain", listener: () => void): this;
127
232
  on(event: "end", listener: () => void): this;
128
233
  on(event: "error", listener: (err: Error) => void): this;
@@ -135,10 +240,9 @@ declare module 'http2' {
135
240
  on(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
136
241
  on(event: "wantTrailers", listener: () => void): this;
137
242
  on(event: string | symbol, listener: (...args: any[]) => void): this;
138
-
139
243
  once(event: "aborted", listener: () => void): this;
140
244
  once(event: "close", listener: () => void): this;
141
- once(event: "data", listener: (chunk: Buffer | string) => void): this;
245
+ once(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this;
142
246
  once(event: "drain", listener: () => void): this;
143
247
  once(event: "end", listener: () => void): this;
144
248
  once(event: "error", listener: (err: Error) => void): this;
@@ -151,10 +255,9 @@ declare module 'http2' {
151
255
  once(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
152
256
  once(event: "wantTrailers", listener: () => void): this;
153
257
  once(event: string | symbol, listener: (...args: any[]) => void): this;
154
-
155
258
  prependListener(event: "aborted", listener: () => void): this;
156
259
  prependListener(event: "close", listener: () => void): this;
157
- prependListener(event: "data", listener: (chunk: Buffer | string) => void): this;
260
+ prependListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this;
158
261
  prependListener(event: "drain", listener: () => void): this;
159
262
  prependListener(event: "end", listener: () => void): this;
160
263
  prependListener(event: "error", listener: (err: Error) => void): this;
@@ -167,10 +270,9 @@ declare module 'http2' {
167
270
  prependListener(event: "trailers", listener: (trailers: IncomingHttpHeaders, flags: number) => void): this;
168
271
  prependListener(event: "wantTrailers", listener: () => void): this;
169
272
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
170
-
171
273
  prependOnceListener(event: "aborted", listener: () => void): this;
172
274
  prependOnceListener(event: "close", listener: () => void): this;
173
- prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this;
275
+ prependOnceListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this;
174
276
  prependOnceListener(event: "drain", listener: () => void): this;
175
277
  prependOnceListener(event: "end", listener: () => void): this;
176
278
  prependOnceListener(event: "error", listener: (err: Error) => void): this;
@@ -184,58 +286,338 @@ declare module 'http2' {
184
286
  prependOnceListener(event: "wantTrailers", listener: () => void): this;
185
287
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
186
288
  }
187
-
188
289
  export interface ClientHttp2Stream extends Http2Stream {
189
290
  addListener(event: "continue", listener: () => {}): this;
190
- addListener(event: "headers", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
291
+ addListener(
292
+ event: "headers",
293
+ listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
294
+ ): this;
191
295
  addListener(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
192
- addListener(event: "response", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
296
+ addListener(
297
+ event: "response",
298
+ listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
299
+ ): this;
193
300
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
194
-
195
301
  emit(event: "continue"): boolean;
196
302
  emit(event: "headers", headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number): boolean;
197
303
  emit(event: "push", headers: IncomingHttpHeaders, flags: number): boolean;
198
304
  emit(event: "response", headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number): boolean;
199
305
  emit(event: string | symbol, ...args: any[]): boolean;
200
-
201
306
  on(event: "continue", listener: () => {}): this;
202
- on(event: "headers", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
307
+ on(
308
+ event: "headers",
309
+ listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
310
+ ): this;
203
311
  on(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
204
- on(event: "response", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
312
+ on(
313
+ event: "response",
314
+ listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
315
+ ): this;
205
316
  on(event: string | symbol, listener: (...args: any[]) => void): this;
206
-
207
317
  once(event: "continue", listener: () => {}): this;
208
- once(event: "headers", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
318
+ once(
319
+ event: "headers",
320
+ listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
321
+ ): this;
209
322
  once(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
210
- once(event: "response", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
323
+ once(
324
+ event: "response",
325
+ listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
326
+ ): this;
211
327
  once(event: string | symbol, listener: (...args: any[]) => void): this;
212
-
213
328
  prependListener(event: "continue", listener: () => {}): this;
214
- prependListener(event: "headers", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
329
+ prependListener(
330
+ event: "headers",
331
+ listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
332
+ ): this;
215
333
  prependListener(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
216
- prependListener(event: "response", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
334
+ prependListener(
335
+ event: "response",
336
+ listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
337
+ ): this;
217
338
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
218
-
219
339
  prependOnceListener(event: "continue", listener: () => {}): this;
220
- prependOnceListener(event: "headers", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
340
+ prependOnceListener(
341
+ event: "headers",
342
+ listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
343
+ ): this;
221
344
  prependOnceListener(event: "push", listener: (headers: IncomingHttpHeaders, flags: number) => void): this;
222
- prependOnceListener(event: "response", listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
345
+ prependOnceListener(
346
+ event: "response",
347
+ listener: (headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void,
348
+ ): this;
223
349
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
224
350
  }
225
-
226
351
  export interface ServerHttp2Stream extends Http2Stream {
352
+ /**
353
+ * True if headers were sent, false otherwise (read-only).
354
+ * @since v8.4.0
355
+ */
227
356
  readonly headersSent: boolean;
357
+ /**
358
+ * Read-only property mapped to the `SETTINGS_ENABLE_PUSH` flag of the remote
359
+ * client's most recent `SETTINGS` frame. Will be `true` if the remote peer
360
+ * accepts push streams, `false` otherwise. Settings are the same for every `Http2Stream` in the same `Http2Session`.
361
+ * @since v8.4.0
362
+ */
228
363
  readonly pushAllowed: boolean;
364
+ /**
365
+ * Sends an additional informational `HEADERS` frame to the connected HTTP/2 peer.
366
+ * @since v8.4.0
367
+ */
229
368
  additionalHeaders(headers: OutgoingHttpHeaders): void;
230
- pushStream(headers: OutgoingHttpHeaders, callback?: (err: Error | null, pushStream: ServerHttp2Stream, headers: OutgoingHttpHeaders) => void): void;
231
- pushStream(headers: OutgoingHttpHeaders, options?: StreamPriorityOptions, callback?: (err: Error | null, pushStream: ServerHttp2Stream, headers: OutgoingHttpHeaders) => void): void;
369
+ /**
370
+ * Initiates a push stream. The callback is invoked with the new `Http2Stream` instance created for the push stream passed as the second argument, or an `Error` passed as the first argument.
371
+ *
372
+ * ```js
373
+ * import http2 from 'node:http2';
374
+ * const server = http2.createServer();
375
+ * server.on('stream', (stream) => {
376
+ * stream.respond({ ':status': 200 });
377
+ * stream.pushStream({ ':path': '/' }, (err, pushStream, headers) => {
378
+ * if (err) throw err;
379
+ * pushStream.respond({ ':status': 200 });
380
+ * pushStream.end('some pushed data');
381
+ * });
382
+ * stream.end('some data');
383
+ * });
384
+ * ```
385
+ *
386
+ * Setting the weight of a push stream is not allowed in the `HEADERS` frame. Pass
387
+ * a `weight` value to `http2stream.priority` with the `silent` option set to `true` to enable server-side bandwidth balancing between concurrent streams.
388
+ *
389
+ * Calling `http2stream.pushStream()` from within a pushed stream is not permitted
390
+ * and will throw an error.
391
+ * @since v8.4.0
392
+ * @param callback Callback that is called once the push stream has been initiated.
393
+ */
394
+ pushStream(
395
+ headers: OutgoingHttpHeaders,
396
+ callback?: (err: Error | null, pushStream: ServerHttp2Stream, headers: OutgoingHttpHeaders) => void,
397
+ ): void;
398
+ pushStream(
399
+ headers: OutgoingHttpHeaders,
400
+ options?: StreamPriorityOptions,
401
+ callback?: (err: Error | null, pushStream: ServerHttp2Stream, headers: OutgoingHttpHeaders) => void,
402
+ ): void;
403
+ /**
404
+ * ```js
405
+ * import http2 from 'node:http2';
406
+ * const server = http2.createServer();
407
+ * server.on('stream', (stream) => {
408
+ * stream.respond({ ':status': 200 });
409
+ * stream.end('some data');
410
+ * });
411
+ * ```
412
+ *
413
+ * Initiates a response. When the `options.waitForTrailers` option is set, the `'wantTrailers'` event
414
+ * will be emitted immediately after queuing the last chunk of payload data to be sent.
415
+ * The `http2stream.sendTrailers()` method can then be used to send trailing header fields to the peer.
416
+ *
417
+ * When `options.waitForTrailers` is set, the `Http2Stream` will not automatically
418
+ * close when the final `DATA` frame is transmitted. User code must call either `http2stream.sendTrailers()` or `http2stream.close()` to close the `Http2Stream`.
419
+ *
420
+ * ```js
421
+ * import http2 from 'node:http2';
422
+ * const server = http2.createServer();
423
+ * server.on('stream', (stream) => {
424
+ * stream.respond({ ':status': 200 }, { waitForTrailers: true });
425
+ * stream.on('wantTrailers', () => {
426
+ * stream.sendTrailers({ ABC: 'some value to send' });
427
+ * });
428
+ * stream.end('some data');
429
+ * });
430
+ * ```
431
+ * @since v8.4.0
432
+ */
232
433
  respond(headers?: OutgoingHttpHeaders, options?: ServerStreamResponseOptions): void;
233
- respondWithFD(fd: number | fs.promises.FileHandle, headers?: OutgoingHttpHeaders, options?: ServerStreamFileResponseOptions): void;
234
- respondWithFile(path: string, headers?: OutgoingHttpHeaders, options?: ServerStreamFileResponseOptionsWithError): void;
434
+ /**
435
+ * Initiates a response whose data is read from the given file descriptor. No
436
+ * validation is performed on the given file descriptor. If an error occurs while
437
+ * attempting to read data using the file descriptor, the `Http2Stream` will be
438
+ * closed using an `RST_STREAM` frame using the standard `INTERNAL_ERROR` code.
439
+ *
440
+ * When used, the `Http2Stream` object's `Duplex` interface will be closed
441
+ * automatically.
442
+ *
443
+ * ```js
444
+ * import http2 from 'node:http2';
445
+ * import fs from 'node:fs';
446
+ *
447
+ * const server = http2.createServer();
448
+ * server.on('stream', (stream) => {
449
+ * const fd = fs.openSync('/some/file', 'r');
450
+ *
451
+ * const stat = fs.fstatSync(fd);
452
+ * const headers = {
453
+ * 'content-length': stat.size,
454
+ * 'last-modified': stat.mtime.toUTCString(),
455
+ * 'content-type': 'text/plain; charset=utf-8',
456
+ * };
457
+ * stream.respondWithFD(fd, headers);
458
+ * stream.on('close', () => fs.closeSync(fd));
459
+ * });
460
+ * ```
461
+ *
462
+ * The optional `options.statCheck` function may be specified to give user code
463
+ * an opportunity to set additional content headers based on the `fs.Stat` details
464
+ * of the given fd. If the `statCheck` function is provided, the `http2stream.respondWithFD()` method will
465
+ * perform an `fs.fstat()` call to collect details on the provided file descriptor.
466
+ *
467
+ * The `offset` and `length` options may be used to limit the response to a
468
+ * specific range subset. This can be used, for instance, to support HTTP Range
469
+ * requests.
470
+ *
471
+ * The file descriptor or `FileHandle` is not closed when the stream is closed,
472
+ * so it will need to be closed manually once it is no longer needed.
473
+ * Using the same file descriptor concurrently for multiple streams
474
+ * is not supported and may result in data loss. Re-using a file descriptor
475
+ * after a stream has finished is supported.
476
+ *
477
+ * When the `options.waitForTrailers` option is set, the `'wantTrailers'` event
478
+ * will be emitted immediately after queuing the last chunk of payload data to be
479
+ * sent. The `http2stream.sendTrailers()` method can then be used to sent trailing
480
+ * header fields to the peer.
481
+ *
482
+ * When `options.waitForTrailers` is set, the `Http2Stream` will not automatically
483
+ * close when the final `DATA` frame is transmitted. User code _must_ call either `http2stream.sendTrailers()`
484
+ * or `http2stream.close()` to close the `Http2Stream`.
485
+ *
486
+ * ```js
487
+ * import http2 from 'node:http2';
488
+ * import fs from 'node:fs';
489
+ *
490
+ * const server = http2.createServer();
491
+ * server.on('stream', (stream) => {
492
+ * const fd = fs.openSync('/some/file', 'r');
493
+ *
494
+ * const stat = fs.fstatSync(fd);
495
+ * const headers = {
496
+ * 'content-length': stat.size,
497
+ * 'last-modified': stat.mtime.toUTCString(),
498
+ * 'content-type': 'text/plain; charset=utf-8',
499
+ * };
500
+ * stream.respondWithFD(fd, headers, { waitForTrailers: true });
501
+ * stream.on('wantTrailers', () => {
502
+ * stream.sendTrailers({ ABC: 'some value to send' });
503
+ * });
504
+ *
505
+ * stream.on('close', () => fs.closeSync(fd));
506
+ * });
507
+ * ```
508
+ * @since v8.4.0
509
+ * @param fd A readable file descriptor.
510
+ */
511
+ respondWithFD(
512
+ fd: number | fs.promises.FileHandle,
513
+ headers?: OutgoingHttpHeaders,
514
+ options?: ServerStreamFileResponseOptions,
515
+ ): void;
516
+ /**
517
+ * Sends a regular file as the response. The `path` must specify a regular file
518
+ * or an `'error'` event will be emitted on the `Http2Stream` object.
519
+ *
520
+ * When used, the `Http2Stream` object's `Duplex` interface will be closed
521
+ * automatically.
522
+ *
523
+ * The optional `options.statCheck` function may be specified to give user code
524
+ * an opportunity to set additional content headers based on the `fs.Stat` details
525
+ * of the given file:
526
+ *
527
+ * If an error occurs while attempting to read the file data, the `Http2Stream` will be closed using an
528
+ * `RST_STREAM` frame using the standard `INTERNAL_ERROR` code.
529
+ * If the `onError` callback is defined, then it will be called. Otherwise, the stream will be destroyed.
530
+ *
531
+ * Example using a file path:
532
+ *
533
+ * ```js
534
+ * import http2 from 'node:http2';
535
+ * const server = http2.createServer();
536
+ * server.on('stream', (stream) => {
537
+ * function statCheck(stat, headers) {
538
+ * headers['last-modified'] = stat.mtime.toUTCString();
539
+ * }
540
+ *
541
+ * function onError(err) {
542
+ * // stream.respond() can throw if the stream has been destroyed by
543
+ * // the other side.
544
+ * try {
545
+ * if (err.code === 'ENOENT') {
546
+ * stream.respond({ ':status': 404 });
547
+ * } else {
548
+ * stream.respond({ ':status': 500 });
549
+ * }
550
+ * } catch (err) {
551
+ * // Perform actual error handling.
552
+ * console.error(err);
553
+ * }
554
+ * stream.end();
555
+ * }
556
+ *
557
+ * stream.respondWithFile('/some/file',
558
+ * { 'content-type': 'text/plain; charset=utf-8' },
559
+ * { statCheck, onError });
560
+ * });
561
+ * ```
562
+ *
563
+ * The `options.statCheck` function may also be used to cancel the send operation
564
+ * by returning `false`. For instance, a conditional request may check the stat
565
+ * results to determine if the file has been modified to return an appropriate `304` response:
566
+ *
567
+ * ```js
568
+ * import http2 from 'node:http2';
569
+ * const server = http2.createServer();
570
+ * server.on('stream', (stream) => {
571
+ * function statCheck(stat, headers) {
572
+ * // Check the stat here...
573
+ * stream.respond({ ':status': 304 });
574
+ * return false; // Cancel the send operation
575
+ * }
576
+ * stream.respondWithFile('/some/file',
577
+ * { 'content-type': 'text/plain; charset=utf-8' },
578
+ * { statCheck });
579
+ * });
580
+ * ```
581
+ *
582
+ * The `content-length` header field will be automatically set.
583
+ *
584
+ * The `offset` and `length` options may be used to limit the response to a
585
+ * specific range subset. This can be used, for instance, to support HTTP Range
586
+ * requests.
587
+ *
588
+ * The `options.onError` function may also be used to handle all the errors
589
+ * that could happen before the delivery of the file is initiated. The
590
+ * default behavior is to destroy the stream.
591
+ *
592
+ * When the `options.waitForTrailers` option is set, the `'wantTrailers'` event
593
+ * will be emitted immediately after queuing the last chunk of payload data to be
594
+ * sent. The `http2stream.sendTrailers()` method can then be used to sent trailing
595
+ * header fields to the peer.
596
+ *
597
+ * When `options.waitForTrailers` is set, the `Http2Stream` will not automatically
598
+ * close when the final `DATA` frame is transmitted. User code must call either`http2stream.sendTrailers()` or `http2stream.close()` to close the`Http2Stream`.
599
+ *
600
+ * ```js
601
+ * import http2 from 'node:http2';
602
+ * const server = http2.createServer();
603
+ * server.on('stream', (stream) => {
604
+ * stream.respondWithFile('/some/file',
605
+ * { 'content-type': 'text/plain; charset=utf-8' },
606
+ * { waitForTrailers: true });
607
+ * stream.on('wantTrailers', () => {
608
+ * stream.sendTrailers({ ABC: 'some value to send' });
609
+ * });
610
+ * });
611
+ * ```
612
+ * @since v8.4.0
613
+ */
614
+ respondWithFile(
615
+ path: string,
616
+ headers?: OutgoingHttpHeaders,
617
+ options?: ServerStreamFileResponseOptionsWithError,
618
+ ): void;
235
619
  }
236
-
237
620
  // Http2Session
238
-
239
621
  export interface Settings {
240
622
  headerTableSize?: number | undefined;
241
623
  enablePush?: boolean | undefined;
@@ -245,15 +627,14 @@ declare module 'http2' {
245
627
  maxHeaderListSize?: number | undefined;
246
628
  enableConnectProtocol?: boolean | undefined;
247
629
  }
248
-
249
630
  export interface ClientSessionRequestOptions {
250
631
  endStream?: boolean | undefined;
251
632
  exclusive?: boolean | undefined;
252
633
  parent?: number | undefined;
253
634
  weight?: number | undefined;
254
635
  waitForTrailers?: boolean | undefined;
636
+ signal?: AbortSignal | undefined;
255
637
  }
256
-
257
638
  export interface SessionState {
258
639
  effectiveLocalWindowSize?: number | undefined;
259
640
  effectiveRecvDataLength?: number | undefined;
@@ -265,412 +646,1584 @@ declare module 'http2' {
265
646
  deflateDynamicTableSize?: number | undefined;
266
647
  inflateDynamicTableSize?: number | undefined;
267
648
  }
268
-
269
649
  export interface Http2Session extends EventEmitter {
650
+ /**
651
+ * Value will be `undefined` if the `Http2Session` is not yet connected to a
652
+ * socket, `h2c` if the `Http2Session` is not connected to a `TLSSocket`, or
653
+ * will return the value of the connected `TLSSocket`'s own `alpnProtocol` property.
654
+ * @since v9.4.0
655
+ */
270
656
  readonly alpnProtocol?: string | undefined;
657
+ /**
658
+ * Will be `true` if this `Http2Session` instance has been closed, otherwise `false`.
659
+ * @since v9.4.0
660
+ */
271
661
  readonly closed: boolean;
662
+ /**
663
+ * Will be `true` if this `Http2Session` instance is still connecting, will be set
664
+ * to `false` before emitting `connect` event and/or calling the `http2.connect` callback.
665
+ * @since v10.0.0
666
+ */
272
667
  readonly connecting: boolean;
668
+ /**
669
+ * Will be `true` if this `Http2Session` instance has been destroyed and must no
670
+ * longer be used, otherwise `false`.
671
+ * @since v8.4.0
672
+ */
273
673
  readonly destroyed: boolean;
674
+ /**
675
+ * Value is `undefined` if the `Http2Session` session socket has not yet been
676
+ * connected, `true` if the `Http2Session` is connected with a `TLSSocket`,
677
+ * and `false` if the `Http2Session` is connected to any other kind of socket
678
+ * or stream.
679
+ * @since v9.4.0
680
+ */
274
681
  readonly encrypted?: boolean | undefined;
682
+ /**
683
+ * A prototype-less object describing the current local settings of this `Http2Session`.
684
+ * The local settings are local to _this_`Http2Session` instance.
685
+ * @since v8.4.0
686
+ */
275
687
  readonly localSettings: Settings;
688
+ /**
689
+ * If the `Http2Session` is connected to a `TLSSocket`, the `originSet` property
690
+ * will return an `Array` of origins for which the `Http2Session` may be
691
+ * considered authoritative.
692
+ *
693
+ * The `originSet` property is only available when using a secure TLS connection.
694
+ * @since v9.4.0
695
+ */
276
696
  readonly originSet?: string[] | undefined;
697
+ /**
698
+ * Indicates whether the `Http2Session` is currently waiting for acknowledgment of
699
+ * a sent `SETTINGS` frame. Will be `true` after calling the `http2session.settings()` method.
700
+ * Will be `false` once all sent `SETTINGS` frames have been acknowledged.
701
+ * @since v8.4.0
702
+ */
277
703
  readonly pendingSettingsAck: boolean;
704
+ /**
705
+ * A prototype-less object describing the current remote settings of this`Http2Session`.
706
+ * The remote settings are set by the _connected_ HTTP/2 peer.
707
+ * @since v8.4.0
708
+ */
278
709
  readonly remoteSettings: Settings;
710
+ /**
711
+ * Returns a `Proxy` object that acts as a `net.Socket` (or `tls.TLSSocket`) but
712
+ * limits available methods to ones safe to use with HTTP/2.
713
+ *
714
+ * `destroy`, `emit`, `end`, `pause`, `read`, `resume`, and `write` will throw
715
+ * an error with code `ERR_HTTP2_NO_SOCKET_MANIPULATION`. See `Http2Session and Sockets` for more information.
716
+ *
717
+ * `setTimeout` method will be called on this `Http2Session`.
718
+ *
719
+ * All other interactions will be routed directly to the socket.
720
+ * @since v8.4.0
721
+ */
279
722
  readonly socket: net.Socket | tls.TLSSocket;
723
+ /**
724
+ * Provides miscellaneous information about the current state of the`Http2Session`.
725
+ *
726
+ * An object describing the current status of this `Http2Session`.
727
+ * @since v8.4.0
728
+ */
280
729
  readonly state: SessionState;
730
+ /**
731
+ * The `http2session.type` will be equal to `http2.constants.NGHTTP2_SESSION_SERVER` if this `Http2Session` instance is a
732
+ * server, and `http2.constants.NGHTTP2_SESSION_CLIENT` if the instance is a
733
+ * client.
734
+ * @since v8.4.0
735
+ */
281
736
  readonly type: number;
282
-
737
+ /**
738
+ * Gracefully closes the `Http2Session`, allowing any existing streams to
739
+ * complete on their own and preventing new `Http2Stream` instances from being
740
+ * created. Once closed, `http2session.destroy()`_might_ be called if there
741
+ * are no open `Http2Stream` instances.
742
+ *
743
+ * If specified, the `callback` function is registered as a handler for the`'close'` event.
744
+ * @since v9.4.0
745
+ */
283
746
  close(callback?: () => void): void;
747
+ /**
748
+ * Immediately terminates the `Http2Session` and the associated `net.Socket` or `tls.TLSSocket`.
749
+ *
750
+ * Once destroyed, the `Http2Session` will emit the `'close'` event. If `error` is not undefined, an `'error'` event will be emitted immediately before the `'close'` event.
751
+ *
752
+ * If there are any remaining open `Http2Streams` associated with the `Http2Session`, those will also be destroyed.
753
+ * @since v8.4.0
754
+ * @param error An `Error` object if the `Http2Session` is being destroyed due to an error.
755
+ * @param code The HTTP/2 error code to send in the final `GOAWAY` frame. If unspecified, and `error` is not undefined, the default is `INTERNAL_ERROR`, otherwise defaults to `NO_ERROR`.
756
+ */
284
757
  destroy(error?: Error, code?: number): void;
758
+ /**
759
+ * Transmits a `GOAWAY` frame to the connected peer _without_ shutting down the`Http2Session`.
760
+ * @since v9.4.0
761
+ * @param code An HTTP/2 error code
762
+ * @param lastStreamID The numeric ID of the last processed `Http2Stream`
763
+ * @param opaqueData A `TypedArray` or `DataView` instance containing additional data to be carried within the `GOAWAY` frame.
764
+ */
285
765
  goaway(code?: number, lastStreamID?: number, opaqueData?: NodeJS.ArrayBufferView): void;
286
- ping(callback: (err: Error | null, duration: number, payload: Buffer) => void): boolean;
287
- ping(payload: NodeJS.ArrayBufferView, callback: (err: Error | null, duration: number, payload: Buffer) => void): boolean;
766
+ /**
767
+ * Sends a `PING` frame to the connected HTTP/2 peer. A `callback` function must
768
+ * be provided. The method will return `true` if the `PING` was sent, `false` otherwise.
769
+ *
770
+ * The maximum number of outstanding (unacknowledged) pings is determined by the `maxOutstandingPings` configuration option. The default maximum is 10.
771
+ *
772
+ * If provided, the `payload` must be a `Buffer`, `TypedArray`, or `DataView` containing 8 bytes of data that will be transmitted with the `PING` and
773
+ * returned with the ping acknowledgment.
774
+ *
775
+ * The callback will be invoked with three arguments: an error argument that will
776
+ * be `null` if the `PING` was successfully acknowledged, a `duration` argument
777
+ * that reports the number of milliseconds elapsed since the ping was sent and the
778
+ * acknowledgment was received, and a `Buffer` containing the 8-byte `PING` payload.
779
+ *
780
+ * ```js
781
+ * session.ping(Buffer.from('abcdefgh'), (err, duration, payload) => {
782
+ * if (!err) {
783
+ * console.log(`Ping acknowledged in ${duration} milliseconds`);
784
+ * console.log(`With payload '${payload.toString()}'`);
785
+ * }
786
+ * });
787
+ * ```
788
+ *
789
+ * If the `payload` argument is not specified, the default payload will be the
790
+ * 64-bit timestamp (little endian) marking the start of the `PING` duration.
791
+ * @since v8.9.3
792
+ * @param payload Optional ping payload.
793
+ */
794
+ ping(callback: (err: Error | null, duration: number, payload: NonSharedBuffer) => void): boolean;
795
+ ping(
796
+ payload: NodeJS.ArrayBufferView,
797
+ callback: (err: Error | null, duration: number, payload: NonSharedBuffer) => void,
798
+ ): boolean;
799
+ /**
800
+ * Calls `ref()` on this `Http2Session` instance's underlying `net.Socket`.
801
+ * @since v9.4.0
802
+ */
288
803
  ref(): void;
804
+ /**
805
+ * Sets the local endpoint's window size.
806
+ * The `windowSize` is the total window size to set, not
807
+ * the delta.
808
+ *
809
+ * ```js
810
+ * import http2 from 'node:http2';
811
+ *
812
+ * const server = http2.createServer();
813
+ * const expectedWindowSize = 2 ** 20;
814
+ * server.on('connect', (session) => {
815
+ *
816
+ * // Set local window size to be 2 ** 20
817
+ * session.setLocalWindowSize(expectedWindowSize);
818
+ * });
819
+ * ```
820
+ * @since v15.3.0, v14.18.0
821
+ */
822
+ setLocalWindowSize(windowSize: number): void;
823
+ /**
824
+ * Used to set a callback function that is called when there is no activity on
825
+ * the `Http2Session` after `msecs` milliseconds. The given `callback` is
826
+ * registered as a listener on the `'timeout'` event.
827
+ * @since v8.4.0
828
+ */
289
829
  setTimeout(msecs: number, callback?: () => void): void;
290
- settings(settings: Settings): void;
830
+ /**
831
+ * Updates the current local settings for this `Http2Session` and sends a new `SETTINGS` frame to the connected HTTP/2 peer.
832
+ *
833
+ * Once called, the `http2session.pendingSettingsAck` property will be `true` while the session is waiting for the remote peer to acknowledge the new
834
+ * settings.
835
+ *
836
+ * The new settings will not become effective until the `SETTINGS` acknowledgment
837
+ * is received and the `'localSettings'` event is emitted. It is possible to send
838
+ * multiple `SETTINGS` frames while acknowledgment is still pending.
839
+ * @since v8.4.0
840
+ * @param callback Callback that is called once the session is connected or right away if the session is already connected.
841
+ */
842
+ settings(
843
+ settings: Settings,
844
+ callback?: (err: Error | null, settings: Settings, duration: number) => void,
845
+ ): void;
846
+ /**
847
+ * Calls `unref()` on this `Http2Session`instance's underlying `net.Socket`.
848
+ * @since v9.4.0
849
+ */
291
850
  unref(): void;
292
-
293
851
  addListener(event: "close", listener: () => void): this;
294
852
  addListener(event: "error", listener: (err: Error) => void): this;
295
- addListener(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this;
296
- addListener(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
853
+ addListener(
854
+ event: "frameError",
855
+ listener: (frameType: number, errorCode: number, streamID: number) => void,
856
+ ): this;
857
+ addListener(
858
+ event: "goaway",
859
+ listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void,
860
+ ): this;
297
861
  addListener(event: "localSettings", listener: (settings: Settings) => void): this;
298
862
  addListener(event: "ping", listener: () => void): this;
299
863
  addListener(event: "remoteSettings", listener: (settings: Settings) => void): this;
300
864
  addListener(event: "timeout", listener: () => void): this;
301
865
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
302
-
303
866
  emit(event: "close"): boolean;
304
867
  emit(event: "error", err: Error): boolean;
305
868
  emit(event: "frameError", frameType: number, errorCode: number, streamID: number): boolean;
306
- emit(event: "goaway", errorCode: number, lastStreamID: number, opaqueData: Buffer): boolean;
869
+ emit(event: "goaway", errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer): boolean;
307
870
  emit(event: "localSettings", settings: Settings): boolean;
308
871
  emit(event: "ping"): boolean;
309
872
  emit(event: "remoteSettings", settings: Settings): boolean;
310
873
  emit(event: "timeout"): boolean;
311
874
  emit(event: string | symbol, ...args: any[]): boolean;
312
-
313
875
  on(event: "close", listener: () => void): this;
314
876
  on(event: "error", listener: (err: Error) => void): this;
315
877
  on(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this;
316
- on(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
878
+ on(
879
+ event: "goaway",
880
+ listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void,
881
+ ): this;
317
882
  on(event: "localSettings", listener: (settings: Settings) => void): this;
318
883
  on(event: "ping", listener: () => void): this;
319
884
  on(event: "remoteSettings", listener: (settings: Settings) => void): this;
320
885
  on(event: "timeout", listener: () => void): this;
321
886
  on(event: string | symbol, listener: (...args: any[]) => void): this;
322
-
323
887
  once(event: "close", listener: () => void): this;
324
888
  once(event: "error", listener: (err: Error) => void): this;
325
889
  once(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this;
326
- once(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
890
+ once(
891
+ event: "goaway",
892
+ listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void,
893
+ ): this;
327
894
  once(event: "localSettings", listener: (settings: Settings) => void): this;
328
895
  once(event: "ping", listener: () => void): this;
329
896
  once(event: "remoteSettings", listener: (settings: Settings) => void): this;
330
897
  once(event: "timeout", listener: () => void): this;
331
898
  once(event: string | symbol, listener: (...args: any[]) => void): this;
332
-
333
899
  prependListener(event: "close", listener: () => void): this;
334
900
  prependListener(event: "error", listener: (err: Error) => void): this;
335
- prependListener(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this;
336
- prependListener(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
901
+ prependListener(
902
+ event: "frameError",
903
+ listener: (frameType: number, errorCode: number, streamID: number) => void,
904
+ ): this;
905
+ prependListener(
906
+ event: "goaway",
907
+ listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void,
908
+ ): this;
337
909
  prependListener(event: "localSettings", listener: (settings: Settings) => void): this;
338
910
  prependListener(event: "ping", listener: () => void): this;
339
911
  prependListener(event: "remoteSettings", listener: (settings: Settings) => void): this;
340
912
  prependListener(event: "timeout", listener: () => void): this;
341
913
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
342
-
343
914
  prependOnceListener(event: "close", listener: () => void): this;
344
915
  prependOnceListener(event: "error", listener: (err: Error) => void): this;
345
- prependOnceListener(event: "frameError", listener: (frameType: number, errorCode: number, streamID: number) => void): this;
346
- prependOnceListener(event: "goaway", listener: (errorCode: number, lastStreamID: number, opaqueData: Buffer) => void): this;
916
+ prependOnceListener(
917
+ event: "frameError",
918
+ listener: (frameType: number, errorCode: number, streamID: number) => void,
919
+ ): this;
920
+ prependOnceListener(
921
+ event: "goaway",
922
+ listener: (errorCode: number, lastStreamID: number, opaqueData?: NonSharedBuffer) => void,
923
+ ): this;
347
924
  prependOnceListener(event: "localSettings", listener: (settings: Settings) => void): this;
348
925
  prependOnceListener(event: "ping", listener: () => void): this;
349
926
  prependOnceListener(event: "remoteSettings", listener: (settings: Settings) => void): this;
350
927
  prependOnceListener(event: "timeout", listener: () => void): this;
351
928
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
352
929
  }
353
-
354
930
  export interface ClientHttp2Session extends Http2Session {
355
- request(headers?: OutgoingHttpHeaders, options?: ClientSessionRequestOptions): ClientHttp2Stream;
356
-
931
+ /**
932
+ * For HTTP/2 Client `Http2Session` instances only, the `http2session.request()` creates and returns an `Http2Stream` instance that can be used to send an
933
+ * HTTP/2 request to the connected server.
934
+ *
935
+ * When a `ClientHttp2Session` is first created, the socket may not yet be
936
+ * connected. if `clienthttp2session.request()` is called during this time, the
937
+ * actual request will be deferred until the socket is ready to go.
938
+ * If the `session` is closed before the actual request be executed, an `ERR_HTTP2_GOAWAY_SESSION` is thrown.
939
+ *
940
+ * This method is only available if `http2session.type` is equal to `http2.constants.NGHTTP2_SESSION_CLIENT`.
941
+ *
942
+ * ```js
943
+ * import http2 from 'node:http2';
944
+ * const clientSession = http2.connect('https://localhost:1234');
945
+ * const {
946
+ * HTTP2_HEADER_PATH,
947
+ * HTTP2_HEADER_STATUS,
948
+ * } = http2.constants;
949
+ *
950
+ * const req = clientSession.request({ [HTTP2_HEADER_PATH]: '/' });
951
+ * req.on('response', (headers) => {
952
+ * console.log(headers[HTTP2_HEADER_STATUS]);
953
+ * req.on('data', (chunk) => { // .. });
954
+ * req.on('end', () => { // .. });
955
+ * });
956
+ * ```
957
+ *
958
+ * When the `options.waitForTrailers` option is set, the `'wantTrailers'` event
959
+ * is emitted immediately after queuing the last chunk of payload data to be sent.
960
+ * The `http2stream.sendTrailers()` method can then be called to send trailing
961
+ * headers to the peer.
962
+ *
963
+ * When `options.waitForTrailers` is set, the `Http2Stream` will not automatically
964
+ * close when the final `DATA` frame is transmitted. User code must call either`http2stream.sendTrailers()` or `http2stream.close()` to close the`Http2Stream`.
965
+ *
966
+ * When `options.signal` is set with an `AbortSignal` and then `abort` on the
967
+ * corresponding `AbortController` is called, the request will emit an `'error'`event with an `AbortError` error.
968
+ *
969
+ * The `:method` and `:path` pseudo-headers are not specified within `headers`,
970
+ * they respectively default to:
971
+ *
972
+ * * `:method` \= `'GET'`
973
+ * * `:path` \= `/`
974
+ * @since v8.4.0
975
+ */
976
+ request(
977
+ headers?: OutgoingHttpHeaders | readonly string[],
978
+ options?: ClientSessionRequestOptions,
979
+ ): ClientHttp2Stream;
357
980
  addListener(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this;
358
981
  addListener(event: "origin", listener: (origins: string[]) => void): this;
359
- addListener(event: "connect", listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
360
- addListener(event: "stream", listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
982
+ addListener(
983
+ event: "connect",
984
+ listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
985
+ ): this;
986
+ addListener(
987
+ event: "stream",
988
+ listener: (
989
+ stream: ClientHttp2Stream,
990
+ headers: IncomingHttpHeaders & IncomingHttpStatusHeader,
991
+ flags: number,
992
+ ) => void,
993
+ ): this;
361
994
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
362
-
363
995
  emit(event: "altsvc", alt: string, origin: string, stream: number): boolean;
364
- emit(event: "origin", origins: ReadonlyArray<string>): boolean;
996
+ emit(event: "origin", origins: readonly string[]): boolean;
365
997
  emit(event: "connect", session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket): boolean;
366
- emit(event: "stream", stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number): boolean;
998
+ emit(
999
+ event: "stream",
1000
+ stream: ClientHttp2Stream,
1001
+ headers: IncomingHttpHeaders & IncomingHttpStatusHeader,
1002
+ flags: number,
1003
+ ): boolean;
367
1004
  emit(event: string | symbol, ...args: any[]): boolean;
368
-
369
1005
  on(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this;
370
1006
  on(event: "origin", listener: (origins: string[]) => void): this;
371
1007
  on(event: "connect", listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
372
- on(event: "stream", listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
1008
+ on(
1009
+ event: "stream",
1010
+ listener: (
1011
+ stream: ClientHttp2Stream,
1012
+ headers: IncomingHttpHeaders & IncomingHttpStatusHeader,
1013
+ flags: number,
1014
+ ) => void,
1015
+ ): this;
373
1016
  on(event: string | symbol, listener: (...args: any[]) => void): this;
374
-
375
1017
  once(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this;
376
1018
  once(event: "origin", listener: (origins: string[]) => void): this;
377
- once(event: "connect", listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
378
- once(event: "stream", listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
1019
+ once(
1020
+ event: "connect",
1021
+ listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
1022
+ ): this;
1023
+ once(
1024
+ event: "stream",
1025
+ listener: (
1026
+ stream: ClientHttp2Stream,
1027
+ headers: IncomingHttpHeaders & IncomingHttpStatusHeader,
1028
+ flags: number,
1029
+ ) => void,
1030
+ ): this;
379
1031
  once(event: string | symbol, listener: (...args: any[]) => void): this;
380
-
381
1032
  prependListener(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this;
382
1033
  prependListener(event: "origin", listener: (origins: string[]) => void): this;
383
- prependListener(event: "connect", listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
384
- prependListener(event: "stream", listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
1034
+ prependListener(
1035
+ event: "connect",
1036
+ listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
1037
+ ): this;
1038
+ prependListener(
1039
+ event: "stream",
1040
+ listener: (
1041
+ stream: ClientHttp2Stream,
1042
+ headers: IncomingHttpHeaders & IncomingHttpStatusHeader,
1043
+ flags: number,
1044
+ ) => void,
1045
+ ): this;
385
1046
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
386
-
387
1047
  prependOnceListener(event: "altsvc", listener: (alt: string, origin: string, stream: number) => void): this;
388
1048
  prependOnceListener(event: "origin", listener: (origins: string[]) => void): this;
389
- prependOnceListener(event: "connect", listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
390
- prependOnceListener(event: "stream", listener: (stream: ClientHttp2Stream, headers: IncomingHttpHeaders & IncomingHttpStatusHeader, flags: number) => void): this;
1049
+ prependOnceListener(
1050
+ event: "connect",
1051
+ listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
1052
+ ): this;
1053
+ prependOnceListener(
1054
+ event: "stream",
1055
+ listener: (
1056
+ stream: ClientHttp2Stream,
1057
+ headers: IncomingHttpHeaders & IncomingHttpStatusHeader,
1058
+ flags: number,
1059
+ ) => void,
1060
+ ): this;
391
1061
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
392
1062
  }
393
-
394
1063
  export interface AlternativeServiceOptions {
395
1064
  origin: number | string | url.URL;
396
1065
  }
397
-
398
- export interface ServerHttp2Session extends Http2Session {
399
- readonly server: Http2Server | Http2SecureServer;
400
-
1066
+ export interface ServerHttp2Session<
1067
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
1068
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
1069
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
1070
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
1071
+ > extends Http2Session {
1072
+ readonly server:
1073
+ | Http2Server<Http1Request, Http1Response, Http2Request, Http2Response>
1074
+ | Http2SecureServer<Http1Request, Http1Response, Http2Request, Http2Response>;
1075
+ /**
1076
+ * Submits an `ALTSVC` frame (as defined by [RFC 7838](https://tools.ietf.org/html/rfc7838)) to the connected client.
1077
+ *
1078
+ * ```js
1079
+ * import http2 from 'node:http2';
1080
+ *
1081
+ * const server = http2.createServer();
1082
+ * server.on('session', (session) => {
1083
+ * // Set altsvc for origin https://example.org:80
1084
+ * session.altsvc('h2=":8000"', 'https://example.org:80');
1085
+ * });
1086
+ *
1087
+ * server.on('stream', (stream) => {
1088
+ * // Set altsvc for a specific stream
1089
+ * stream.session.altsvc('h2=":8000"', stream.id);
1090
+ * });
1091
+ * ```
1092
+ *
1093
+ * Sending an `ALTSVC` frame with a specific stream ID indicates that the alternate
1094
+ * service is associated with the origin of the given `Http2Stream`.
1095
+ *
1096
+ * The `alt` and origin string _must_ contain only ASCII bytes and are
1097
+ * strictly interpreted as a sequence of ASCII bytes. The special value `'clear'`may be passed to clear any previously set alternative service for a given
1098
+ * domain.
1099
+ *
1100
+ * When a string is passed for the `originOrStream` argument, it will be parsed as
1101
+ * a URL and the origin will be derived. For instance, the origin for the
1102
+ * HTTP URL `'https://example.org/foo/bar'` is the ASCII string`'https://example.org'`. An error will be thrown if either the given string
1103
+ * cannot be parsed as a URL or if a valid origin cannot be derived.
1104
+ *
1105
+ * A `URL` object, or any object with an `origin` property, may be passed as`originOrStream`, in which case the value of the `origin` property will be
1106
+ * used. The value of the `origin` property _must_ be a properly serialized
1107
+ * ASCII origin.
1108
+ * @since v9.4.0
1109
+ * @param alt A description of the alternative service configuration as defined by `RFC 7838`.
1110
+ * @param originOrStream Either a URL string specifying the origin (or an `Object` with an `origin` property) or the numeric identifier of an active `Http2Stream` as given by the
1111
+ * `http2stream.id` property.
1112
+ */
401
1113
  altsvc(alt: string, originOrStream: number | string | url.URL | AlternativeServiceOptions): void;
402
- origin(...args: Array<string | url.URL | { origin: string }>): void;
403
-
404
- addListener(event: "connect", listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
405
- addListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1114
+ /**
1115
+ * Submits an `ORIGIN` frame (as defined by [RFC 8336](https://tools.ietf.org/html/rfc8336)) to the connected client
1116
+ * to advertise the set of origins for which the server is capable of providing
1117
+ * authoritative responses.
1118
+ *
1119
+ * ```js
1120
+ * import http2 from 'node:http2';
1121
+ * const options = getSecureOptionsSomehow();
1122
+ * const server = http2.createSecureServer(options);
1123
+ * server.on('stream', (stream) => {
1124
+ * stream.respond();
1125
+ * stream.end('ok');
1126
+ * });
1127
+ * server.on('session', (session) => {
1128
+ * session.origin('https://example.com', 'https://example.org');
1129
+ * });
1130
+ * ```
1131
+ *
1132
+ * When a string is passed as an `origin`, it will be parsed as a URL and the
1133
+ * origin will be derived. For instance, the origin for the HTTP URL `'https://example.org/foo/bar'` is the ASCII string` 'https://example.org'`. An error will be thrown if either the given
1134
+ * string
1135
+ * cannot be parsed as a URL or if a valid origin cannot be derived.
1136
+ *
1137
+ * A `URL` object, or any object with an `origin` property, may be passed as
1138
+ * an `origin`, in which case the value of the `origin` property will be
1139
+ * used. The value of the `origin` property _must_ be a properly serialized
1140
+ * ASCII origin.
1141
+ *
1142
+ * Alternatively, the `origins` option may be used when creating a new HTTP/2
1143
+ * server using the `http2.createSecureServer()` method:
1144
+ *
1145
+ * ```js
1146
+ * import http2 from 'node:http2';
1147
+ * const options = getSecureOptionsSomehow();
1148
+ * options.origins = ['https://example.com', 'https://example.org'];
1149
+ * const server = http2.createSecureServer(options);
1150
+ * server.on('stream', (stream) => {
1151
+ * stream.respond();
1152
+ * stream.end('ok');
1153
+ * });
1154
+ * ```
1155
+ * @since v10.12.0
1156
+ * @param origins One or more URL Strings passed as separate arguments.
1157
+ */
1158
+ origin(
1159
+ ...origins: Array<
1160
+ | string
1161
+ | url.URL
1162
+ | {
1163
+ origin: string;
1164
+ }
1165
+ >
1166
+ ): void;
1167
+ addListener(
1168
+ event: "connect",
1169
+ listener: (
1170
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1171
+ socket: net.Socket | tls.TLSSocket,
1172
+ ) => void,
1173
+ ): this;
1174
+ addListener(
1175
+ event: "stream",
1176
+ listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1177
+ ): this;
406
1178
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
407
-
408
- emit(event: "connect", session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket): boolean;
1179
+ emit(
1180
+ event: "connect",
1181
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1182
+ socket: net.Socket | tls.TLSSocket,
1183
+ ): boolean;
409
1184
  emit(event: "stream", stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
410
1185
  emit(event: string | symbol, ...args: any[]): boolean;
411
-
412
- on(event: "connect", listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
413
- on(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1186
+ on(
1187
+ event: "connect",
1188
+ listener: (
1189
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1190
+ socket: net.Socket | tls.TLSSocket,
1191
+ ) => void,
1192
+ ): this;
1193
+ on(
1194
+ event: "stream",
1195
+ listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1196
+ ): this;
414
1197
  on(event: string | symbol, listener: (...args: any[]) => void): this;
415
-
416
- once(event: "connect", listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
417
- once(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1198
+ once(
1199
+ event: "connect",
1200
+ listener: (
1201
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1202
+ socket: net.Socket | tls.TLSSocket,
1203
+ ) => void,
1204
+ ): this;
1205
+ once(
1206
+ event: "stream",
1207
+ listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1208
+ ): this;
418
1209
  once(event: string | symbol, listener: (...args: any[]) => void): this;
419
-
420
- prependListener(event: "connect", listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
421
- prependListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1210
+ prependListener(
1211
+ event: "connect",
1212
+ listener: (
1213
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1214
+ socket: net.Socket | tls.TLSSocket,
1215
+ ) => void,
1216
+ ): this;
1217
+ prependListener(
1218
+ event: "stream",
1219
+ listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1220
+ ): this;
422
1221
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
423
-
424
- prependOnceListener(event: "connect", listener: (session: ServerHttp2Session, socket: net.Socket | tls.TLSSocket) => void): this;
425
- prependOnceListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1222
+ prependOnceListener(
1223
+ event: "connect",
1224
+ listener: (
1225
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1226
+ socket: net.Socket | tls.TLSSocket,
1227
+ ) => void,
1228
+ ): this;
1229
+ prependOnceListener(
1230
+ event: "stream",
1231
+ listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1232
+ ): this;
426
1233
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
427
1234
  }
428
-
429
1235
  // Http2Server
430
-
431
1236
  export interface SessionOptions {
1237
+ /**
1238
+ * Sets the maximum dynamic table size for deflating header fields.
1239
+ * @default 4Kib
1240
+ */
432
1241
  maxDeflateDynamicTableSize?: number | undefined;
1242
+ /**
1243
+ * Sets the maximum number of settings entries per `SETTINGS` frame.
1244
+ * The minimum value allowed is `1`.
1245
+ * @default 32
1246
+ */
1247
+ maxSettings?: number | undefined;
1248
+ /**
1249
+ * Sets the maximum memory that the `Http2Session` is permitted to use.
1250
+ * The value is expressed in terms of number of megabytes, e.g. `1` equal 1 megabyte.
1251
+ * The minimum value allowed is `1`.
1252
+ * This is a credit based limit, existing `Http2Stream`s may cause this limit to be exceeded,
1253
+ * but new `Http2Stream` instances will be rejected while this limit is exceeded.
1254
+ * The current number of `Http2Stream` sessions, the current memory use of the header compression tables,
1255
+ * current data queued to be sent, and unacknowledged `PING` and `SETTINGS` frames are all counted towards the current limit.
1256
+ * @default 10
1257
+ */
433
1258
  maxSessionMemory?: number | undefined;
1259
+ /**
1260
+ * Sets the maximum number of header entries.
1261
+ * This is similar to `server.maxHeadersCount` or `request.maxHeadersCount` in the `node:http` module.
1262
+ * The minimum value is `1`.
1263
+ * @default 128
1264
+ */
434
1265
  maxHeaderListPairs?: number | undefined;
1266
+ /**
1267
+ * Sets the maximum number of outstanding, unacknowledged pings.
1268
+ * @default 10
1269
+ */
435
1270
  maxOutstandingPings?: number | undefined;
1271
+ /**
1272
+ * Sets the maximum allowed size for a serialized, compressed block of headers.
1273
+ * Attempts to send headers that exceed this limit will result in
1274
+ * a `'frameError'` event being emitted and the stream being closed and destroyed.
1275
+ */
436
1276
  maxSendHeaderBlockLength?: number | undefined;
1277
+ /**
1278
+ * Strategy used for determining the amount of padding to use for `HEADERS` and `DATA` frames.
1279
+ * @default http2.constants.PADDING_STRATEGY_NONE
1280
+ */
437
1281
  paddingStrategy?: number | undefined;
1282
+ /**
1283
+ * Sets the maximum number of concurrent streams for the remote peer as if a `SETTINGS` frame had been received.
1284
+ * Will be overridden if the remote peer sets its own value for `maxConcurrentStreams`.
1285
+ * @default 100
1286
+ */
438
1287
  peerMaxConcurrentStreams?: number | undefined;
1288
+ /**
1289
+ * The initial settings to send to the remote peer upon connection.
1290
+ */
439
1291
  settings?: Settings | undefined;
440
-
441
- selectPadding?(frameLen: number, maxFrameLen: number): number;
442
- createConnection?(authority: url.URL, option: SessionOptions): stream.Duplex;
1292
+ /**
1293
+ * The array of integer values determines the settings types,
1294
+ * which are included in the `CustomSettings`-property of the received remoteSettings.
1295
+ * Please see the `CustomSettings`-property of the `Http2Settings` object for more information, on the allowed setting types.
1296
+ */
1297
+ remoteCustomSettings?: number[] | undefined;
1298
+ /**
1299
+ * Specifies a timeout in milliseconds that
1300
+ * a server should wait when an [`'unknownProtocol'`][] is emitted. If the
1301
+ * socket has not been destroyed by that time the server will destroy it.
1302
+ * @default 100000
1303
+ */
1304
+ unknownProtocolTimeout?: number | undefined;
1305
+ /**
1306
+ * If `true`, it turns on strict leading
1307
+ * and trailing whitespace validation for HTTP/2 header field names and values
1308
+ * as per [RFC-9113](https://www.rfc-editor.org/rfc/rfc9113.html#section-8.2.1).
1309
+ * @since v24.2.0
1310
+ * @default true
1311
+ */
1312
+ strictFieldWhitespaceValidation?: boolean | undefined;
443
1313
  }
444
-
445
1314
  export interface ClientSessionOptions extends SessionOptions {
1315
+ /**
1316
+ * Sets the maximum number of reserved push streams the client will accept at any given time.
1317
+ * Once the current number of currently reserved push streams exceeds reaches this limit,
1318
+ * new push streams sent by the server will be automatically rejected.
1319
+ * The minimum allowed value is 0. The maximum allowed value is 2<sup>32</sup>-1.
1320
+ * A negative value sets this option to the maximum allowed value.
1321
+ * @default 200
1322
+ */
446
1323
  maxReservedRemoteStreams?: number | undefined;
1324
+ /**
1325
+ * An optional callback that receives the `URL` instance passed to `connect` and the `options` object,
1326
+ * and returns any `Duplex` stream that is to be used as the connection for this session.
1327
+ */
447
1328
  createConnection?: ((authority: url.URL, option: SessionOptions) => stream.Duplex) | undefined;
1329
+ /**
1330
+ * The protocol to connect with, if not set in the `authority`.
1331
+ * Value may be either `'http:'` or `'https:'`.
1332
+ * @default 'https:'
1333
+ */
1334
+ protocol?: "http:" | "https:" | undefined;
448
1335
  }
449
-
450
- export interface ServerSessionOptions extends SessionOptions {
451
- Http1IncomingMessage?: typeof IncomingMessage | undefined;
452
- Http1ServerResponse?: typeof ServerResponse | undefined;
453
- Http2ServerRequest?: typeof Http2ServerRequest | undefined;
454
- Http2ServerResponse?: typeof Http2ServerResponse | undefined;
1336
+ export interface ServerSessionOptions<
1337
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
1338
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
1339
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
1340
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
1341
+ > extends SessionOptions {
1342
+ streamResetBurst?: number | undefined;
1343
+ streamResetRate?: number | undefined;
1344
+ Http1IncomingMessage?: Http1Request | undefined;
1345
+ Http1ServerResponse?: Http1Response | undefined;
1346
+ Http2ServerRequest?: Http2Request | undefined;
1347
+ Http2ServerResponse?: Http2Response | undefined;
455
1348
  }
456
-
457
- export interface SecureClientSessionOptions extends ClientSessionOptions, tls.ConnectionOptions { }
458
- export interface SecureServerSessionOptions extends ServerSessionOptions, tls.TlsOptions { }
459
-
460
- export interface ServerOptions extends ServerSessionOptions { }
461
-
462
- export interface SecureServerOptions extends SecureServerSessionOptions {
1349
+ export interface SecureClientSessionOptions extends ClientSessionOptions, tls.ConnectionOptions {}
1350
+ export interface SecureServerSessionOptions<
1351
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
1352
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
1353
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
1354
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
1355
+ > extends ServerSessionOptions<Http1Request, Http1Response, Http2Request, Http2Response>, tls.TlsOptions {}
1356
+ export interface ServerOptions<
1357
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
1358
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
1359
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
1360
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
1361
+ > extends ServerSessionOptions<Http1Request, Http1Response, Http2Request, Http2Response> {}
1362
+ export interface SecureServerOptions<
1363
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
1364
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
1365
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
1366
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
1367
+ > extends SecureServerSessionOptions<Http1Request, Http1Response, Http2Request, Http2Response> {
463
1368
  allowHTTP1?: boolean | undefined;
464
1369
  origins?: string[] | undefined;
465
1370
  }
466
-
467
- export interface Http2Server extends net.Server {
468
- addListener(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
469
- addListener(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
470
- addListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
1371
+ interface HTTP2ServerCommon {
1372
+ setTimeout(msec?: number, callback?: () => void): this;
1373
+ /**
1374
+ * Throws ERR_HTTP2_INVALID_SETTING_VALUE for invalid settings values.
1375
+ * Throws ERR_INVALID_ARG_TYPE for invalid settings argument.
1376
+ */
1377
+ updateSettings(settings: Settings): void;
1378
+ }
1379
+ export interface Http2Server<
1380
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
1381
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
1382
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
1383
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
1384
+ > extends net.Server, HTTP2ServerCommon {
1385
+ addListener(
1386
+ event: "checkContinue",
1387
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1388
+ ): this;
1389
+ addListener(
1390
+ event: "request",
1391
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1392
+ ): this;
1393
+ addListener(
1394
+ event: "session",
1395
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1396
+ ): this;
471
1397
  addListener(event: "sessionError", listener: (err: Error) => void): this;
472
- addListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1398
+ addListener(
1399
+ event: "stream",
1400
+ listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1401
+ ): this;
473
1402
  addListener(event: "timeout", listener: () => void): this;
474
1403
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
475
-
476
- emit(event: "checkContinue", request: Http2ServerRequest, response: Http2ServerResponse): boolean;
477
- emit(event: "request", request: Http2ServerRequest, response: Http2ServerResponse): boolean;
478
- emit(event: "session", session: ServerHttp2Session): boolean;
1404
+ emit(
1405
+ event: "checkContinue",
1406
+ request: InstanceType<Http2Request>,
1407
+ response: InstanceType<Http2Response>,
1408
+ ): boolean;
1409
+ emit(event: "request", request: InstanceType<Http2Request>, response: InstanceType<Http2Response>): boolean;
1410
+ emit(
1411
+ event: "session",
1412
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1413
+ ): boolean;
479
1414
  emit(event: "sessionError", err: Error): boolean;
480
1415
  emit(event: "stream", stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
481
1416
  emit(event: "timeout"): boolean;
482
1417
  emit(event: string | symbol, ...args: any[]): boolean;
483
-
484
- on(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
485
- on(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
486
- on(event: "session", listener: (session: ServerHttp2Session) => void): this;
1418
+ on(
1419
+ event: "checkContinue",
1420
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1421
+ ): this;
1422
+ on(
1423
+ event: "request",
1424
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1425
+ ): this;
1426
+ on(
1427
+ event: "session",
1428
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1429
+ ): this;
487
1430
  on(event: "sessionError", listener: (err: Error) => void): this;
488
- on(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1431
+ on(
1432
+ event: "stream",
1433
+ listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1434
+ ): this;
489
1435
  on(event: "timeout", listener: () => void): this;
490
1436
  on(event: string | symbol, listener: (...args: any[]) => void): this;
491
-
492
- once(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
493
- once(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
494
- once(event: "session", listener: (session: ServerHttp2Session) => void): this;
1437
+ once(
1438
+ event: "checkContinue",
1439
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1440
+ ): this;
1441
+ once(
1442
+ event: "request",
1443
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1444
+ ): this;
1445
+ once(
1446
+ event: "session",
1447
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1448
+ ): this;
495
1449
  once(event: "sessionError", listener: (err: Error) => void): this;
496
- once(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1450
+ once(
1451
+ event: "stream",
1452
+ listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1453
+ ): this;
497
1454
  once(event: "timeout", listener: () => void): this;
498
1455
  once(event: string | symbol, listener: (...args: any[]) => void): this;
499
-
500
- prependListener(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
501
- prependListener(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
502
- prependListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
1456
+ prependListener(
1457
+ event: "checkContinue",
1458
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1459
+ ): this;
1460
+ prependListener(
1461
+ event: "request",
1462
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1463
+ ): this;
1464
+ prependListener(
1465
+ event: "session",
1466
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1467
+ ): this;
503
1468
  prependListener(event: "sessionError", listener: (err: Error) => void): this;
504
- prependListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1469
+ prependListener(
1470
+ event: "stream",
1471
+ listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1472
+ ): this;
505
1473
  prependListener(event: "timeout", listener: () => void): this;
506
1474
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
507
-
508
- prependOnceListener(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
509
- prependOnceListener(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
510
- prependOnceListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
1475
+ prependOnceListener(
1476
+ event: "checkContinue",
1477
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1478
+ ): this;
1479
+ prependOnceListener(
1480
+ event: "request",
1481
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1482
+ ): this;
1483
+ prependOnceListener(
1484
+ event: "session",
1485
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1486
+ ): this;
511
1487
  prependOnceListener(event: "sessionError", listener: (err: Error) => void): this;
512
- prependOnceListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1488
+ prependOnceListener(
1489
+ event: "stream",
1490
+ listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1491
+ ): this;
513
1492
  prependOnceListener(event: "timeout", listener: () => void): this;
514
1493
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
515
-
516
- setTimeout(msec?: number, callback?: () => void): this;
517
1494
  }
518
-
519
- export interface Http2SecureServer extends tls.Server {
520
- addListener(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
521
- addListener(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
522
- addListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
1495
+ export interface Http2SecureServer<
1496
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
1497
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
1498
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
1499
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
1500
+ > extends tls.Server, HTTP2ServerCommon {
1501
+ addListener(
1502
+ event: "checkContinue",
1503
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1504
+ ): this;
1505
+ addListener(
1506
+ event: "request",
1507
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1508
+ ): this;
1509
+ addListener(
1510
+ event: "session",
1511
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1512
+ ): this;
523
1513
  addListener(event: "sessionError", listener: (err: Error) => void): this;
524
- addListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1514
+ addListener(
1515
+ event: "stream",
1516
+ listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1517
+ ): this;
525
1518
  addListener(event: "timeout", listener: () => void): this;
526
1519
  addListener(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
527
1520
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
528
-
529
- emit(event: "checkContinue", request: Http2ServerRequest, response: Http2ServerResponse): boolean;
530
- emit(event: "request", request: Http2ServerRequest, response: Http2ServerResponse): boolean;
531
- emit(event: "session", session: ServerHttp2Session): boolean;
1521
+ emit(
1522
+ event: "checkContinue",
1523
+ request: InstanceType<Http2Request>,
1524
+ response: InstanceType<Http2Response>,
1525
+ ): boolean;
1526
+ emit(event: "request", request: InstanceType<Http2Request>, response: InstanceType<Http2Response>): boolean;
1527
+ emit(
1528
+ event: "session",
1529
+ session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>,
1530
+ ): boolean;
532
1531
  emit(event: "sessionError", err: Error): boolean;
533
1532
  emit(event: "stream", stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number): boolean;
534
1533
  emit(event: "timeout"): boolean;
535
1534
  emit(event: "unknownProtocol", socket: tls.TLSSocket): boolean;
536
1535
  emit(event: string | symbol, ...args: any[]): boolean;
537
-
538
- on(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
539
- on(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
540
- on(event: "session", listener: (session: ServerHttp2Session) => void): this;
1536
+ on(
1537
+ event: "checkContinue",
1538
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1539
+ ): this;
1540
+ on(
1541
+ event: "request",
1542
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1543
+ ): this;
1544
+ on(
1545
+ event: "session",
1546
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1547
+ ): this;
541
1548
  on(event: "sessionError", listener: (err: Error) => void): this;
542
- on(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1549
+ on(
1550
+ event: "stream",
1551
+ listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1552
+ ): this;
543
1553
  on(event: "timeout", listener: () => void): this;
544
1554
  on(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
545
1555
  on(event: string | symbol, listener: (...args: any[]) => void): this;
546
-
547
- once(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
548
- once(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
549
- once(event: "session", listener: (session: ServerHttp2Session) => void): this;
1556
+ once(
1557
+ event: "checkContinue",
1558
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1559
+ ): this;
1560
+ once(
1561
+ event: "request",
1562
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1563
+ ): this;
1564
+ once(
1565
+ event: "session",
1566
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1567
+ ): this;
550
1568
  once(event: "sessionError", listener: (err: Error) => void): this;
551
- once(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1569
+ once(
1570
+ event: "stream",
1571
+ listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1572
+ ): this;
552
1573
  once(event: "timeout", listener: () => void): this;
553
1574
  once(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
554
1575
  once(event: string | symbol, listener: (...args: any[]) => void): this;
555
-
556
- prependListener(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
557
- prependListener(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
558
- prependListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
1576
+ prependListener(
1577
+ event: "checkContinue",
1578
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1579
+ ): this;
1580
+ prependListener(
1581
+ event: "request",
1582
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1583
+ ): this;
1584
+ prependListener(
1585
+ event: "session",
1586
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1587
+ ): this;
559
1588
  prependListener(event: "sessionError", listener: (err: Error) => void): this;
560
- prependListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1589
+ prependListener(
1590
+ event: "stream",
1591
+ listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1592
+ ): this;
561
1593
  prependListener(event: "timeout", listener: () => void): this;
562
1594
  prependListener(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
563
1595
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
564
-
565
- prependOnceListener(event: "checkContinue", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
566
- prependOnceListener(event: "request", listener: (request: Http2ServerRequest, response: Http2ServerResponse) => void): this;
567
- prependOnceListener(event: "session", listener: (session: ServerHttp2Session) => void): this;
1596
+ prependOnceListener(
1597
+ event: "checkContinue",
1598
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1599
+ ): this;
1600
+ prependOnceListener(
1601
+ event: "request",
1602
+ listener: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
1603
+ ): this;
1604
+ prependOnceListener(
1605
+ event: "session",
1606
+ listener: (session: ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>) => void,
1607
+ ): this;
568
1608
  prependOnceListener(event: "sessionError", listener: (err: Error) => void): this;
569
- prependOnceListener(event: "stream", listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void): this;
1609
+ prependOnceListener(
1610
+ event: "stream",
1611
+ listener: (stream: ServerHttp2Stream, headers: IncomingHttpHeaders, flags: number) => void,
1612
+ ): this;
570
1613
  prependOnceListener(event: "timeout", listener: () => void): this;
571
1614
  prependOnceListener(event: "unknownProtocol", listener: (socket: tls.TLSSocket) => void): this;
572
1615
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
573
-
574
- setTimeout(msec?: number, callback?: () => void): this;
575
1616
  }
576
-
1617
+ /**
1618
+ * A `Http2ServerRequest` object is created by {@link Server} or {@link SecureServer} and passed as the first argument to the `'request'` event. It may be used to access a request status,
1619
+ * headers, and
1620
+ * data.
1621
+ * @since v8.4.0
1622
+ */
577
1623
  export class Http2ServerRequest extends stream.Readable {
578
- constructor(stream: ServerHttp2Stream, headers: IncomingHttpHeaders, options: stream.ReadableOptions, rawHeaders: ReadonlyArray<string>);
579
-
1624
+ constructor(
1625
+ stream: ServerHttp2Stream,
1626
+ headers: IncomingHttpHeaders,
1627
+ options: stream.ReadableOptions,
1628
+ rawHeaders: readonly string[],
1629
+ );
1630
+ /**
1631
+ * The `request.aborted` property will be `true` if the request has
1632
+ * been aborted.
1633
+ * @since v10.1.0
1634
+ */
580
1635
  readonly aborted: boolean;
1636
+ /**
1637
+ * The request authority pseudo header field. Because HTTP/2 allows requests
1638
+ * to set either `:authority` or `host`, this value is derived from `req.headers[':authority']` if present. Otherwise, it is derived from `req.headers['host']`.
1639
+ * @since v8.4.0
1640
+ */
581
1641
  readonly authority: string;
1642
+ /**
1643
+ * See `request.socket`.
1644
+ * @since v8.4.0
1645
+ * @deprecated Since v13.0.0 - Use `socket`.
1646
+ */
1647
+ readonly connection: net.Socket | tls.TLSSocket;
1648
+ /**
1649
+ * The `request.complete` property will be `true` if the request has
1650
+ * been completed, aborted, or destroyed.
1651
+ * @since v12.10.0
1652
+ */
1653
+ readonly complete: boolean;
1654
+ /**
1655
+ * The request/response headers object.
1656
+ *
1657
+ * Key-value pairs of header names and values. Header names are lower-cased.
1658
+ *
1659
+ * ```js
1660
+ * // Prints something like:
1661
+ * //
1662
+ * // { 'user-agent': 'curl/7.22.0',
1663
+ * // host: '127.0.0.1:8000',
1664
+ * // accept: '*' }
1665
+ * console.log(request.headers);
1666
+ * ```
1667
+ *
1668
+ * See `HTTP/2 Headers Object`.
1669
+ *
1670
+ * In HTTP/2, the request path, host name, protocol, and method are represented as
1671
+ * special headers prefixed with the `:` character (e.g. `':path'`). These special
1672
+ * headers will be included in the `request.headers` object. Care must be taken not
1673
+ * to inadvertently modify these special headers or errors may occur. For instance,
1674
+ * removing all headers from the request will cause errors to occur:
1675
+ *
1676
+ * ```js
1677
+ * removeAllHeaders(request.headers);
1678
+ * assert(request.url); // Fails because the :path header has been removed
1679
+ * ```
1680
+ * @since v8.4.0
1681
+ */
582
1682
  readonly headers: IncomingHttpHeaders;
1683
+ /**
1684
+ * In case of server request, the HTTP version sent by the client. In the case of
1685
+ * client response, the HTTP version of the connected-to server. Returns `'2.0'`.
1686
+ *
1687
+ * Also `message.httpVersionMajor` is the first integer and `message.httpVersionMinor` is the second.
1688
+ * @since v8.4.0
1689
+ */
583
1690
  readonly httpVersion: string;
1691
+ readonly httpVersionMinor: number;
1692
+ readonly httpVersionMajor: number;
1693
+ /**
1694
+ * The request method as a string. Read-only. Examples: `'GET'`, `'DELETE'`.
1695
+ * @since v8.4.0
1696
+ */
584
1697
  readonly method: string;
1698
+ /**
1699
+ * The raw request/response headers list exactly as they were received.
1700
+ *
1701
+ * The keys and values are in the same list. It is _not_ a
1702
+ * list of tuples. So, the even-numbered offsets are key values, and the
1703
+ * odd-numbered offsets are the associated values.
1704
+ *
1705
+ * Header names are not lowercased, and duplicates are not merged.
1706
+ *
1707
+ * ```js
1708
+ * // Prints something like:
1709
+ * //
1710
+ * // [ 'user-agent',
1711
+ * // 'this is invalid because there can be only one',
1712
+ * // 'User-Agent',
1713
+ * // 'curl/7.22.0',
1714
+ * // 'Host',
1715
+ * // '127.0.0.1:8000',
1716
+ * // 'ACCEPT',
1717
+ * // '*' ]
1718
+ * console.log(request.rawHeaders);
1719
+ * ```
1720
+ * @since v8.4.0
1721
+ */
585
1722
  readonly rawHeaders: string[];
1723
+ /**
1724
+ * The raw request/response trailer keys and values exactly as they were
1725
+ * received. Only populated at the `'end'` event.
1726
+ * @since v8.4.0
1727
+ */
586
1728
  readonly rawTrailers: string[];
1729
+ /**
1730
+ * The request scheme pseudo header field indicating the scheme
1731
+ * portion of the target URL.
1732
+ * @since v8.4.0
1733
+ */
587
1734
  readonly scheme: string;
1735
+ /**
1736
+ * Returns a `Proxy` object that acts as a `net.Socket` (or `tls.TLSSocket`) but
1737
+ * applies getters, setters, and methods based on HTTP/2 logic.
1738
+ *
1739
+ * `destroyed`, `readable`, and `writable` properties will be retrieved from and
1740
+ * set on `request.stream`.
1741
+ *
1742
+ * `destroy`, `emit`, `end`, `on` and `once` methods will be called on `request.stream`.
1743
+ *
1744
+ * `setTimeout` method will be called on `request.stream.session`.
1745
+ *
1746
+ * `pause`, `read`, `resume`, and `write` will throw an error with code `ERR_HTTP2_NO_SOCKET_MANIPULATION`. See `Http2Session and Sockets` for
1747
+ * more information.
1748
+ *
1749
+ * All other interactions will be routed directly to the socket. With TLS support,
1750
+ * use `request.socket.getPeerCertificate()` to obtain the client's
1751
+ * authentication details.
1752
+ * @since v8.4.0
1753
+ */
588
1754
  readonly socket: net.Socket | tls.TLSSocket;
1755
+ /**
1756
+ * The `Http2Stream` object backing the request.
1757
+ * @since v8.4.0
1758
+ */
589
1759
  readonly stream: ServerHttp2Stream;
1760
+ /**
1761
+ * The request/response trailers object. Only populated at the `'end'` event.
1762
+ * @since v8.4.0
1763
+ */
590
1764
  readonly trailers: IncomingHttpHeaders;
1765
+ /**
1766
+ * Request URL string. This contains only the URL that is present in the actual
1767
+ * HTTP request. If the request is:
1768
+ *
1769
+ * ```http
1770
+ * GET /status?name=ryan HTTP/1.1
1771
+ * Accept: text/plain
1772
+ * ```
1773
+ *
1774
+ * Then `request.url` will be:
1775
+ *
1776
+ * ```js
1777
+ * '/status?name=ryan'
1778
+ * ```
1779
+ *
1780
+ * To parse the url into its parts, `new URL()` can be used:
1781
+ *
1782
+ * ```console
1783
+ * $ node
1784
+ * > new URL('/status?name=ryan', 'http://example.com')
1785
+ * URL {
1786
+ * href: 'http://example.com/status?name=ryan',
1787
+ * origin: 'http://example.com',
1788
+ * protocol: 'http:',
1789
+ * username: '',
1790
+ * password: '',
1791
+ * host: 'example.com',
1792
+ * hostname: 'example.com',
1793
+ * port: '',
1794
+ * pathname: '/status',
1795
+ * search: '?name=ryan',
1796
+ * searchParams: URLSearchParams { 'name' => 'ryan' },
1797
+ * hash: ''
1798
+ * }
1799
+ * ```
1800
+ * @since v8.4.0
1801
+ */
591
1802
  url: string;
592
-
1803
+ /**
1804
+ * Sets the `Http2Stream`'s timeout value to `msecs`. If a callback is
1805
+ * provided, then it is added as a listener on the `'timeout'` event on
1806
+ * the response object.
1807
+ *
1808
+ * If no `'timeout'` listener is added to the request, the response, or
1809
+ * the server, then `Http2Stream`s are destroyed when they time out. If a
1810
+ * handler is assigned to the request, the response, or the server's `'timeout'`events, timed out sockets must be handled explicitly.
1811
+ * @since v8.4.0
1812
+ */
593
1813
  setTimeout(msecs: number, callback?: () => void): void;
594
- read(size?: number): Buffer | string | null;
595
-
1814
+ read(size?: number): NonSharedBuffer | string | null;
596
1815
  addListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this;
597
1816
  addListener(event: "close", listener: () => void): this;
598
- addListener(event: "data", listener: (chunk: Buffer | string) => void): this;
1817
+ addListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this;
599
1818
  addListener(event: "end", listener: () => void): this;
600
1819
  addListener(event: "readable", listener: () => void): this;
601
1820
  addListener(event: "error", listener: (err: Error) => void): this;
602
1821
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
603
-
604
1822
  emit(event: "aborted", hadError: boolean, code: number): boolean;
605
1823
  emit(event: "close"): boolean;
606
- emit(event: "data", chunk: Buffer | string): boolean;
1824
+ emit(event: "data", chunk: NonSharedBuffer | string): boolean;
607
1825
  emit(event: "end"): boolean;
608
1826
  emit(event: "readable"): boolean;
609
1827
  emit(event: "error", err: Error): boolean;
610
1828
  emit(event: string | symbol, ...args: any[]): boolean;
611
-
612
1829
  on(event: "aborted", listener: (hadError: boolean, code: number) => void): this;
613
1830
  on(event: "close", listener: () => void): this;
614
- on(event: "data", listener: (chunk: Buffer | string) => void): this;
1831
+ on(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this;
615
1832
  on(event: "end", listener: () => void): this;
616
1833
  on(event: "readable", listener: () => void): this;
617
1834
  on(event: "error", listener: (err: Error) => void): this;
618
1835
  on(event: string | symbol, listener: (...args: any[]) => void): this;
619
-
620
1836
  once(event: "aborted", listener: (hadError: boolean, code: number) => void): this;
621
1837
  once(event: "close", listener: () => void): this;
622
- once(event: "data", listener: (chunk: Buffer | string) => void): this;
1838
+ once(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this;
623
1839
  once(event: "end", listener: () => void): this;
624
1840
  once(event: "readable", listener: () => void): this;
625
1841
  once(event: "error", listener: (err: Error) => void): this;
626
1842
  once(event: string | symbol, listener: (...args: any[]) => void): this;
627
-
628
1843
  prependListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this;
629
1844
  prependListener(event: "close", listener: () => void): this;
630
- prependListener(event: "data", listener: (chunk: Buffer | string) => void): this;
1845
+ prependListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this;
631
1846
  prependListener(event: "end", listener: () => void): this;
632
1847
  prependListener(event: "readable", listener: () => void): this;
633
1848
  prependListener(event: "error", listener: (err: Error) => void): this;
634
1849
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
635
-
636
1850
  prependOnceListener(event: "aborted", listener: (hadError: boolean, code: number) => void): this;
637
1851
  prependOnceListener(event: "close", listener: () => void): this;
638
- prependOnceListener(event: "data", listener: (chunk: Buffer | string) => void): this;
1852
+ prependOnceListener(event: "data", listener: (chunk: NonSharedBuffer | string) => void): this;
639
1853
  prependOnceListener(event: "end", listener: () => void): this;
640
1854
  prependOnceListener(event: "readable", listener: () => void): this;
641
1855
  prependOnceListener(event: "error", listener: (err: Error) => void): this;
642
1856
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
643
1857
  }
644
-
645
- export class Http2ServerResponse extends stream.Writable {
1858
+ /**
1859
+ * This object is created internally by an HTTP server, not by the user. It is
1860
+ * passed as the second parameter to the `'request'` event.
1861
+ * @since v8.4.0
1862
+ */
1863
+ export class Http2ServerResponse<Request extends Http2ServerRequest = Http2ServerRequest> extends stream.Writable {
646
1864
  constructor(stream: ServerHttp2Stream);
647
-
1865
+ /**
1866
+ * See `response.socket`.
1867
+ * @since v8.4.0
1868
+ * @deprecated Since v13.0.0 - Use `socket`.
1869
+ */
648
1870
  readonly connection: net.Socket | tls.TLSSocket;
1871
+ /**
1872
+ * Append a single header value to the header object.
1873
+ *
1874
+ * If the value is an array, this is equivalent to calling this method multiple times.
1875
+ *
1876
+ * If there were no previous values for the header, this is equivalent to calling {@link setHeader}.
1877
+ *
1878
+ * Attempting to set a header field name or value that contains invalid characters will result in a
1879
+ * [TypeError](https://nodejs.org/docs/latest-v22.x/api/errors.html#class-typeerror) being thrown.
1880
+ *
1881
+ * ```js
1882
+ * // Returns headers including "set-cookie: a" and "set-cookie: b"
1883
+ * const server = http2.createServer((req, res) => {
1884
+ * res.setHeader('set-cookie', 'a');
1885
+ * res.appendHeader('set-cookie', 'b');
1886
+ * res.writeHead(200);
1887
+ * res.end('ok');
1888
+ * });
1889
+ * ```
1890
+ * @since v20.12.0
1891
+ */
1892
+ appendHeader(name: string, value: string | string[]): void;
1893
+ /**
1894
+ * Boolean value that indicates whether the response has completed. Starts
1895
+ * as `false`. After `response.end()` executes, the value will be `true`.
1896
+ * @since v8.4.0
1897
+ * @deprecated Since v13.4.0,v12.16.0 - Use `writableEnded`.
1898
+ */
649
1899
  readonly finished: boolean;
1900
+ /**
1901
+ * True if headers were sent, false otherwise (read-only).
1902
+ * @since v8.4.0
1903
+ */
650
1904
  readonly headersSent: boolean;
1905
+ /**
1906
+ * A reference to the original HTTP2 `request` object.
1907
+ * @since v15.7.0
1908
+ */
1909
+ readonly req: Request;
1910
+ /**
1911
+ * Returns a `Proxy` object that acts as a `net.Socket` (or `tls.TLSSocket`) but
1912
+ * applies getters, setters, and methods based on HTTP/2 logic.
1913
+ *
1914
+ * `destroyed`, `readable`, and `writable` properties will be retrieved from and
1915
+ * set on `response.stream`.
1916
+ *
1917
+ * `destroy`, `emit`, `end`, `on` and `once` methods will be called on `response.stream`.
1918
+ *
1919
+ * `setTimeout` method will be called on `response.stream.session`.
1920
+ *
1921
+ * `pause`, `read`, `resume`, and `write` will throw an error with code `ERR_HTTP2_NO_SOCKET_MANIPULATION`. See `Http2Session and Sockets` for
1922
+ * more information.
1923
+ *
1924
+ * All other interactions will be routed directly to the socket.
1925
+ *
1926
+ * ```js
1927
+ * import http2 from 'node:http2';
1928
+ * const server = http2.createServer((req, res) => {
1929
+ * const ip = req.socket.remoteAddress;
1930
+ * const port = req.socket.remotePort;
1931
+ * res.end(`Your IP address is ${ip} and your source port is ${port}.`);
1932
+ * }).listen(3000);
1933
+ * ```
1934
+ * @since v8.4.0
1935
+ */
651
1936
  readonly socket: net.Socket | tls.TLSSocket;
1937
+ /**
1938
+ * The `Http2Stream` object backing the response.
1939
+ * @since v8.4.0
1940
+ */
652
1941
  readonly stream: ServerHttp2Stream;
1942
+ /**
1943
+ * When true, the Date header will be automatically generated and sent in
1944
+ * the response if it is not already present in the headers. Defaults to true.
1945
+ *
1946
+ * This should only be disabled for testing; HTTP requires the Date header
1947
+ * in responses.
1948
+ * @since v8.4.0
1949
+ */
653
1950
  sendDate: boolean;
1951
+ /**
1952
+ * When using implicit headers (not calling `response.writeHead()` explicitly),
1953
+ * this property controls the status code that will be sent to the client when
1954
+ * the headers get flushed.
1955
+ *
1956
+ * ```js
1957
+ * response.statusCode = 404;
1958
+ * ```
1959
+ *
1960
+ * After response header was sent to the client, this property indicates the
1961
+ * status code which was sent out.
1962
+ * @since v8.4.0
1963
+ */
654
1964
  statusCode: number;
655
- statusMessage: '';
1965
+ /**
1966
+ * Status message is not supported by HTTP/2 (RFC 7540 8.1.2.4). It returns
1967
+ * an empty string.
1968
+ * @since v8.4.0
1969
+ */
1970
+ statusMessage: "";
1971
+ /**
1972
+ * This method adds HTTP trailing headers (a header but at the end of the
1973
+ * message) to the response.
1974
+ *
1975
+ * Attempting to set a header field name or value that contains invalid characters
1976
+ * will result in a `TypeError` being thrown.
1977
+ * @since v8.4.0
1978
+ */
656
1979
  addTrailers(trailers: OutgoingHttpHeaders): void;
1980
+ /**
1981
+ * This method signals to the server that all of the response headers and body
1982
+ * have been sent; that server should consider this message complete.
1983
+ * The method, `response.end()`, MUST be called on each response.
1984
+ *
1985
+ * If `data` is specified, it is equivalent to calling `response.write(data, encoding)` followed by `response.end(callback)`.
1986
+ *
1987
+ * If `callback` is specified, it will be called when the response stream
1988
+ * is finished.
1989
+ * @since v8.4.0
1990
+ */
657
1991
  end(callback?: () => void): this;
658
1992
  end(data: string | Uint8Array, callback?: () => void): this;
659
- end(data: string | Uint8Array, encoding: string, callback?: () => void): this;
1993
+ end(data: string | Uint8Array, encoding: BufferEncoding, callback?: () => void): this;
1994
+ /**
1995
+ * Reads out a header that has already been queued but not sent to the client.
1996
+ * The name is case-insensitive.
1997
+ *
1998
+ * ```js
1999
+ * const contentType = response.getHeader('content-type');
2000
+ * ```
2001
+ * @since v8.4.0
2002
+ */
660
2003
  getHeader(name: string): string;
2004
+ /**
2005
+ * Returns an array containing the unique names of the current outgoing headers.
2006
+ * All header names are lowercase.
2007
+ *
2008
+ * ```js
2009
+ * response.setHeader('Foo', 'bar');
2010
+ * response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
2011
+ *
2012
+ * const headerNames = response.getHeaderNames();
2013
+ * // headerNames === ['foo', 'set-cookie']
2014
+ * ```
2015
+ * @since v8.4.0
2016
+ */
661
2017
  getHeaderNames(): string[];
2018
+ /**
2019
+ * Returns a shallow copy of the current outgoing headers. Since a shallow copy
2020
+ * is used, array values may be mutated without additional calls to various
2021
+ * header-related http module methods. The keys of the returned object are the
2022
+ * header names and the values are the respective header values. All header names
2023
+ * are lowercase.
2024
+ *
2025
+ * The object returned by the `response.getHeaders()` method _does not_ prototypically inherit from the JavaScript `Object`. This means that typical `Object` methods such as `obj.toString()`,
2026
+ * `obj.hasOwnProperty()`, and others
2027
+ * are not defined and _will not work_.
2028
+ *
2029
+ * ```js
2030
+ * response.setHeader('Foo', 'bar');
2031
+ * response.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);
2032
+ *
2033
+ * const headers = response.getHeaders();
2034
+ * // headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }
2035
+ * ```
2036
+ * @since v8.4.0
2037
+ */
662
2038
  getHeaders(): OutgoingHttpHeaders;
2039
+ /**
2040
+ * Returns `true` if the header identified by `name` is currently set in the
2041
+ * outgoing headers. The header name matching is case-insensitive.
2042
+ *
2043
+ * ```js
2044
+ * const hasContentType = response.hasHeader('content-type');
2045
+ * ```
2046
+ * @since v8.4.0
2047
+ */
663
2048
  hasHeader(name: string): boolean;
2049
+ /**
2050
+ * Removes a header that has been queued for implicit sending.
2051
+ *
2052
+ * ```js
2053
+ * response.removeHeader('Content-Encoding');
2054
+ * ```
2055
+ * @since v8.4.0
2056
+ */
664
2057
  removeHeader(name: string): void;
665
- setHeader(name: string, value: number | string | ReadonlyArray<string>): void;
2058
+ /**
2059
+ * Sets a single header value for implicit headers. If this header already exists
2060
+ * in the to-be-sent headers, its value will be replaced. Use an array of strings
2061
+ * here to send multiple headers with the same name.
2062
+ *
2063
+ * ```js
2064
+ * response.setHeader('Content-Type', 'text/html; charset=utf-8');
2065
+ * ```
2066
+ *
2067
+ * or
2068
+ *
2069
+ * ```js
2070
+ * response.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);
2071
+ * ```
2072
+ *
2073
+ * Attempting to set a header field name or value that contains invalid characters
2074
+ * will result in a `TypeError` being thrown.
2075
+ *
2076
+ * When headers have been set with `response.setHeader()`, they will be merged
2077
+ * with any headers passed to `response.writeHead()`, with the headers passed
2078
+ * to `response.writeHead()` given precedence.
2079
+ *
2080
+ * ```js
2081
+ * // Returns content-type = text/plain
2082
+ * const server = http2.createServer((req, res) => {
2083
+ * res.setHeader('Content-Type', 'text/html; charset=utf-8');
2084
+ * res.setHeader('X-Foo', 'bar');
2085
+ * res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
2086
+ * res.end('ok');
2087
+ * });
2088
+ * ```
2089
+ * @since v8.4.0
2090
+ */
2091
+ setHeader(name: string, value: number | string | readonly string[]): void;
2092
+ /**
2093
+ * Sets the `Http2Stream`'s timeout value to `msecs`. If a callback is
2094
+ * provided, then it is added as a listener on the `'timeout'` event on
2095
+ * the response object.
2096
+ *
2097
+ * If no `'timeout'` listener is added to the request, the response, or
2098
+ * the server, then `Http2Stream` s are destroyed when they time out. If a
2099
+ * handler is assigned to the request, the response, or the server's `'timeout'` events, timed out sockets must be handled explicitly.
2100
+ * @since v8.4.0
2101
+ */
666
2102
  setTimeout(msecs: number, callback?: () => void): void;
2103
+ /**
2104
+ * If this method is called and `response.writeHead()` has not been called,
2105
+ * it will switch to implicit header mode and flush the implicit headers.
2106
+ *
2107
+ * This sends a chunk of the response body. This method may
2108
+ * be called multiple times to provide successive parts of the body.
2109
+ *
2110
+ * In the `node:http` module, the response body is omitted when the
2111
+ * request is a HEAD request. Similarly, the `204` and `304` responses _must not_ include a message body.
2112
+ *
2113
+ * `chunk` can be a string or a buffer. If `chunk` is a string,
2114
+ * the second parameter specifies how to encode it into a byte stream.
2115
+ * By default the `encoding` is `'utf8'`. `callback` will be called when this chunk
2116
+ * of data is flushed.
2117
+ *
2118
+ * This is the raw HTTP body and has nothing to do with higher-level multi-part
2119
+ * body encodings that may be used.
2120
+ *
2121
+ * The first time `response.write()` is called, it will send the buffered
2122
+ * header information and the first chunk of the body to the client. The second
2123
+ * time `response.write()` is called, Node.js assumes data will be streamed,
2124
+ * and sends the new data separately. That is, the response is buffered up to the
2125
+ * first chunk of the body.
2126
+ *
2127
+ * Returns `true` if the entire data was flushed successfully to the kernel
2128
+ * buffer. Returns `false` if all or part of the data was queued in user memory.`'drain'` will be emitted when the buffer is free again.
2129
+ * @since v8.4.0
2130
+ */
667
2131
  write(chunk: string | Uint8Array, callback?: (err: Error) => void): boolean;
668
- write(chunk: string | Uint8Array, encoding: string, callback?: (err: Error) => void): boolean;
2132
+ write(chunk: string | Uint8Array, encoding: BufferEncoding, callback?: (err: Error) => void): boolean;
2133
+ /**
2134
+ * Sends a status `100 Continue` to the client, indicating that the request body
2135
+ * should be sent. See the `'checkContinue'` event on `Http2Server` and `Http2SecureServer`.
2136
+ * @since v8.4.0
2137
+ */
669
2138
  writeContinue(): void;
2139
+ /**
2140
+ * Sends a status `103 Early Hints` to the client with a Link header,
2141
+ * indicating that the user agent can preload/preconnect the linked resources.
2142
+ * The `hints` is an object containing the values of headers to be sent with
2143
+ * early hints message.
2144
+ *
2145
+ * **Example**
2146
+ *
2147
+ * ```js
2148
+ * const earlyHintsLink = '</styles.css>; rel=preload; as=style';
2149
+ * response.writeEarlyHints({
2150
+ * 'link': earlyHintsLink,
2151
+ * });
2152
+ *
2153
+ * const earlyHintsLinks = [
2154
+ * '</styles.css>; rel=preload; as=style',
2155
+ * '</scripts.js>; rel=preload; as=script',
2156
+ * ];
2157
+ * response.writeEarlyHints({
2158
+ * 'link': earlyHintsLinks,
2159
+ * });
2160
+ * ```
2161
+ * @since v18.11.0
2162
+ */
2163
+ writeEarlyHints(hints: Record<string, string | string[]>): void;
2164
+ /**
2165
+ * Sends a response header to the request. The status code is a 3-digit HTTP
2166
+ * status code, like `404`. The last argument, `headers`, are the response headers.
2167
+ *
2168
+ * Returns a reference to the `Http2ServerResponse`, so that calls can be chained.
2169
+ *
2170
+ * For compatibility with `HTTP/1`, a human-readable `statusMessage` may be
2171
+ * passed as the second argument. However, because the `statusMessage` has no
2172
+ * meaning within HTTP/2, the argument will have no effect and a process warning
2173
+ * will be emitted.
2174
+ *
2175
+ * ```js
2176
+ * const body = 'hello world';
2177
+ * response.writeHead(200, {
2178
+ * 'Content-Length': Buffer.byteLength(body),
2179
+ * 'Content-Type': 'text/plain; charset=utf-8',
2180
+ * });
2181
+ * ```
2182
+ *
2183
+ * `Content-Length` is given in bytes not characters. The`Buffer.byteLength()` API may be used to determine the number of bytes in a
2184
+ * given encoding. On outbound messages, Node.js does not check if Content-Length
2185
+ * and the length of the body being transmitted are equal or not. However, when
2186
+ * receiving messages, Node.js will automatically reject messages when the `Content-Length` does not match the actual payload size.
2187
+ *
2188
+ * This method may be called at most one time on a message before `response.end()` is called.
2189
+ *
2190
+ * If `response.write()` or `response.end()` are called before calling
2191
+ * this, the implicit/mutable headers will be calculated and call this function.
2192
+ *
2193
+ * When headers have been set with `response.setHeader()`, they will be merged
2194
+ * with any headers passed to `response.writeHead()`, with the headers passed
2195
+ * to `response.writeHead()` given precedence.
2196
+ *
2197
+ * ```js
2198
+ * // Returns content-type = text/plain
2199
+ * const server = http2.createServer((req, res) => {
2200
+ * res.setHeader('Content-Type', 'text/html; charset=utf-8');
2201
+ * res.setHeader('X-Foo', 'bar');
2202
+ * res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
2203
+ * res.end('ok');
2204
+ * });
2205
+ * ```
2206
+ *
2207
+ * Attempting to set a header field name or value that contains invalid characters
2208
+ * will result in a `TypeError` being thrown.
2209
+ * @since v8.4.0
2210
+ */
670
2211
  writeHead(statusCode: number, headers?: OutgoingHttpHeaders): this;
671
2212
  writeHead(statusCode: number, statusMessage: string, headers?: OutgoingHttpHeaders): this;
672
- createPushResponse(headers: OutgoingHttpHeaders, callback: (err: Error | null, res: Http2ServerResponse) => void): void;
673
-
2213
+ /**
2214
+ * Call `http2stream.pushStream()` with the given headers, and wrap the
2215
+ * given `Http2Stream` on a newly created `Http2ServerResponse` as the callback
2216
+ * parameter if successful. When `Http2ServerRequest` is closed, the callback is
2217
+ * called with an error `ERR_HTTP2_INVALID_STREAM`.
2218
+ * @since v8.4.0
2219
+ * @param headers An object describing the headers
2220
+ * @param callback Called once `http2stream.pushStream()` is finished, or either when the attempt to create the pushed `Http2Stream` has failed or has been rejected, or the state of
2221
+ * `Http2ServerRequest` is closed prior to calling the `http2stream.pushStream()` method
2222
+ */
2223
+ createPushResponse(
2224
+ headers: OutgoingHttpHeaders,
2225
+ callback: (err: Error | null, res: Http2ServerResponse) => void,
2226
+ ): void;
674
2227
  addListener(event: "close", listener: () => void): this;
675
2228
  addListener(event: "drain", listener: () => void): this;
676
2229
  addListener(event: "error", listener: (error: Error) => void): this;
@@ -678,7 +2231,6 @@ declare module 'http2' {
678
2231
  addListener(event: "pipe", listener: (src: stream.Readable) => void): this;
679
2232
  addListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
680
2233
  addListener(event: string | symbol, listener: (...args: any[]) => void): this;
681
-
682
2234
  emit(event: "close"): boolean;
683
2235
  emit(event: "drain"): boolean;
684
2236
  emit(event: "error", error: Error): boolean;
@@ -686,7 +2238,6 @@ declare module 'http2' {
686
2238
  emit(event: "pipe", src: stream.Readable): boolean;
687
2239
  emit(event: "unpipe", src: stream.Readable): boolean;
688
2240
  emit(event: string | symbol, ...args: any[]): boolean;
689
-
690
2241
  on(event: "close", listener: () => void): this;
691
2242
  on(event: "drain", listener: () => void): this;
692
2243
  on(event: "error", listener: (error: Error) => void): this;
@@ -694,7 +2245,6 @@ declare module 'http2' {
694
2245
  on(event: "pipe", listener: (src: stream.Readable) => void): this;
695
2246
  on(event: "unpipe", listener: (src: stream.Readable) => void): this;
696
2247
  on(event: string | symbol, listener: (...args: any[]) => void): this;
697
-
698
2248
  once(event: "close", listener: () => void): this;
699
2249
  once(event: "drain", listener: () => void): this;
700
2250
  once(event: "error", listener: (error: Error) => void): this;
@@ -702,7 +2252,6 @@ declare module 'http2' {
702
2252
  once(event: "pipe", listener: (src: stream.Readable) => void): this;
703
2253
  once(event: "unpipe", listener: (src: stream.Readable) => void): this;
704
2254
  once(event: string | symbol, listener: (...args: any[]) => void): this;
705
-
706
2255
  prependListener(event: "close", listener: () => void): this;
707
2256
  prependListener(event: "drain", listener: () => void): this;
708
2257
  prependListener(event: "error", listener: (error: Error) => void): this;
@@ -710,7 +2259,6 @@ declare module 'http2' {
710
2259
  prependListener(event: "pipe", listener: (src: stream.Readable) => void): this;
711
2260
  prependListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
712
2261
  prependListener(event: string | symbol, listener: (...args: any[]) => void): this;
713
-
714
2262
  prependOnceListener(event: "close", listener: () => void): this;
715
2263
  prependOnceListener(event: "drain", listener: () => void): this;
716
2264
  prependOnceListener(event: "error", listener: (error: Error) => void): this;
@@ -719,9 +2267,6 @@ declare module 'http2' {
719
2267
  prependOnceListener(event: "unpipe", listener: (src: stream.Readable) => void): this;
720
2268
  prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;
721
2269
  }
722
-
723
- // Public API
724
-
725
2270
  export namespace constants {
726
2271
  const NGHTTP2_SESSION_SERVER: number;
727
2272
  const NGHTTP2_SESSION_CLIENT: number;
@@ -780,7 +2325,13 @@ declare module 'http2' {
780
2325
  const HTTP2_HEADER_ACCEPT_LANGUAGE: string;
781
2326
  const HTTP2_HEADER_ACCEPT_RANGES: string;
782
2327
  const HTTP2_HEADER_ACCEPT: string;
2328
+ const HTTP2_HEADER_ACCESS_CONTROL_ALLOW_CREDENTIALS: string;
2329
+ const HTTP2_HEADER_ACCESS_CONTROL_ALLOW_HEADERS: string;
2330
+ const HTTP2_HEADER_ACCESS_CONTROL_ALLOW_METHODS: string;
783
2331
  const HTTP2_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN: string;
2332
+ const HTTP2_HEADER_ACCESS_CONTROL_EXPOSE_HEADERS: string;
2333
+ const HTTP2_HEADER_ACCESS_CONTROL_REQUEST_HEADERS: string;
2334
+ const HTTP2_HEADER_ACCESS_CONTROL_REQUEST_METHOD: string;
784
2335
  const HTTP2_HEADER_AGE: string;
785
2336
  const HTTP2_HEADER_ALLOW: string;
786
2337
  const HTTP2_HEADER_AUTHORIZATION: string;
@@ -932,21 +2483,162 @@ declare module 'http2' {
932
2483
  const HTTP_STATUS_NOT_EXTENDED: number;
933
2484
  const HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED: number;
934
2485
  }
935
-
2486
+ /**
2487
+ * This symbol can be set as a property on the HTTP/2 headers object with
2488
+ * an array value in order to provide a list of headers considered sensitive.
2489
+ */
2490
+ export const sensitiveHeaders: symbol;
2491
+ /**
2492
+ * Returns an object containing the default settings for an `Http2Session` instance. This method returns a new object instance every time it is called
2493
+ * so instances returned may be safely modified for use.
2494
+ * @since v8.4.0
2495
+ */
936
2496
  export function getDefaultSettings(): Settings;
937
- export function getPackedSettings(settings: Settings): Buffer;
2497
+ /**
2498
+ * Returns a `Buffer` instance containing serialized representation of the given
2499
+ * HTTP/2 settings as specified in the [HTTP/2](https://tools.ietf.org/html/rfc7540) specification. This is intended
2500
+ * for use with the `HTTP2-Settings` header field.
2501
+ *
2502
+ * ```js
2503
+ * import http2 from 'node:http2';
2504
+ *
2505
+ * const packed = http2.getPackedSettings({ enablePush: false });
2506
+ *
2507
+ * console.log(packed.toString('base64'));
2508
+ * // Prints: AAIAAAAA
2509
+ * ```
2510
+ * @since v8.4.0
2511
+ */
2512
+ export function getPackedSettings(settings: Settings): NonSharedBuffer;
2513
+ /**
2514
+ * Returns a `HTTP/2 Settings Object` containing the deserialized settings from
2515
+ * the given `Buffer` as generated by `http2.getPackedSettings()`.
2516
+ * @since v8.4.0
2517
+ * @param buf The packed settings.
2518
+ */
938
2519
  export function getUnpackedSettings(buf: Uint8Array): Settings;
939
-
940
- export function createServer(onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void): Http2Server;
941
- export function createServer(options: ServerOptions, onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void): Http2Server;
942
-
943
- export function createSecureServer(onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void): Http2SecureServer;
944
- export function createSecureServer(options: SecureServerOptions, onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void): Http2SecureServer;
945
-
946
- export function connect(authority: string | url.URL, listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void): ClientHttp2Session;
2520
+ /**
2521
+ * Returns a `net.Server` instance that creates and manages `Http2Session` instances.
2522
+ *
2523
+ * Since there are no browsers known that support [unencrypted HTTP/2](https://http2.github.io/faq/#does-http2-require-encryption), the use of {@link createSecureServer} is necessary when
2524
+ * communicating
2525
+ * with browser clients.
2526
+ *
2527
+ * ```js
2528
+ * import http2 from 'node:http2';
2529
+ *
2530
+ * // Create an unencrypted HTTP/2 server.
2531
+ * // Since there are no browsers known that support
2532
+ * // unencrypted HTTP/2, the use of `http2.createSecureServer()`
2533
+ * // is necessary when communicating with browser clients.
2534
+ * const server = http2.createServer();
2535
+ *
2536
+ * server.on('stream', (stream, headers) => {
2537
+ * stream.respond({
2538
+ * 'content-type': 'text/html; charset=utf-8',
2539
+ * ':status': 200,
2540
+ * });
2541
+ * stream.end('<h1>Hello World</h1>');
2542
+ * });
2543
+ *
2544
+ * server.listen(8000);
2545
+ * ```
2546
+ * @since v8.4.0
2547
+ * @param onRequestHandler See `Compatibility API`
2548
+ */
2549
+ export function createServer(
2550
+ onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
2551
+ ): Http2Server;
2552
+ export function createServer<
2553
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
2554
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
2555
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
2556
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
2557
+ >(
2558
+ options: ServerOptions<Http1Request, Http1Response, Http2Request, Http2Response>,
2559
+ onRequestHandler?: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
2560
+ ): Http2Server<Http1Request, Http1Response, Http2Request, Http2Response>;
2561
+ /**
2562
+ * Returns a `tls.Server` instance that creates and manages `Http2Session` instances.
2563
+ *
2564
+ * ```js
2565
+ * import http2 from 'node:http2';
2566
+ * import fs from 'node:fs';
2567
+ *
2568
+ * const options = {
2569
+ * key: fs.readFileSync('server-key.pem'),
2570
+ * cert: fs.readFileSync('server-cert.pem'),
2571
+ * };
2572
+ *
2573
+ * // Create a secure HTTP/2 server
2574
+ * const server = http2.createSecureServer(options);
2575
+ *
2576
+ * server.on('stream', (stream, headers) => {
2577
+ * stream.respond({
2578
+ * 'content-type': 'text/html; charset=utf-8',
2579
+ * ':status': 200,
2580
+ * });
2581
+ * stream.end('<h1>Hello World</h1>');
2582
+ * });
2583
+ *
2584
+ * server.listen(8443);
2585
+ * ```
2586
+ * @since v8.4.0
2587
+ * @param onRequestHandler See `Compatibility API`
2588
+ */
2589
+ export function createSecureServer(
2590
+ onRequestHandler?: (request: Http2ServerRequest, response: Http2ServerResponse) => void,
2591
+ ): Http2SecureServer;
2592
+ export function createSecureServer<
2593
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
2594
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
2595
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
2596
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
2597
+ >(
2598
+ options: SecureServerOptions<Http1Request, Http1Response, Http2Request, Http2Response>,
2599
+ onRequestHandler?: (request: InstanceType<Http2Request>, response: InstanceType<Http2Response>) => void,
2600
+ ): Http2SecureServer<Http1Request, Http1Response, Http2Request, Http2Response>;
2601
+ /**
2602
+ * Returns a `ClientHttp2Session` instance.
2603
+ *
2604
+ * ```js
2605
+ * import http2 from 'node:http2';
2606
+ * const client = http2.connect('https://localhost:1234');
2607
+ *
2608
+ * // Use the client
2609
+ *
2610
+ * client.close();
2611
+ * ```
2612
+ * @since v8.4.0
2613
+ * @param authority The remote HTTP/2 server to connect to. This must be in the form of a minimal, valid URL with the `http://` or `https://` prefix, host name, and IP port (if a non-default port
2614
+ * is used). Userinfo (user ID and password), path, querystring, and fragment details in the URL will be ignored.
2615
+ * @param listener Will be registered as a one-time listener of the {@link 'connect'} event.
2616
+ */
2617
+ export function connect(
2618
+ authority: string | url.URL,
2619
+ listener: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
2620
+ ): ClientHttp2Session;
947
2621
  export function connect(
948
2622
  authority: string | url.URL,
949
2623
  options?: ClientSessionOptions | SecureClientSessionOptions,
950
- listener?: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void
2624
+ listener?: (session: ClientHttp2Session, socket: net.Socket | tls.TLSSocket) => void,
951
2625
  ): ClientHttp2Session;
2626
+ /**
2627
+ * Create an HTTP/2 server session from an existing socket.
2628
+ * @param socket A Duplex Stream
2629
+ * @param options Any `{@link createServer}` options can be provided.
2630
+ * @since v20.12.0
2631
+ */
2632
+ export function performServerHandshake<
2633
+ Http1Request extends typeof IncomingMessage = typeof IncomingMessage,
2634
+ Http1Response extends typeof ServerResponse<InstanceType<Http1Request>> = typeof ServerResponse,
2635
+ Http2Request extends typeof Http2ServerRequest = typeof Http2ServerRequest,
2636
+ Http2Response extends typeof Http2ServerResponse<InstanceType<Http2Request>> = typeof Http2ServerResponse,
2637
+ >(
2638
+ socket: stream.Duplex,
2639
+ options?: ServerOptions<Http1Request, Http1Response, Http2Request, Http2Response>,
2640
+ ): ServerHttp2Session<Http1Request, Http1Response, Http2Request, Http2Response>;
2641
+ }
2642
+ declare module "node:http2" {
2643
+ export * from "http2";
952
2644
  }