@volter/tabnode 0.2.14-volter.88

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 (429) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +78 -0
  3. package/THIRD-PARTY-NOTICES.md +12 -0
  4. package/dist/__sw__.js +526 -0
  5. package/dist/assets/runtime-worker-4MKaHFVb.js +75221 -0
  6. package/dist/assets/runtime-worker-4MKaHFVb.js.map +1 -0
  7. package/dist/code-transforms.d.ts +21 -0
  8. package/dist/code-transforms.d.ts.map +1 -0
  9. package/dist/config/cdn.d.ts +12 -0
  10. package/dist/config/cdn.d.ts.map +1 -0
  11. package/dist/create-runtime.d.ts +22 -0
  12. package/dist/create-runtime.d.ts.map +1 -0
  13. package/dist/host-globals.d.ts +62 -0
  14. package/dist/host-globals.d.ts.map +1 -0
  15. package/dist/index.cjs +36021 -0
  16. package/dist/index.cjs.map +1 -0
  17. package/dist/index.d.ts +127 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.mjs +36020 -0
  20. package/dist/index.mjs.map +1 -0
  21. package/dist/node-internals.d.ts +68 -0
  22. package/dist/node-internals.d.ts.map +1 -0
  23. package/dist/node-lib/binding/blob.d.ts +12 -0
  24. package/dist/node-lib/binding/blob.d.ts.map +1 -0
  25. package/dist/node-lib/binding/buffer.d.ts +144 -0
  26. package/dist/node-lib/binding/buffer.d.ts.map +1 -0
  27. package/dist/node-lib/binding/cares_wrap.d.ts +14 -0
  28. package/dist/node-lib/binding/cares_wrap.d.ts.map +1 -0
  29. package/dist/node-lib/binding/fds.d.ts +30 -0
  30. package/dist/node-lib/binding/fds.d.ts.map +1 -0
  31. package/dist/node-lib/binding/fs.d.ts +157 -0
  32. package/dist/node-lib/binding/fs.d.ts.map +1 -0
  33. package/dist/node-lib/binding/handles.d.ts +81 -0
  34. package/dist/node-lib/binding/handles.d.ts.map +1 -0
  35. package/dist/node-lib/binding/http_parser.d.ts +122 -0
  36. package/dist/node-lib/binding/http_parser.d.ts.map +1 -0
  37. package/dist/node-lib/binding/index.d.ts +3 -0
  38. package/dist/node-lib/binding/index.d.ts.map +1 -0
  39. package/dist/node-lib/binding/llhttp-wasm.d.ts +22 -0
  40. package/dist/node-lib/binding/llhttp-wasm.d.ts.map +1 -0
  41. package/dist/node-lib/binding/misc.d.ts +123 -0
  42. package/dist/node-lib/binding/misc.d.ts.map +1 -0
  43. package/dist/node-lib/binding/pipe_wrap.d.ts +84 -0
  44. package/dist/node-lib/binding/pipe_wrap.d.ts.map +1 -0
  45. package/dist/node-lib/binding/process_wrap.d.ts +173 -0
  46. package/dist/node-lib/binding/process_wrap.d.ts.map +1 -0
  47. package/dist/node-lib/binding/spawn_sync.d.ts +30 -0
  48. package/dist/node-lib/binding/spawn_sync.d.ts.map +1 -0
  49. package/dist/node-lib/binding/stream_wrap.d.ts +191 -0
  50. package/dist/node-lib/binding/stream_wrap.d.ts.map +1 -0
  51. package/dist/node-lib/binding/stubs.d.ts +23 -0
  52. package/dist/node-lib/binding/stubs.d.ts.map +1 -0
  53. package/dist/node-lib/binding/tcp_wrap.d.ts +98 -0
  54. package/dist/node-lib/binding/tcp_wrap.d.ts.map +1 -0
  55. package/dist/node-lib/binding/tty_wrap.d.ts +36 -0
  56. package/dist/node-lib/binding/tty_wrap.d.ts.map +1 -0
  57. package/dist/node-lib/binding/util.d.ts +126 -0
  58. package/dist/node-lib/binding/util.d.ts.map +1 -0
  59. package/dist/node-lib/binding/uv.d.ts +32 -0
  60. package/dist/node-lib/binding/uv.d.ts.map +1 -0
  61. package/dist/node-lib/binding/zlib-pako.d.ts +22 -0
  62. package/dist/node-lib/binding/zlib-pako.d.ts.map +1 -0
  63. package/dist/node-lib/binding/zlib.d.ts +38 -0
  64. package/dist/node-lib/binding/zlib.d.ts.map +1 -0
  65. package/dist/node-lib/buffer-module.d.ts +51 -0
  66. package/dist/node-lib/buffer-module.d.ts.map +1 -0
  67. package/dist/node-lib/child-process-module.d.ts +26 -0
  68. package/dist/node-lib/child-process-module.d.ts.map +1 -0
  69. package/dist/node-lib/events-module.d.ts +58 -0
  70. package/dist/node-lib/events-module.d.ts.map +1 -0
  71. package/dist/node-lib/fs-module.d.ts +5 -0
  72. package/dist/node-lib/fs-module.d.ts.map +1 -0
  73. package/dist/node-lib/http-bridge.d.ts +43 -0
  74. package/dist/node-lib/http-bridge.d.ts.map +1 -0
  75. package/dist/node-lib/http-module.d.ts +35 -0
  76. package/dist/node-lib/http-module.d.ts.map +1 -0
  77. package/dist/node-lib/internals/addresses.d.ts +40 -0
  78. package/dist/node-lib/internals/addresses.d.ts.map +1 -0
  79. package/dist/node-lib/internals/buffer-and-streams.d.ts +96 -0
  80. package/dist/node-lib/internals/buffer-and-streams.d.ts.map +1 -0
  81. package/dist/node-lib/internals/child-process.d.ts +27 -0
  82. package/dist/node-lib/internals/child-process.d.ts.map +1 -0
  83. package/dist/node-lib/internals/events-util.d.ts +83 -0
  84. package/dist/node-lib/internals/events-util.d.ts.map +1 -0
  85. package/dist/node-lib/internals/index.d.ts +2 -0
  86. package/dist/node-lib/internals/index.d.ts.map +1 -0
  87. package/dist/node-lib/internals/modules.d.ts +67 -0
  88. package/dist/node-lib/internals/modules.d.ts.map +1 -0
  89. package/dist/node-lib/internals/readline-access.d.ts +2 -0
  90. package/dist/node-lib/internals/readline-access.d.ts.map +1 -0
  91. package/dist/node-lib/internals/runtime.d.ts +150 -0
  92. package/dist/node-lib/internals/runtime.d.ts.map +1 -0
  93. package/dist/node-lib/internals/util.d.ts +33 -0
  94. package/dist/node-lib/internals/util.d.ts.map +1 -0
  95. package/dist/node-lib/lazy.d.ts +31 -0
  96. package/dist/node-lib/lazy.d.ts.map +1 -0
  97. package/dist/node-lib/load.d.ts +27 -0
  98. package/dist/node-lib/load.d.ts.map +1 -0
  99. package/dist/node-lib/module-hooks.d.ts +89 -0
  100. package/dist/node-lib/module-hooks.d.ts.map +1 -0
  101. package/dist/node-lib/net-module.d.ts +181 -0
  102. package/dist/node-lib/net-module.d.ts.map +1 -0
  103. package/dist/node-lib/node-versions.d.ts +27 -0
  104. package/dist/node-lib/node-versions.d.ts.map +1 -0
  105. package/dist/node-lib/public-modules.d.ts +2 -0
  106. package/dist/node-lib/public-modules.d.ts.map +1 -0
  107. package/dist/node-lib/require-hook.d.ts +15 -0
  108. package/dist/node-lib/require-hook.d.ts.map +1 -0
  109. package/dist/node-lib/small-modules.d.ts +16 -0
  110. package/dist/node-lib/small-modules.d.ts.map +1 -0
  111. package/dist/node-lib/sources.d.ts +4 -0
  112. package/dist/node-lib/sources.d.ts.map +1 -0
  113. package/dist/node-lib/stream-module.d.ts +77 -0
  114. package/dist/node-lib/stream-module.d.ts.map +1 -0
  115. package/dist/node-lib/timers.d.ts +19 -0
  116. package/dist/node-lib/timers.d.ts.map +1 -0
  117. package/dist/node-lib/util-module.d.ts +76 -0
  118. package/dist/node-lib/util-module.d.ts.map +1 -0
  119. package/dist/node-resolution.d.ts +50 -0
  120. package/dist/node-resolution.d.ts.map +1 -0
  121. package/dist/node-resolver.d.ts +7 -0
  122. package/dist/node-resolver.d.ts.map +1 -0
  123. package/dist/npm/index.d.ts +73 -0
  124. package/dist/npm/index.d.ts.map +1 -0
  125. package/dist/npm/registry.d.ts +111 -0
  126. package/dist/npm/registry.d.ts.map +1 -0
  127. package/dist/npm/resolver.d.ts +79 -0
  128. package/dist/npm/resolver.d.ts.map +1 -0
  129. package/dist/npm/tarball.d.ts +28 -0
  130. package/dist/npm/tarball.d.ts.map +1 -0
  131. package/dist/process-tokens.d.ts +77 -0
  132. package/dist/process-tokens.d.ts.map +1 -0
  133. package/dist/punycode-source.d.ts +3 -0
  134. package/dist/punycode-source.d.ts.map +1 -0
  135. package/dist/runtime-interface.d.ts +74 -0
  136. package/dist/runtime-interface.d.ts.map +1 -0
  137. package/dist/runtime.d.ts +144 -0
  138. package/dist/runtime.d.ts.map +1 -0
  139. package/dist/server-bridge.d.ts +147 -0
  140. package/dist/server-bridge.d.ts.map +1 -0
  141. package/dist/shims/async_hooks.d.ts +50 -0
  142. package/dist/shims/async_hooks.d.ts.map +1 -0
  143. package/dist/shims/child_process.d.ts +104 -0
  144. package/dist/shims/child_process.d.ts.map +1 -0
  145. package/dist/shims/cluster.d.ts +52 -0
  146. package/dist/shims/cluster.d.ts.map +1 -0
  147. package/dist/shims/command-line.d.ts +43 -0
  148. package/dist/shims/command-line.d.ts.map +1 -0
  149. package/dist/shims/constants.d.ts +222 -0
  150. package/dist/shims/constants.d.ts.map +1 -0
  151. package/dist/shims/crypto-constants.d.ts +12 -0
  152. package/dist/shims/crypto-constants.d.ts.map +1 -0
  153. package/dist/shims/crypto.d.ts +144 -0
  154. package/dist/shims/crypto.d.ts.map +1 -0
  155. package/dist/shims/dgram.d.ts +34 -0
  156. package/dist/shims/dgram.d.ts.map +1 -0
  157. package/dist/shims/dns.d.ts +91 -0
  158. package/dist/shims/dns.d.ts.map +1 -0
  159. package/dist/shims/domain.d.ts +25 -0
  160. package/dist/shims/domain.d.ts.map +1 -0
  161. package/dist/shims/esbuild.d.ts +205 -0
  162. package/dist/shims/esbuild.d.ts.map +1 -0
  163. package/dist/shims/fs.d.ts +25 -0
  164. package/dist/shims/fs.d.ts.map +1 -0
  165. package/dist/shims/http2.d.ts +81 -0
  166. package/dist/shims/http2.d.ts.map +1 -0
  167. package/dist/shims/inspector.d.ts +25 -0
  168. package/dist/shims/inspector.d.ts.map +1 -0
  169. package/dist/shims/module.d.ts +22 -0
  170. package/dist/shims/module.d.ts.map +1 -0
  171. package/dist/shims/os.d.ts +159 -0
  172. package/dist/shims/os.d.ts.map +1 -0
  173. package/dist/shims/path.d.ts +52 -0
  174. package/dist/shims/path.d.ts.map +1 -0
  175. package/dist/shims/perf_hooks.d.ts +50 -0
  176. package/dist/shims/perf_hooks.d.ts.map +1 -0
  177. package/dist/shims/process.d.ts +226 -0
  178. package/dist/shims/process.d.ts.map +1 -0
  179. package/dist/shims/rollup.d.ts +71 -0
  180. package/dist/shims/rollup.d.ts.map +1 -0
  181. package/dist/shims/string_decoder.d.ts +41 -0
  182. package/dist/shims/string_decoder.d.ts.map +1 -0
  183. package/dist/shims/sync-child.d.ts +64 -0
  184. package/dist/shims/sync-child.d.ts.map +1 -0
  185. package/dist/shims/tls.d.ts +53 -0
  186. package/dist/shims/tls.d.ts.map +1 -0
  187. package/dist/shims/url.d.ts +84 -0
  188. package/dist/shims/url.d.ts.map +1 -0
  189. package/dist/shims/v8.d.ts +73 -0
  190. package/dist/shims/v8.d.ts.map +1 -0
  191. package/dist/shims/vfs-adapter.d.ts +126 -0
  192. package/dist/shims/vfs-adapter.d.ts.map +1 -0
  193. package/dist/shims/vm.d.ts +52 -0
  194. package/dist/shims/vm.d.ts.map +1 -0
  195. package/dist/shims/wasi.d.ts +78 -0
  196. package/dist/shims/wasi.d.ts.map +1 -0
  197. package/dist/shims/worker_threads.d.ts +66 -0
  198. package/dist/shims/worker_threads.d.ts.map +1 -0
  199. package/dist/shims/zlib-constants.d.ts +66 -0
  200. package/dist/shims/zlib-constants.d.ts.map +1 -0
  201. package/dist/shims/zlib.d.ts +102 -0
  202. package/dist/shims/zlib.d.ts.map +1 -0
  203. package/dist/transform.d.ts +24 -0
  204. package/dist/transform.d.ts.map +1 -0
  205. package/dist/types/package-json.d.ts +18 -0
  206. package/dist/types/package-json.d.ts.map +1 -0
  207. package/dist/utils/binary-encoding.d.ts +13 -0
  208. package/dist/utils/binary-encoding.d.ts.map +1 -0
  209. package/dist/utils/glob.d.ts +19 -0
  210. package/dist/utils/glob.d.ts.map +1 -0
  211. package/dist/utils/hash.d.ts +6 -0
  212. package/dist/utils/hash.d.ts.map +1 -0
  213. package/dist/virtual-fs.d.ts +259 -0
  214. package/dist/virtual-fs.d.ts.map +1 -0
  215. package/dist/vite-plugin.cjs +50 -0
  216. package/dist/vite-plugin.cjs.map +1 -0
  217. package/dist/vite-plugin.d.ts +36 -0
  218. package/dist/vite-plugin.d.ts.map +1 -0
  219. package/dist/vite-plugin.mjs +31 -0
  220. package/dist/vite-plugin.mjs.map +1 -0
  221. package/dist/worker/runtime-worker.d.ts +8 -0
  222. package/dist/worker/runtime-worker.d.ts.map +1 -0
  223. package/dist/worker-runtime.d.ts +50 -0
  224. package/dist/worker-runtime.d.ts.map +1 -0
  225. package/package.json +88 -0
  226. package/src/code-transforms.ts +560 -0
  227. package/src/config/cdn.ts +13 -0
  228. package/src/create-runtime.ts +89 -0
  229. package/src/host-globals.ts +121 -0
  230. package/src/index.ts +235 -0
  231. package/src/node-internals.ts +283 -0
  232. package/src/node-lib/LICENSE +47 -0
  233. package/src/node-lib/_http_agent.js +547 -0
  234. package/src/node-lib/_http_client.js +996 -0
  235. package/src/node-lib/_http_common.js +269 -0
  236. package/src/node-lib/_http_incoming.js +453 -0
  237. package/src/node-lib/_http_outgoing.js +1262 -0
  238. package/src/node-lib/_http_server.js +1230 -0
  239. package/src/node-lib/assert/strict.js +3 -0
  240. package/src/node-lib/assert.js +844 -0
  241. package/src/node-lib/binding/blob.ts +35 -0
  242. package/src/node-lib/binding/buffer.ts +465 -0
  243. package/src/node-lib/binding/cares_wrap.ts +57 -0
  244. package/src/node-lib/binding/fds.ts +80 -0
  245. package/src/node-lib/binding/fs.ts +857 -0
  246. package/src/node-lib/binding/handles.ts +187 -0
  247. package/src/node-lib/binding/http_parser.ts +536 -0
  248. package/src/node-lib/binding/index.ts +77 -0
  249. package/src/node-lib/binding/llhttp-wasm.ts +670 -0
  250. package/src/node-lib/binding/misc.ts +252 -0
  251. package/src/node-lib/binding/pipe_wrap.ts +166 -0
  252. package/src/node-lib/binding/process_wrap.ts +371 -0
  253. package/src/node-lib/binding/spawn_sync.ts +141 -0
  254. package/src/node-lib/binding/stream_wrap.ts +413 -0
  255. package/src/node-lib/binding/stubs.ts +19 -0
  256. package/src/node-lib/binding/tcp_wrap.ts +254 -0
  257. package/src/node-lib/binding/tty_wrap.ts +56 -0
  258. package/src/node-lib/binding/util.ts +274 -0
  259. package/src/node-lib/binding/uv.ts +102 -0
  260. package/src/node-lib/binding/zlib-pako.ts +50 -0
  261. package/src/node-lib/binding/zlib.ts +259 -0
  262. package/src/node-lib/buffer-module.ts +70 -0
  263. package/src/node-lib/buffer.js +1373 -0
  264. package/src/node-lib/child-process-module.ts +58 -0
  265. package/src/node-lib/child_process.js +1046 -0
  266. package/src/node-lib/constants.js +41 -0
  267. package/src/node-lib/diagnostics_channel.js +438 -0
  268. package/src/node-lib/events-module.ts +80 -0
  269. package/src/node-lib/events.js +1223 -0
  270. package/src/node-lib/fs-module.ts +43 -0
  271. package/src/node-lib/fs.js +3377 -0
  272. package/src/node-lib/http-bridge.ts +299 -0
  273. package/src/node-lib/http-module.ts +53 -0
  274. package/src/node-lib/http.js +198 -0
  275. package/src/node-lib/https.js +429 -0
  276. package/src/node-lib/internal/assert/assertion_error.js +417 -0
  277. package/src/node-lib/internal/assert/calltracker.js +153 -0
  278. package/src/node-lib/internal/assert/myers_diff.js +177 -0
  279. package/src/node-lib/internal/assert/utils.js +278 -0
  280. package/src/node-lib/internal/buffer.js +1120 -0
  281. package/src/node-lib/internal/child_process/serialization.js +169 -0
  282. package/src/node-lib/internal/child_process.js +1135 -0
  283. package/src/node-lib/internal/constants.js +56 -0
  284. package/src/node-lib/internal/deps/minimatch/index.js +1628 -0
  285. package/src/node-lib/internal/errors.js +1912 -0
  286. package/src/node-lib/internal/events/abort_listener.js +54 -0
  287. package/src/node-lib/internal/events/symbols.js +11 -0
  288. package/src/node-lib/internal/fixed_queue.js +119 -0
  289. package/src/node-lib/internal/freelist.js +30 -0
  290. package/src/node-lib/internal/fs/cp/cp-sync.js +242 -0
  291. package/src/node-lib/internal/fs/cp/cp.js +382 -0
  292. package/src/node-lib/internal/fs/dir.js +369 -0
  293. package/src/node-lib/internal/fs/glob.js +763 -0
  294. package/src/node-lib/internal/fs/promises.js +1312 -0
  295. package/src/node-lib/internal/fs/read/context.js +129 -0
  296. package/src/node-lib/internal/fs/recursive_watch.js +275 -0
  297. package/src/node-lib/internal/fs/rimraf.js +311 -0
  298. package/src/node-lib/internal/fs/streams.js +571 -0
  299. package/src/node-lib/internal/fs/sync_write_stream.js +49 -0
  300. package/src/node-lib/internal/fs/utils.js +987 -0
  301. package/src/node-lib/internal/fs/watchers.js +418 -0
  302. package/src/node-lib/internal/http.js +62 -0
  303. package/src/node-lib/internal/mime.js +389 -0
  304. package/src/node-lib/internal/modules/customization_hooks.js +406 -0
  305. package/src/node-lib/internal/net.js +95 -0
  306. package/src/node-lib/internal/querystring.js +119 -0
  307. package/src/node-lib/internal/readline/callbacks.js +132 -0
  308. package/src/node-lib/internal/readline/emitKeypressEvents.js +99 -0
  309. package/src/node-lib/internal/readline/interface.js +1418 -0
  310. package/src/node-lib/internal/readline/promises.js +144 -0
  311. package/src/node-lib/internal/readline/utils.js +405 -0
  312. package/src/node-lib/internal/socket_list.js +108 -0
  313. package/src/node-lib/internal/stream_base_commons.js +280 -0
  314. package/src/node-lib/internal/streams/add-abort-signal.js +60 -0
  315. package/src/node-lib/internal/streams/compose.js +257 -0
  316. package/src/node-lib/internal/streams/destroy.js +361 -0
  317. package/src/node-lib/internal/streams/duplex.js +203 -0
  318. package/src/node-lib/internal/streams/duplexify.js +379 -0
  319. package/src/node-lib/internal/streams/duplexpair.js +62 -0
  320. package/src/node-lib/internal/streams/end-of-stream.js +331 -0
  321. package/src/node-lib/internal/streams/from.js +208 -0
  322. package/src/node-lib/internal/streams/lazy_transform.js +57 -0
  323. package/src/node-lib/internal/streams/legacy.js +125 -0
  324. package/src/node-lib/internal/streams/operators.js +436 -0
  325. package/src/node-lib/internal/streams/passthrough.js +47 -0
  326. package/src/node-lib/internal/streams/pipeline.js +465 -0
  327. package/src/node-lib/internal/streams/readable.js +1762 -0
  328. package/src/node-lib/internal/streams/state.js +51 -0
  329. package/src/node-lib/internal/streams/transform.js +204 -0
  330. package/src/node-lib/internal/streams/utils.js +363 -0
  331. package/src/node-lib/internal/streams/writable.js +1163 -0
  332. package/src/node-lib/internal/tty.js +260 -0
  333. package/src/node-lib/internal/util/colors.js +40 -0
  334. package/src/node-lib/internal/util/comparisons.js +1028 -0
  335. package/src/node-lib/internal/util/debuglog.js +524 -0
  336. package/src/node-lib/internal/util/inspect.js +2535 -0
  337. package/src/node-lib/internal/util/parse_args/parse_args.js +412 -0
  338. package/src/node-lib/internal/util/parse_args/utils.js +197 -0
  339. package/src/node-lib/internal/util.js +1003 -0
  340. package/src/node-lib/internal/validators.js +654 -0
  341. package/src/node-lib/internals/addresses.ts +159 -0
  342. package/src/node-lib/internals/buffer-and-streams.ts +224 -0
  343. package/src/node-lib/internals/child-process.ts +64 -0
  344. package/src/node-lib/internals/events-util.ts +105 -0
  345. package/src/node-lib/internals/index.ts +66 -0
  346. package/src/node-lib/internals/modules.ts +117 -0
  347. package/src/node-lib/internals/readline-access.ts +16 -0
  348. package/src/node-lib/internals/runtime.ts +277 -0
  349. package/src/node-lib/internals/util.ts +98 -0
  350. package/src/node-lib/lazy.ts +158 -0
  351. package/src/node-lib/load.ts +390 -0
  352. package/src/node-lib/module-hooks.ts +281 -0
  353. package/src/node-lib/net-module.ts +248 -0
  354. package/src/node-lib/net.js +2540 -0
  355. package/src/node-lib/node-versions.ts +34 -0
  356. package/src/node-lib/os.js +356 -0
  357. package/src/node-lib/path.js +1694 -0
  358. package/src/node-lib/primordials.js +743 -0
  359. package/src/node-lib/public-modules.ts +109 -0
  360. package/src/node-lib/punycode.js +455 -0
  361. package/src/node-lib/querystring.js +484 -0
  362. package/src/node-lib/readline/promises.js +73 -0
  363. package/src/node-lib/readline.js +523 -0
  364. package/src/node-lib/require-hook.ts +27 -0
  365. package/src/node-lib/small-modules.ts +35 -0
  366. package/src/node-lib/sources.ts +200 -0
  367. package/src/node-lib/stream/promises.js +44 -0
  368. package/src/node-lib/stream-module.ts +101 -0
  369. package/src/node-lib/stream.js +152 -0
  370. package/src/node-lib/timers.ts +33 -0
  371. package/src/node-lib/tty.js +168 -0
  372. package/src/node-lib/util-module.ts +104 -0
  373. package/src/node-lib/util.js +689 -0
  374. package/src/node-lib/wasi.js +179 -0
  375. package/src/node-lib/zlib.js +1036 -0
  376. package/src/node-resolution.ts +241 -0
  377. package/src/node-resolver.ts +33 -0
  378. package/src/npm/index.ts +425 -0
  379. package/src/npm/registry.ts +235 -0
  380. package/src/npm/resolver.ts +589 -0
  381. package/src/npm/tarball.ts +246 -0
  382. package/src/process-tokens.ts +156 -0
  383. package/src/punycode-source.ts +6 -0
  384. package/src/runtime-interface.ts +85 -0
  385. package/src/runtime.ts +3073 -0
  386. package/src/server-bridge.ts +971 -0
  387. package/src/shims/async_hooks.ts +181 -0
  388. package/src/shims/child_process.ts +1591 -0
  389. package/src/shims/cluster.ts +79 -0
  390. package/src/shims/command-line.ts +79 -0
  391. package/src/shims/constants.ts +68 -0
  392. package/src/shims/crypto-constants.ts +11 -0
  393. package/src/shims/crypto.ts +1061 -0
  394. package/src/shims/dgram.ts +47 -0
  395. package/src/shims/dns.ts +185 -0
  396. package/src/shims/domain.ts +58 -0
  397. package/src/shims/esbuild.ts +1638 -0
  398. package/src/shims/fs.ts +82 -0
  399. package/src/shims/http2.ts +96 -0
  400. package/src/shims/inspector.ts +30 -0
  401. package/src/shims/module.ts +86 -0
  402. package/src/shims/os.ts +195 -0
  403. package/src/shims/path.ts +246 -0
  404. package/src/shims/perf_hooks.ts +92 -0
  405. package/src/shims/process.ts +804 -0
  406. package/src/shims/rollup.ts +149 -0
  407. package/src/shims/string_decoder.ts +396 -0
  408. package/src/shims/sync-child.ts +469 -0
  409. package/src/shims/tls.ts +94 -0
  410. package/src/shims/url.ts +217 -0
  411. package/src/shims/v8.ts +113 -0
  412. package/src/shims/vfs-adapter.ts +408 -0
  413. package/src/shims/vm.ts +132 -0
  414. package/src/shims/wasi.ts +1440 -0
  415. package/src/shims/worker_threads.ts +114 -0
  416. package/src/shims/zlib-constants.ts +65 -0
  417. package/src/shims/zlib.ts +228 -0
  418. package/src/transform.ts +324 -0
  419. package/src/types/external.d.ts +55 -0
  420. package/src/types/package-json.ts +17 -0
  421. package/src/types/pako-zlib.d.ts +30 -0
  422. package/src/types/sha.js.d.ts +14 -0
  423. package/src/utils/binary-encoding.ts +43 -0
  424. package/src/utils/glob.ts +54 -0
  425. package/src/utils/hash.ts +12 -0
  426. package/src/virtual-fs.ts +1048 -0
  427. package/src/vite-plugin.ts +76 -0
  428. package/src/worker/runtime-worker.ts +128 -0
  429. package/src/worker-runtime.ts +145 -0
@@ -0,0 +1,1230 @@
1
+ // Copyright Joyent, Inc. and other Node contributors.
2
+ //
3
+ // Permission is hereby granted, free of charge, to any person obtaining a
4
+ // copy of this software and associated documentation files (the
5
+ // "Software"), to deal in the Software without restriction, including
6
+ // without limitation the rights to use, copy, modify, merge, publish,
7
+ // distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ // persons to whom the Software is furnished to do so, subject to the
9
+ // following conditions:
10
+ //
11
+ // The above copyright notice and this permission notice shall be included
12
+ // in all copies or substantial portions of the Software.
13
+ //
14
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
17
+ // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18
+ // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
+ // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
+ // USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+ 'use strict';
23
+
24
+ const {
25
+ ArrayIsArray,
26
+ Error,
27
+ MathMin,
28
+ ObjectKeys,
29
+ ObjectSetPrototypeOf,
30
+ ReflectApply,
31
+ Symbol,
32
+ SymbolFor,
33
+ } = primordials;
34
+
35
+ const net = require('net');
36
+ const EE = require('events');
37
+ const assert = require('internal/assert');
38
+ const {
39
+ parsers,
40
+ freeParser,
41
+ continueExpression,
42
+ chunkExpression,
43
+ kIncomingMessage,
44
+ HTTPParser,
45
+ isLenient,
46
+ _checkInvalidHeaderChar: checkInvalidHeaderChar,
47
+ prepareError,
48
+ } = require('_http_common');
49
+ const { ConnectionsList } = internalBinding('http_parser');
50
+ const {
51
+ kUniqueHeaders,
52
+ parseUniqueHeadersOption,
53
+ OutgoingMessage,
54
+ } = require('_http_outgoing');
55
+ const {
56
+ kOutHeaders,
57
+ kNeedDrain,
58
+ isTraceHTTPEnabled,
59
+ traceBegin,
60
+ traceEnd,
61
+ getNextTraceEventId,
62
+ } = require('internal/http');
63
+ const {
64
+ defaultTriggerAsyncIdScope,
65
+ getOrSetAsyncId,
66
+ } = require('internal/async_hooks');
67
+ const { IncomingMessage } = require('_http_incoming');
68
+ const {
69
+ ConnResetException,
70
+ codes: {
71
+ ERR_HTTP_HEADERS_SENT,
72
+ ERR_HTTP_INVALID_STATUS_CODE,
73
+ ERR_HTTP_REQUEST_TIMEOUT,
74
+ ERR_HTTP_SOCKET_ASSIGNED,
75
+ ERR_HTTP_SOCKET_ENCODING,
76
+ ERR_INVALID_ARG_VALUE,
77
+ ERR_INVALID_CHAR,
78
+ ERR_OUT_OF_RANGE,
79
+ },
80
+ } = require('internal/errors');
81
+ const {
82
+ assignFunctionName,
83
+ kEmptyObject,
84
+ promisify,
85
+ SymbolAsyncDispose,
86
+ } = require('internal/util');
87
+ const {
88
+ validateInteger,
89
+ validateBoolean,
90
+ validateLinkHeaderValue,
91
+ validateObject,
92
+ } = require('internal/validators');
93
+ const Buffer = require('buffer').Buffer;
94
+ const { setInterval, clearInterval } = require('timers');
95
+ let debug = require('internal/util/debuglog').debuglog('http', (fn) => {
96
+ debug = fn;
97
+ });
98
+
99
+ const dc = require('diagnostics_channel');
100
+ const onRequestStartChannel = dc.channel('http.server.request.start');
101
+ const onResponseCreatedChannel = dc.channel('http.server.response.created');
102
+ const onResponseFinishChannel = dc.channel('http.server.response.finish');
103
+
104
+ const kServerResponse = Symbol('ServerResponse');
105
+ const kServerResponseStatistics = Symbol('ServerResponseStatistics');
106
+
107
+ const {
108
+ hasObserver,
109
+ startPerf,
110
+ stopPerf,
111
+ } = require('internal/perf/observe');
112
+
113
+ const STATUS_CODES = {
114
+ 100: 'Continue', // RFC 7231 6.2.1
115
+ 101: 'Switching Protocols', // RFC 7231 6.2.2
116
+ 102: 'Processing', // RFC 2518 10.1 (obsoleted by RFC 4918)
117
+ 103: 'Early Hints', // RFC 8297 2
118
+ 200: 'OK', // RFC 7231 6.3.1
119
+ 201: 'Created', // RFC 7231 6.3.2
120
+ 202: 'Accepted', // RFC 7231 6.3.3
121
+ 203: 'Non-Authoritative Information', // RFC 7231 6.3.4
122
+ 204: 'No Content', // RFC 7231 6.3.5
123
+ 205: 'Reset Content', // RFC 7231 6.3.6
124
+ 206: 'Partial Content', // RFC 7233 4.1
125
+ 207: 'Multi-Status', // RFC 4918 11.1
126
+ 208: 'Already Reported', // RFC 5842 7.1
127
+ 226: 'IM Used', // RFC 3229 10.4.1
128
+ 300: 'Multiple Choices', // RFC 7231 6.4.1
129
+ 301: 'Moved Permanently', // RFC 7231 6.4.2
130
+ 302: 'Found', // RFC 7231 6.4.3
131
+ 303: 'See Other', // RFC 7231 6.4.4
132
+ 304: 'Not Modified', // RFC 7232 4.1
133
+ 305: 'Use Proxy', // RFC 7231 6.4.5
134
+ 307: 'Temporary Redirect', // RFC 7231 6.4.7
135
+ 308: 'Permanent Redirect', // RFC 7238 3
136
+ 400: 'Bad Request', // RFC 7231 6.5.1
137
+ 401: 'Unauthorized', // RFC 7235 3.1
138
+ 402: 'Payment Required', // RFC 7231 6.5.2
139
+ 403: 'Forbidden', // RFC 7231 6.5.3
140
+ 404: 'Not Found', // RFC 7231 6.5.4
141
+ 405: 'Method Not Allowed', // RFC 7231 6.5.5
142
+ 406: 'Not Acceptable', // RFC 7231 6.5.6
143
+ 407: 'Proxy Authentication Required', // RFC 7235 3.2
144
+ 408: 'Request Timeout', // RFC 7231 6.5.7
145
+ 409: 'Conflict', // RFC 7231 6.5.8
146
+ 410: 'Gone', // RFC 7231 6.5.9
147
+ 411: 'Length Required', // RFC 7231 6.5.10
148
+ 412: 'Precondition Failed', // RFC 7232 4.2
149
+ 413: 'Payload Too Large', // RFC 7231 6.5.11
150
+ 414: 'URI Too Long', // RFC 7231 6.5.12
151
+ 415: 'Unsupported Media Type', // RFC 7231 6.5.13
152
+ 416: 'Range Not Satisfiable', // RFC 7233 4.4
153
+ 417: 'Expectation Failed', // RFC 7231 6.5.14
154
+ 418: 'I\'m a Teapot', // RFC 7168 2.3.3
155
+ 421: 'Misdirected Request', // RFC 7540 9.1.2
156
+ 422: 'Unprocessable Entity', // RFC 4918 11.2
157
+ 423: 'Locked', // RFC 4918 11.3
158
+ 424: 'Failed Dependency', // RFC 4918 11.4
159
+ 425: 'Too Early', // RFC 8470 5.2
160
+ 426: 'Upgrade Required', // RFC 2817 and RFC 7231 6.5.15
161
+ 428: 'Precondition Required', // RFC 6585 3
162
+ 429: 'Too Many Requests', // RFC 6585 4
163
+ 431: 'Request Header Fields Too Large', // RFC 6585 5
164
+ 451: 'Unavailable For Legal Reasons', // RFC 7725 3
165
+ 500: 'Internal Server Error', // RFC 7231 6.6.1
166
+ 501: 'Not Implemented', // RFC 7231 6.6.2
167
+ 502: 'Bad Gateway', // RFC 7231 6.6.3
168
+ 503: 'Service Unavailable', // RFC 7231 6.6.4
169
+ 504: 'Gateway Timeout', // RFC 7231 6.6.5
170
+ 505: 'HTTP Version Not Supported', // RFC 7231 6.6.6
171
+ 506: 'Variant Also Negotiates', // RFC 2295 8.1
172
+ 507: 'Insufficient Storage', // RFC 4918 11.5
173
+ 508: 'Loop Detected', // RFC 5842 7.2
174
+ 509: 'Bandwidth Limit Exceeded',
175
+ 510: 'Not Extended', // RFC 2774 7
176
+ 511: 'Network Authentication Required', // RFC 6585 6
177
+ };
178
+
179
+ const kOnExecute = HTTPParser.kOnExecute | 0;
180
+ const kOnTimeout = HTTPParser.kOnTimeout | 0;
181
+ const kLenientAll = HTTPParser.kLenientAll | 0;
182
+ const kLenientNone = HTTPParser.kLenientNone | 0;
183
+ const kConnections = Symbol('http.server.connections');
184
+ const kConnectionsCheckingInterval = Symbol('http.server.connectionsCheckingInterval');
185
+
186
+ const HTTP_SERVER_TRACE_EVENT_NAME = 'http.server.request';
187
+ // TODO(jazelly): make this configurable
188
+ const HTTP_SERVER_KEEP_ALIVE_TIMEOUT_BUFFER = 1000;
189
+
190
+ class HTTPServerAsyncResource {
191
+ constructor(type, socket) {
192
+ this.type = type;
193
+ this.socket = socket;
194
+ }
195
+ }
196
+
197
+ function ServerResponse(req, options) {
198
+ OutgoingMessage.call(this, options);
199
+
200
+ if (req.method === 'HEAD') this._hasBody = false;
201
+
202
+ this.req = req;
203
+ this.sendDate = true;
204
+ this._sent100 = false;
205
+ this._expect_continue = false;
206
+
207
+ if (req.httpVersionMajor < 1 || req.httpVersionMinor < 1) {
208
+ this.useChunkedEncodingByDefault = chunkExpression.test(req.headers.te);
209
+ this.shouldKeepAlive = false;
210
+ }
211
+
212
+ if (hasObserver('http')) {
213
+ startPerf(this, kServerResponseStatistics, {
214
+ type: 'http',
215
+ name: 'HttpRequest',
216
+ detail: {
217
+ req: {
218
+ method: req.method,
219
+ url: req.url,
220
+ headers: req.headers,
221
+ },
222
+ },
223
+ });
224
+ }
225
+ if (isTraceHTTPEnabled()) {
226
+ this._traceEventId = getNextTraceEventId();
227
+ traceBegin(HTTP_SERVER_TRACE_EVENT_NAME, this._traceEventId);
228
+ }
229
+ if (onResponseCreatedChannel.hasSubscribers) {
230
+ onResponseCreatedChannel.publish({
231
+ request: req,
232
+ response: this,
233
+ });
234
+ }
235
+ }
236
+ ObjectSetPrototypeOf(ServerResponse.prototype, OutgoingMessage.prototype);
237
+ ObjectSetPrototypeOf(ServerResponse, OutgoingMessage);
238
+
239
+ ServerResponse.prototype._finish = function _finish() {
240
+ if (this[kServerResponseStatistics] && hasObserver('http')) {
241
+ stopPerf(this, kServerResponseStatistics, {
242
+ detail: {
243
+ res: {
244
+ statusCode: this.statusCode,
245
+ statusMessage: this.statusMessage,
246
+ headers: typeof this.getHeaders === 'function' ? this.getHeaders() : {},
247
+ },
248
+ },
249
+ });
250
+ }
251
+ OutgoingMessage.prototype._finish.call(this);
252
+ if (isTraceHTTPEnabled() && typeof this._traceEventId === 'number') {
253
+ const data = {
254
+ url: this.req?.url,
255
+ statusCode: this.statusCode,
256
+ };
257
+ traceEnd(HTTP_SERVER_TRACE_EVENT_NAME, this._traceEventId, data);
258
+ }
259
+ };
260
+
261
+
262
+ ServerResponse.prototype.statusCode = 200;
263
+ ServerResponse.prototype.statusMessage = undefined;
264
+
265
+ function onServerResponseClose() {
266
+ // EventEmitter.emit makes a copy of the 'close' listeners array before
267
+ // calling the listeners. detachSocket() unregisters onServerResponseClose
268
+ // but if detachSocket() is called, directly or indirectly, by a 'close'
269
+ // listener, onServerResponseClose is still in that copy of the listeners
270
+ // array. That is, in the example below, b still gets called even though
271
+ // it's been removed by a:
272
+ //
273
+ // const EventEmitter = require('events');
274
+ // const obj = new EventEmitter();
275
+ // obj.on('event', a);
276
+ // obj.on('event', b);
277
+ // function a() { obj.removeListener('event', b) }
278
+ // function b() { throw "BAM!" }
279
+ // obj.emit('event'); // throws
280
+ //
281
+ // Ergo, we need to deal with stale 'close' events and handle the case
282
+ // where the ServerResponse object has already been deconstructed.
283
+ // Fortunately, that requires only a single if check. :-)
284
+ if (this._httpMessage) {
285
+ emitCloseNT(this._httpMessage);
286
+ }
287
+ }
288
+
289
+ ServerResponse.prototype.assignSocket = function assignSocket(socket) {
290
+ if (socket._httpMessage) {
291
+ throw new ERR_HTTP_SOCKET_ASSIGNED();
292
+ }
293
+ socket._httpMessage = this;
294
+ socket.on('close', onServerResponseClose);
295
+ this.socket = socket;
296
+ this.emit('socket', socket);
297
+ this._flush();
298
+ };
299
+
300
+ ServerResponse.prototype.detachSocket = function detachSocket(socket) {
301
+ assert(socket._httpMessage === this);
302
+ socket.removeListener('close', onServerResponseClose);
303
+ socket._httpMessage = null;
304
+ this.socket = null;
305
+ };
306
+
307
+ ServerResponse.prototype.writeContinue = function writeContinue(cb) {
308
+ this._writeRaw('HTTP/1.1 100 Continue\r\n\r\n', 'ascii', cb);
309
+ this._sent100 = true;
310
+ };
311
+
312
+ ServerResponse.prototype.writeProcessing = function writeProcessing(cb) {
313
+ this._writeRaw('HTTP/1.1 102 Processing\r\n\r\n', 'ascii', cb);
314
+ };
315
+
316
+ ServerResponse.prototype.writeEarlyHints = function writeEarlyHints(hints, cb) {
317
+ let head = 'HTTP/1.1 103 Early Hints\r\n';
318
+
319
+ validateObject(hints, 'hints');
320
+
321
+ if (hints.link === null || hints.link === undefined) {
322
+ return;
323
+ }
324
+
325
+ const link = validateLinkHeaderValue(hints.link);
326
+
327
+ if (link.length === 0) {
328
+ return;
329
+ }
330
+
331
+ head += 'Link: ' + link + '\r\n';
332
+
333
+ for (const key of ObjectKeys(hints)) {
334
+ if (key !== 'link') {
335
+ head += key + ': ' + hints[key] + '\r\n';
336
+ }
337
+ }
338
+
339
+ head += '\r\n';
340
+
341
+ this._writeRaw(head, 'ascii', cb);
342
+ };
343
+
344
+ ServerResponse.prototype._implicitHeader = function _implicitHeader() {
345
+ this.writeHead(this.statusCode);
346
+ };
347
+
348
+ ServerResponse.prototype.writeHead = writeHead;
349
+ function writeHead(statusCode, reason, obj) {
350
+
351
+ if (this._header) {
352
+ throw new ERR_HTTP_HEADERS_SENT('write');
353
+ }
354
+
355
+ const originalStatusCode = statusCode;
356
+
357
+ statusCode |= 0;
358
+ if (statusCode < 100 || statusCode > 999) {
359
+ throw new ERR_HTTP_INVALID_STATUS_CODE(originalStatusCode);
360
+ }
361
+
362
+
363
+ if (typeof reason === 'string') {
364
+ // writeHead(statusCode, reasonPhrase[, headers])
365
+ this.statusMessage = reason;
366
+ } else {
367
+ // writeHead(statusCode[, headers])
368
+ this.statusMessage ||= STATUS_CODES[statusCode] || 'unknown';
369
+ obj ??= reason;
370
+ }
371
+ this.statusCode = statusCode;
372
+
373
+ let headers;
374
+ if (this[kOutHeaders]) {
375
+ // Slow-case: when progressive API and header fields are passed.
376
+ let k;
377
+ if (ArrayIsArray(obj)) {
378
+ if (obj.length % 2 !== 0) {
379
+ throw new ERR_INVALID_ARG_VALUE('headers', obj);
380
+ }
381
+
382
+ // Headers in obj should override previous headers but still
383
+ // allow explicit duplicates. To do so, we first remove any
384
+ // existing conflicts, then use appendHeader.
385
+
386
+ for (let n = 0; n < obj.length; n += 2) {
387
+ k = obj[n + 0];
388
+ this.removeHeader(k);
389
+ }
390
+
391
+ for (let n = 0; n < obj.length; n += 2) {
392
+ k = obj[n + 0];
393
+ if (k) this.appendHeader(k, obj[n + 1]);
394
+ }
395
+ } else if (obj) {
396
+ const keys = ObjectKeys(obj);
397
+ // Retain for(;;) loop for performance reasons
398
+ // Refs: https://github.com/nodejs/node/pull/30958
399
+ for (let i = 0; i < keys.length; i++) {
400
+ k = keys[i];
401
+ if (k) this.setHeader(k, obj[k]);
402
+ }
403
+ }
404
+ // Only progressive api is used
405
+ headers = this[kOutHeaders];
406
+ } else {
407
+ // Only writeHead() called
408
+ headers = obj;
409
+ }
410
+
411
+ if (checkInvalidHeaderChar(this.statusMessage))
412
+ throw new ERR_INVALID_CHAR('statusMessage');
413
+
414
+ const statusLine = `HTTP/1.1 ${statusCode} ${this.statusMessage}\r\n`;
415
+
416
+ if (statusCode === 204 || statusCode === 304 ||
417
+ (statusCode >= 100 && statusCode <= 199)) {
418
+ // RFC 2616, 10.2.5:
419
+ // The 204 response MUST NOT include a message-body, and thus is always
420
+ // terminated by the first empty line after the header fields.
421
+ // RFC 2616, 10.3.5:
422
+ // The 304 response MUST NOT contain a message-body, and thus is always
423
+ // terminated by the first empty line after the header fields.
424
+ // RFC 2616, 10.1 Informational 1xx:
425
+ // This class of status code indicates a provisional response,
426
+ // consisting only of the Status-Line and optional headers, and is
427
+ // terminated by an empty line.
428
+ this._hasBody = false;
429
+ }
430
+
431
+ // Don't keep alive connections where the client expects 100 Continue
432
+ // but we sent a final status; they may put extra bytes on the wire.
433
+ if (this._expect_continue && !this._sent100) {
434
+ this.shouldKeepAlive = false;
435
+ }
436
+
437
+ this._storeHeader(statusLine, headers);
438
+
439
+ return this;
440
+ }
441
+
442
+ // Docs-only deprecated: DEP0063
443
+ ServerResponse.prototype.writeHeader = ServerResponse.prototype.writeHead;
444
+
445
+ function storeHTTPOptions(options) {
446
+ this[kIncomingMessage] = options.IncomingMessage || IncomingMessage;
447
+ this[kServerResponse] = options.ServerResponse || ServerResponse;
448
+
449
+ const maxHeaderSize = options.maxHeaderSize;
450
+ if (maxHeaderSize !== undefined)
451
+ validateInteger(maxHeaderSize, 'maxHeaderSize', 0);
452
+ this.maxHeaderSize = maxHeaderSize;
453
+
454
+ const insecureHTTPParser = options.insecureHTTPParser;
455
+ if (insecureHTTPParser !== undefined)
456
+ validateBoolean(insecureHTTPParser, 'options.insecureHTTPParser');
457
+ this.insecureHTTPParser = insecureHTTPParser;
458
+
459
+ const requestTimeout = options.requestTimeout;
460
+ if (requestTimeout !== undefined) {
461
+ validateInteger(requestTimeout, 'requestTimeout', 0);
462
+ this.requestTimeout = requestTimeout;
463
+ } else {
464
+ this.requestTimeout = 300_000; // 5 minutes
465
+ }
466
+
467
+ const headersTimeout = options.headersTimeout;
468
+ if (headersTimeout !== undefined) {
469
+ validateInteger(headersTimeout, 'headersTimeout', 0);
470
+ this.headersTimeout = headersTimeout;
471
+ } else {
472
+ this.headersTimeout = MathMin(60_000, this.requestTimeout); // Minimum between 60 seconds or requestTimeout
473
+ }
474
+
475
+ if (this.requestTimeout > 0 && this.headersTimeout > 0 && this.headersTimeout > this.requestTimeout) {
476
+ throw new ERR_OUT_OF_RANGE('headersTimeout', '<= requestTimeout', headersTimeout);
477
+ }
478
+
479
+ const keepAliveTimeout = options.keepAliveTimeout;
480
+ if (keepAliveTimeout !== undefined) {
481
+ validateInteger(keepAliveTimeout, 'keepAliveTimeout', 0);
482
+ this.keepAliveTimeout = keepAliveTimeout;
483
+ } else {
484
+ this.keepAliveTimeout = 5_000; // 5 seconds;
485
+ }
486
+
487
+ const connectionsCheckingInterval = options.connectionsCheckingInterval;
488
+ if (connectionsCheckingInterval !== undefined) {
489
+ validateInteger(connectionsCheckingInterval, 'connectionsCheckingInterval', 0);
490
+ this.connectionsCheckingInterval = connectionsCheckingInterval;
491
+ } else {
492
+ this.connectionsCheckingInterval = 30_000; // 30 seconds
493
+ }
494
+
495
+ const requireHostHeader = options.requireHostHeader;
496
+ if (requireHostHeader !== undefined) {
497
+ validateBoolean(requireHostHeader, 'options.requireHostHeader');
498
+ this.requireHostHeader = requireHostHeader;
499
+ } else {
500
+ this.requireHostHeader = true;
501
+ }
502
+
503
+ const joinDuplicateHeaders = options.joinDuplicateHeaders;
504
+ if (joinDuplicateHeaders !== undefined) {
505
+ validateBoolean(joinDuplicateHeaders, 'options.joinDuplicateHeaders');
506
+ }
507
+ this.joinDuplicateHeaders = joinDuplicateHeaders;
508
+
509
+ const rejectNonStandardBodyWrites = options.rejectNonStandardBodyWrites;
510
+ if (rejectNonStandardBodyWrites !== undefined) {
511
+ validateBoolean(rejectNonStandardBodyWrites, 'options.rejectNonStandardBodyWrites');
512
+ this.rejectNonStandardBodyWrites = rejectNonStandardBodyWrites;
513
+ } else {
514
+ this.rejectNonStandardBodyWrites = false;
515
+ }
516
+ }
517
+
518
+ function setupConnectionsTracking() {
519
+ // Start connection handling
520
+ this[kConnections] ||= new ConnectionsList();
521
+
522
+ if (this[kConnectionsCheckingInterval]) {
523
+ clearInterval(this[kConnectionsCheckingInterval]);
524
+ }
525
+ // This checker is started without checking whether any headersTimeout or requestTimeout is non zero
526
+ // otherwise it would not be started if such timeouts are modified after createServer.
527
+ this[kConnectionsCheckingInterval] =
528
+ setInterval(checkConnections.bind(this), this.connectionsCheckingInterval).unref();
529
+ }
530
+
531
+ function httpServerPreClose(server) {
532
+ server.closeIdleConnections();
533
+ clearInterval(server[kConnectionsCheckingInterval]);
534
+ }
535
+
536
+ function Server(options, requestListener) {
537
+ if (!(this instanceof Server)) return new Server(options, requestListener);
538
+
539
+ if (typeof options === 'function') {
540
+ requestListener = options;
541
+ options = kEmptyObject;
542
+ } else if (options == null) {
543
+ options = kEmptyObject;
544
+ } else {
545
+ validateObject(options, 'options');
546
+ }
547
+
548
+ storeHTTPOptions.call(this, options);
549
+ net.Server.call(
550
+ this,
551
+ { allowHalfOpen: true, noDelay: options.noDelay ?? true,
552
+ keepAlive: options.keepAlive,
553
+ keepAliveInitialDelay: options.keepAliveInitialDelay,
554
+ highWaterMark: options.highWaterMark });
555
+
556
+ if (requestListener) {
557
+ this.on('request', requestListener);
558
+ }
559
+
560
+ // Similar option to this. Too lazy to write my own docs.
561
+ // http://www.squid-cache.org/Doc/config/half_closed_clients/
562
+ // https://wiki.squid-cache.org/SquidFaq/InnerWorkings#What_is_a_half-closed_filedescriptor.3F
563
+ this.httpAllowHalfOpen = false;
564
+
565
+ this.on('connection', connectionListener);
566
+ this.on('listening', setupConnectionsTracking);
567
+
568
+ this.timeout = 0;
569
+ this.maxHeadersCount = null;
570
+ this.maxRequestsPerSocket = 0;
571
+
572
+ this[kUniqueHeaders] = parseUniqueHeadersOption(options.uniqueHeaders);
573
+ }
574
+ ObjectSetPrototypeOf(Server.prototype, net.Server.prototype);
575
+ ObjectSetPrototypeOf(Server, net.Server);
576
+
577
+ Server.prototype.close = function close() {
578
+ httpServerPreClose(this);
579
+ ReflectApply(net.Server.prototype.close, this, arguments);
580
+ return this;
581
+ };
582
+
583
+ Server.prototype[SymbolAsyncDispose] = assignFunctionName(SymbolAsyncDispose, async function() {
584
+ await promisify(this.close).call(this);
585
+ });
586
+
587
+ Server.prototype.closeAllConnections = function closeAllConnections() {
588
+ if (!this[kConnections]) {
589
+ return;
590
+ }
591
+
592
+ const connections = this[kConnections].all();
593
+
594
+ for (let i = 0, l = connections.length; i < l; i++) {
595
+ connections[i].socket.destroy();
596
+ }
597
+ };
598
+
599
+ Server.prototype.closeIdleConnections = function closeIdleConnections() {
600
+ if (!this[kConnections]) {
601
+ return;
602
+ }
603
+
604
+ const connections = this[kConnections].idle();
605
+
606
+ for (let i = 0, l = connections.length; i < l; i++) {
607
+ if (connections[i].socket._httpMessage && !connections[i].socket._httpMessage.finished) {
608
+ continue;
609
+ }
610
+
611
+ connections[i].socket.destroy();
612
+ }
613
+ };
614
+
615
+ Server.prototype.setTimeout = function setTimeout(msecs, callback) {
616
+ this.timeout = msecs;
617
+ if (callback)
618
+ this.on('timeout', callback);
619
+ return this;
620
+ };
621
+
622
+ Server.prototype[EE.captureRejectionSymbol] =
623
+ assignFunctionName(EE.captureRejectionSymbol, function(err, event, ...args) {
624
+ switch (event) {
625
+ case 'request': {
626
+ const { 1: res } = args;
627
+ if (!res.headersSent && !res.writableEnded) {
628
+ // Don't leak headers.
629
+ const names = res.getHeaderNames();
630
+ for (let i = 0; i < names.length; i++) {
631
+ res.removeHeader(names[i]);
632
+ }
633
+ res.statusCode = 500;
634
+ res.end(STATUS_CODES[500]);
635
+ } else {
636
+ res.destroy();
637
+ }
638
+ break;
639
+ }
640
+ default:
641
+ net.Server.prototype[SymbolFor('nodejs.rejection')]
642
+ .apply(this, arguments);
643
+ }
644
+ });
645
+
646
+ function checkConnections() {
647
+ if (this.headersTimeout === 0 && this.requestTimeout === 0) {
648
+ return;
649
+ }
650
+
651
+ const expired = this[kConnections].expired(this.headersTimeout, this.requestTimeout);
652
+
653
+ for (let i = 0; i < expired.length; i++) {
654
+ const socket = expired[i].socket;
655
+
656
+ if (socket) {
657
+ onRequestTimeout(socket);
658
+ }
659
+ }
660
+ }
661
+
662
+ function connectionListener(socket) {
663
+ defaultTriggerAsyncIdScope(
664
+ getOrSetAsyncId(socket), connectionListenerInternal, this, socket,
665
+ );
666
+ }
667
+
668
+ function connectionListenerInternal(server, socket) {
669
+ debug('SERVER new http connection');
670
+
671
+ // Ensure that the server property of the socket is correctly set.
672
+ // See https://github.com/nodejs/node/issues/13435
673
+ socket.server = server;
674
+
675
+ // If the user has added a listener to the server,
676
+ // request, or response, then it's their responsibility.
677
+ // otherwise, destroy on timeout by default
678
+ if (server.timeout && typeof socket.setTimeout === 'function')
679
+ socket.setTimeout(server.timeout);
680
+ socket.on('timeout', socketOnTimeout);
681
+
682
+ const parser = parsers.alloc();
683
+
684
+ const lenient = server.insecureHTTPParser === undefined ?
685
+ isLenient() : server.insecureHTTPParser;
686
+
687
+ // TODO(addaleax): This doesn't play well with the
688
+ // `async_hooks.currentResource()` proposal, see
689
+ // https://github.com/nodejs/node/pull/21313
690
+ parser.initialize(
691
+ HTTPParser.REQUEST,
692
+ new HTTPServerAsyncResource('HTTPINCOMINGMESSAGE', socket),
693
+ server.maxHeaderSize || 0,
694
+ lenient ? kLenientAll : kLenientNone,
695
+ server[kConnections],
696
+ );
697
+ parser.socket = socket;
698
+ socket.parser = parser;
699
+
700
+ // Propagate headers limit from server instance to parser
701
+ if (typeof server.maxHeadersCount === 'number') {
702
+ parser.maxHeaderPairs = server.maxHeadersCount << 1;
703
+ }
704
+
705
+ const state = {
706
+ onData: null,
707
+ onEnd: null,
708
+ onClose: null,
709
+ onDrain: null,
710
+ outgoing: [],
711
+ incoming: [],
712
+ // `outgoingData` is an approximate amount of bytes queued through all
713
+ // inactive responses. If more data than the high watermark is queued - we
714
+ // need to pause TCP socket/HTTP parser, and wait until the data will be
715
+ // sent to the client.
716
+ outgoingData: 0,
717
+ requestsCount: 0,
718
+ keepAliveTimeoutSet: false,
719
+ };
720
+ state.onData = socketOnData.bind(undefined,
721
+ server, socket, parser, state);
722
+ state.onEnd = socketOnEnd.bind(undefined,
723
+ server, socket, parser, state);
724
+ state.onClose = socketOnClose.bind(undefined,
725
+ socket, state);
726
+ state.onDrain = socketOnDrain.bind(undefined,
727
+ socket, state);
728
+ socket.on('data', state.onData);
729
+ socket.on('error', socketOnError);
730
+ socket.on('end', state.onEnd);
731
+ socket.on('close', state.onClose);
732
+ socket.on('drain', state.onDrain);
733
+ parser.onIncoming = parserOnIncoming.bind(undefined,
734
+ server, socket, state);
735
+
736
+ // We are consuming socket, so it won't get any actual data
737
+ socket.on('resume', onSocketResume);
738
+ socket.on('pause', onSocketPause);
739
+
740
+ // Overrides to unconsume on `data`, `readable` listeners
741
+ socket.on = generateSocketListenerWrapper('on');
742
+ socket.addListener = generateSocketListenerWrapper('addListener');
743
+ socket.prependListener = generateSocketListenerWrapper('prependListener');
744
+ socket.setEncoding = socketSetEncoding;
745
+
746
+ // We only consume the socket if it has never been consumed before.
747
+ if (socket._handle?.isStreamBase &&
748
+ !socket._handle._consumed) {
749
+ parser._consumed = true;
750
+ socket._handle._consumed = true;
751
+ parser.consume(socket._handle);
752
+ }
753
+ parser[kOnExecute] =
754
+ onParserExecute.bind(undefined,
755
+ server, socket, parser, state);
756
+
757
+ parser[kOnTimeout] =
758
+ onParserTimeout.bind(undefined,
759
+ server, socket);
760
+
761
+ socket._paused = false;
762
+ }
763
+
764
+ function socketSetEncoding() {
765
+ throw new ERR_HTTP_SOCKET_ENCODING();
766
+ }
767
+
768
+ function updateOutgoingData(socket, state, delta) {
769
+ state.outgoingData += delta;
770
+ socketOnDrain(socket, state);
771
+ }
772
+
773
+ function socketOnDrain(socket, state) {
774
+ const needPause = state.outgoingData > socket.writableHighWaterMark;
775
+
776
+ // If we previously paused, then start reading again.
777
+ if (socket._paused && !needPause) {
778
+ socket._paused = false;
779
+ if (socket.parser)
780
+ socket.parser.resume();
781
+ socket.resume();
782
+ }
783
+
784
+ const msg = socket._httpMessage;
785
+ if (msg && !msg.finished && msg[kNeedDrain]) {
786
+ msg[kNeedDrain] = false;
787
+ msg.emit('drain');
788
+ }
789
+ }
790
+
791
+ function socketOnTimeout() {
792
+ const req = this.parser?.incoming;
793
+ const reqTimeout = req && !req.complete && req.emit('timeout', this);
794
+ const res = this._httpMessage;
795
+ const resTimeout = res && res.emit('timeout', this);
796
+ const serverTimeout = this.server.emit('timeout', this);
797
+
798
+ if (!reqTimeout && !resTimeout && !serverTimeout)
799
+ this.destroy();
800
+ }
801
+
802
+ function socketOnClose(socket, state) {
803
+ debug('server socket close');
804
+ freeParser(socket.parser, null, socket);
805
+ abortIncoming(state.incoming);
806
+ }
807
+
808
+ function abortIncoming(incoming) {
809
+ while (incoming.length) {
810
+ const req = incoming.shift();
811
+ req.destroy(new ConnResetException('aborted'));
812
+ }
813
+ // Abort socket._httpMessage ?
814
+ }
815
+
816
+ function socketOnEnd(server, socket, parser, state) {
817
+ const ret = parser.finish();
818
+
819
+ if (ret instanceof Error) {
820
+ debug('parse error');
821
+ // socketOnError has additional logic and will call socket.destroy(err).
822
+ socketOnError.call(socket, ret);
823
+ } else if (!server.httpAllowHalfOpen) {
824
+ socket.end();
825
+ } else if (state.outgoing.length) {
826
+ state.outgoing[state.outgoing.length - 1]._last = true;
827
+ } else if (socket._httpMessage) {
828
+ socket._httpMessage._last = true;
829
+ } else {
830
+ socket.end();
831
+ }
832
+ }
833
+
834
+ function socketOnData(server, socket, parser, state, d) {
835
+ assert(!socket._paused);
836
+ debug('SERVER socketOnData %d', d.length);
837
+
838
+ const ret = parser.execute(d);
839
+ onParserExecuteCommon(server, socket, parser, state, ret, d);
840
+ }
841
+
842
+ function onRequestTimeout(socket) {
843
+ // socketOnError has additional logic and will call socket.destroy(err).
844
+ socketOnError.call(socket, new ERR_HTTP_REQUEST_TIMEOUT());
845
+ }
846
+
847
+ function onParserExecute(server, socket, parser, state, ret) {
848
+ // When underlying `net.Socket` instance is consumed - no
849
+ // `data` events are emitted, and thus `socket.setTimeout` fires the
850
+ // callback even if the data is constantly flowing into the socket.
851
+ // See, https://github.com/nodejs/node/commit/ec2822adaad76b126b5cccdeaa1addf2376c9aa6
852
+ socket._unrefTimer();
853
+ debug('SERVER socketOnParserExecute %d', ret);
854
+ onParserExecuteCommon(server, socket, parser, state, ret, undefined);
855
+ }
856
+
857
+ function onParserTimeout(server, socket) {
858
+ const serverTimeout = server.emit('timeout', socket);
859
+
860
+ if (!serverTimeout)
861
+ socket.destroy();
862
+ }
863
+
864
+ const noop = () => {};
865
+ const badRequestResponse = Buffer.from(
866
+ `HTTP/1.1 400 ${STATUS_CODES[400]}\r\n` +
867
+ 'Connection: close\r\n\r\n', 'ascii',
868
+ );
869
+ const requestTimeoutResponse = Buffer.from(
870
+ `HTTP/1.1 408 ${STATUS_CODES[408]}\r\n` +
871
+ 'Connection: close\r\n\r\n', 'ascii',
872
+ );
873
+ const requestHeaderFieldsTooLargeResponse = Buffer.from(
874
+ `HTTP/1.1 431 ${STATUS_CODES[431]}\r\n` +
875
+ 'Connection: close\r\n\r\n', 'ascii',
876
+ );
877
+
878
+ const requestChunkExtensionsTooLargeResponse = Buffer.from(
879
+ `HTTP/1.1 413 ${STATUS_CODES[413]}\r\n` +
880
+ 'Connection: close\r\n\r\n', 'ascii',
881
+ );
882
+
883
+ function socketOnError(e) {
884
+ // Ignore further errors
885
+ this.removeListener('error', socketOnError);
886
+
887
+ if (this.listenerCount('error', noop) === 0) {
888
+ this.on('error', noop);
889
+ }
890
+
891
+ if (!this.server.emit('clientError', e, this)) {
892
+ // Caution must be taken to avoid corrupting the remote peer.
893
+ // Reply an error segment if there is no in-flight `ServerResponse`,
894
+ // or no data of the in-flight one has been written yet to this socket.
895
+ if (this.writable &&
896
+ (!this._httpMessage || !this._httpMessage._headerSent)) {
897
+ let response;
898
+
899
+ switch (e.code) {
900
+ case 'HPE_HEADER_OVERFLOW':
901
+ response = requestHeaderFieldsTooLargeResponse;
902
+ break;
903
+ case 'HPE_CHUNK_EXTENSIONS_OVERFLOW':
904
+ response = requestChunkExtensionsTooLargeResponse;
905
+ break;
906
+ case 'ERR_HTTP_REQUEST_TIMEOUT':
907
+ response = requestTimeoutResponse;
908
+ break;
909
+ default:
910
+ response = badRequestResponse;
911
+ break;
912
+ }
913
+
914
+ this.write(response);
915
+ }
916
+ this.destroy(e);
917
+ }
918
+ }
919
+
920
+ function onParserExecuteCommon(server, socket, parser, state, ret, d) {
921
+ if (ret instanceof Error) {
922
+ prepareError(ret, parser, d);
923
+ debug('parse error', ret);
924
+ socketOnError.call(socket, ret);
925
+ } else if (parser.incoming?.upgrade) {
926
+ // Upgrade or CONNECT
927
+ const req = parser.incoming;
928
+ debug('SERVER upgrade or connect', req.method);
929
+
930
+ d ||= parser.getCurrentBuffer();
931
+
932
+ socket.removeListener('data', state.onData);
933
+ socket.removeListener('end', state.onEnd);
934
+ socket.removeListener('close', state.onClose);
935
+ socket.removeListener('drain', state.onDrain);
936
+ socket.removeListener('error', socketOnError);
937
+ socket.removeListener('timeout', socketOnTimeout);
938
+ unconsume(parser, socket);
939
+ parser.finish();
940
+ freeParser(parser, req, socket);
941
+ parser = null;
942
+
943
+ const eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
944
+ if (eventName === 'upgrade' || server.listenerCount(eventName) > 0) {
945
+ debug('SERVER have listener for %s', eventName);
946
+ const bodyHead = d.slice(ret, d.length);
947
+
948
+ socket.readableFlowing = null;
949
+
950
+ server.emit(eventName, req, socket, bodyHead);
951
+ } else {
952
+ // Got CONNECT method, but have no handler.
953
+ socket.destroy();
954
+ }
955
+ } else if (parser.incoming && parser.incoming.method === 'PRI') {
956
+ debug('SERVER got PRI request');
957
+ socket.destroy();
958
+ }
959
+
960
+ if (socket._paused && socket.parser) {
961
+ // onIncoming paused the socket, we should pause the parser as well
962
+ debug('pause parser');
963
+ socket.parser.pause();
964
+ }
965
+ }
966
+
967
+ function clearIncoming(req) {
968
+ req ||= this;
969
+ const parser = req.socket?.parser;
970
+ // Reset the .incoming property so that the request object can be gc'ed.
971
+ if (parser && parser.incoming === req) {
972
+ if (req.readableEnded) {
973
+ parser.incoming = null;
974
+ } else {
975
+ req.on('end', clearIncoming);
976
+ }
977
+ }
978
+ }
979
+
980
+ function resOnFinish(req, res, socket, state, server) {
981
+ if (onResponseFinishChannel.hasSubscribers) {
982
+ onResponseFinishChannel.publish({
983
+ request: req,
984
+ response: res,
985
+ socket,
986
+ server,
987
+ });
988
+ }
989
+
990
+ // Usually the first incoming element should be our request. it may
991
+ // be that in the case abortIncoming() was called that the incoming
992
+ // array will be empty.
993
+ assert(state.incoming.length === 0 || state.incoming[0] === req);
994
+
995
+ state.incoming.shift();
996
+
997
+ // If the user never called req.read(), and didn't pipe() or
998
+ // .resume() or .on('data'), then we call req._dump() so that the
999
+ // bytes will be pulled off the wire.
1000
+ if (!req._consuming && !req._readableState.resumeScheduled)
1001
+ req._dump();
1002
+
1003
+ res.detachSocket(socket);
1004
+ clearIncoming(req);
1005
+ process.nextTick(emitCloseNT, res);
1006
+
1007
+ if (res._last) {
1008
+ if (typeof socket.destroySoon === 'function') {
1009
+ socket.destroySoon();
1010
+ } else {
1011
+ socket.end();
1012
+ }
1013
+ } else if (state.outgoing.length === 0) {
1014
+ if (server.keepAliveTimeout && typeof socket.setTimeout === 'function') {
1015
+ // Increase the internal timeout wrt the advertised value to reduce
1016
+ // the likelihood of ECONNRESET errors.
1017
+ socket.setTimeout(server.keepAliveTimeout + HTTP_SERVER_KEEP_ALIVE_TIMEOUT_BUFFER);
1018
+ state.keepAliveTimeoutSet = true;
1019
+ }
1020
+ } else {
1021
+ // Start sending the next message
1022
+ const m = state.outgoing.shift();
1023
+ if (m) {
1024
+ m.assignSocket(socket);
1025
+ }
1026
+ }
1027
+ }
1028
+
1029
+ function emitCloseNT(self) {
1030
+ if (!self._closed) {
1031
+ self.destroyed = true;
1032
+ self._closed = true;
1033
+ self.emit('close');
1034
+ }
1035
+ }
1036
+
1037
+ // The following callback is issued after the headers have been read on a
1038
+ // new message. In this callback we setup the response object and pass it
1039
+ // to the user.
1040
+ function parserOnIncoming(server, socket, state, req, keepAlive) {
1041
+ resetSocketTimeout(server, socket, state);
1042
+
1043
+ if (req.upgrade) {
1044
+ req.upgrade = req.method === 'CONNECT' ||
1045
+ server.listenerCount('upgrade') > 0;
1046
+ if (req.upgrade)
1047
+ return 2;
1048
+ }
1049
+
1050
+ state.incoming.push(req);
1051
+
1052
+ // If the writable end isn't consuming, then stop reading
1053
+ // so that we don't become overwhelmed by a flood of
1054
+ // pipelined requests that may never be resolved.
1055
+ if (!socket._paused) {
1056
+ const ws = socket._writableState;
1057
+ if (ws.needDrain || state.outgoingData >= socket.writableHighWaterMark) {
1058
+ socket._paused = true;
1059
+ // We also need to pause the parser, but don't do that until after
1060
+ // the call to execute, because we may still be processing the last
1061
+ // chunk.
1062
+ socket.pause();
1063
+ }
1064
+ }
1065
+
1066
+ const res = new server[kServerResponse](req,
1067
+ {
1068
+ highWaterMark: socket.writableHighWaterMark,
1069
+ rejectNonStandardBodyWrites: server.rejectNonStandardBodyWrites,
1070
+ });
1071
+ res._keepAliveTimeout = server.keepAliveTimeout;
1072
+ res._maxRequestsPerSocket = server.maxRequestsPerSocket;
1073
+ res._onPendingData = updateOutgoingData.bind(undefined,
1074
+ socket, state);
1075
+
1076
+ res.shouldKeepAlive = keepAlive;
1077
+ res[kUniqueHeaders] = server[kUniqueHeaders];
1078
+
1079
+ if (onRequestStartChannel.hasSubscribers) {
1080
+ onRequestStartChannel.publish({
1081
+ request: req,
1082
+ response: res,
1083
+ socket,
1084
+ server,
1085
+ });
1086
+ }
1087
+
1088
+ if (socket._httpMessage) {
1089
+ // There are already pending outgoing res, append.
1090
+ state.outgoing.push(res);
1091
+ } else {
1092
+ res.assignSocket(socket);
1093
+ }
1094
+
1095
+ // When we're finished writing the response, check if this is the last
1096
+ // response, if so destroy the socket.
1097
+ res.on('finish',
1098
+ resOnFinish.bind(undefined,
1099
+ req, res, socket, state, server));
1100
+
1101
+ let handled = false;
1102
+
1103
+
1104
+ if (req.httpVersionMajor === 1 && req.httpVersionMinor === 1) {
1105
+
1106
+ // From RFC 7230 5.4 https://datatracker.ietf.org/doc/html/rfc7230#section-5.4
1107
+ // A server MUST respond with a 400 (Bad Request) status code to any
1108
+ // HTTP/1.1 request message that lacks a Host header field
1109
+ if (server.requireHostHeader && req.headers.host === undefined) {
1110
+ res.writeHead(400, ['Connection', 'close']);
1111
+ res.end();
1112
+ return 0;
1113
+ }
1114
+
1115
+ const isRequestsLimitSet = (
1116
+ typeof server.maxRequestsPerSocket === 'number' &&
1117
+ server.maxRequestsPerSocket > 0
1118
+ );
1119
+
1120
+ if (isRequestsLimitSet) {
1121
+ state.requestsCount++;
1122
+ res.maxRequestsOnConnectionReached = (
1123
+ server.maxRequestsPerSocket <= state.requestsCount);
1124
+ }
1125
+
1126
+ if (isRequestsLimitSet &&
1127
+ (server.maxRequestsPerSocket < state.requestsCount)) {
1128
+ handled = true;
1129
+ server.emit('dropRequest', req, socket);
1130
+ res.writeHead(503);
1131
+ res.end();
1132
+ } else if (req.headers.expect !== undefined) {
1133
+ handled = true;
1134
+
1135
+ if (continueExpression.test(req.headers.expect)) {
1136
+ res._expect_continue = true;
1137
+ if (server.listenerCount('checkContinue') > 0) {
1138
+ server.emit('checkContinue', req, res);
1139
+ } else {
1140
+ res.writeContinue();
1141
+ server.emit('request', req, res);
1142
+ }
1143
+ } else if (server.listenerCount('checkExpectation') > 0) {
1144
+ server.emit('checkExpectation', req, res);
1145
+ } else {
1146
+ res.writeHead(417);
1147
+ res.end();
1148
+ }
1149
+ }
1150
+ }
1151
+
1152
+ if (!handled) {
1153
+ server.emit('request', req, res);
1154
+ }
1155
+
1156
+ return 0; // No special treatment.
1157
+ }
1158
+
1159
+ function resetSocketTimeout(server, socket, state) {
1160
+ if (!state.keepAliveTimeoutSet)
1161
+ return;
1162
+
1163
+ socket.setTimeout(server.timeout || 0);
1164
+ state.keepAliveTimeoutSet = false;
1165
+ }
1166
+
1167
+ function onSocketResume() {
1168
+ // It may seem that the socket is resumed, but this is an enemy's trick to
1169
+ // deceive us! `resume` is emitted asynchronously, and may be called from
1170
+ // `incoming.readStart()`. Stop the socket again here, just to preserve the
1171
+ // state.
1172
+ //
1173
+ // We don't care about stream semantics for the consumed socket anyway.
1174
+ if (this._paused) {
1175
+ this.pause();
1176
+ return;
1177
+ }
1178
+
1179
+ if (this._handle && !this._handle.reading) {
1180
+ this._handle.reading = true;
1181
+ this._handle.readStart();
1182
+ }
1183
+ }
1184
+
1185
+ function onSocketPause() {
1186
+ if (this._handle?.reading) {
1187
+ this._handle.reading = false;
1188
+ this._handle.readStop();
1189
+ }
1190
+ }
1191
+
1192
+ function unconsume(parser, socket) {
1193
+ if (socket._handle) {
1194
+ if (parser._consumed)
1195
+ parser.unconsume();
1196
+ parser._consumed = false;
1197
+ socket.removeListener('pause', onSocketPause);
1198
+ socket.removeListener('resume', onSocketResume);
1199
+ }
1200
+ }
1201
+
1202
+ function generateSocketListenerWrapper(originalFnName) {
1203
+ return function socketListenerWrap(ev, fn) {
1204
+ const res = net.Socket.prototype[originalFnName].call(this,
1205
+ ev, fn);
1206
+ if (!this.parser) {
1207
+ this.on = net.Socket.prototype.on;
1208
+ this.addListener = net.Socket.prototype.addListener;
1209
+ this.prependListener = net.Socket.prototype.prependListener;
1210
+ return res;
1211
+ }
1212
+
1213
+ if (ev === 'data' || ev === 'readable')
1214
+ unconsume(this.parser, this);
1215
+
1216
+ return res;
1217
+ };
1218
+ }
1219
+
1220
+ module.exports = {
1221
+ STATUS_CODES,
1222
+ Server,
1223
+ ServerResponse,
1224
+ setupConnectionsTracking,
1225
+ storeHTTPOptions,
1226
+ _connectionListener: connectionListener,
1227
+ kServerResponse,
1228
+ httpServerPreClose,
1229
+ kConnectionsCheckingInterval,
1230
+ };