@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,996 @@
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
+ Boolean,
27
+ Error,
28
+ NumberIsFinite,
29
+ ObjectAssign,
30
+ ObjectKeys,
31
+ ObjectSetPrototypeOf,
32
+ ReflectApply,
33
+ String,
34
+ Symbol,
35
+ } = primordials;
36
+
37
+ const net = require('net');
38
+ const assert = require('internal/assert');
39
+ const {
40
+ kEmptyObject,
41
+ once,
42
+ } = require('internal/util');
43
+ const {
44
+ _checkIsHttpToken: checkIsHttpToken,
45
+ freeParser,
46
+ parsers,
47
+ HTTPParser,
48
+ isLenient,
49
+ prepareError,
50
+ } = require('_http_common');
51
+ const {
52
+ kUniqueHeaders,
53
+ parseUniqueHeadersOption,
54
+ OutgoingMessage,
55
+ } = require('_http_outgoing');
56
+ const Agent = require('_http_agent');
57
+ const { Buffer } = require('buffer');
58
+ const { defaultTriggerAsyncIdScope } = require('internal/async_hooks');
59
+ const { URL, urlToHttpOptions, isURL } = require('internal/url');
60
+ const {
61
+ kOutHeaders,
62
+ kNeedDrain,
63
+ isTraceHTTPEnabled,
64
+ traceBegin,
65
+ traceEnd,
66
+ getNextTraceEventId,
67
+ } = require('internal/http');
68
+ const {
69
+ ConnResetException,
70
+ codes: {
71
+ ERR_HTTP_HEADERS_SENT,
72
+ ERR_INVALID_ARG_TYPE,
73
+ ERR_INVALID_HTTP_TOKEN,
74
+ ERR_INVALID_PROTOCOL,
75
+ ERR_UNESCAPED_CHARACTERS,
76
+ },
77
+ } = require('internal/errors');
78
+ const {
79
+ validateInteger,
80
+ validateBoolean,
81
+ } = require('internal/validators');
82
+ const { getTimerDuration } = require('internal/timers');
83
+ const {
84
+ hasObserver,
85
+ startPerf,
86
+ stopPerf,
87
+ } = require('internal/perf/observe');
88
+
89
+ const kClientRequestStatistics = Symbol('ClientRequestStatistics');
90
+
91
+ const dc = require('diagnostics_channel');
92
+ const onClientRequestCreatedChannel = dc.channel('http.client.request.created');
93
+ const onClientRequestStartChannel = dc.channel('http.client.request.start');
94
+ const onClientRequestErrorChannel = dc.channel('http.client.request.error');
95
+ const onClientResponseFinishChannel = dc.channel('http.client.response.finish');
96
+
97
+ function emitErrorEvent(request, error) {
98
+ if (onClientRequestErrorChannel.hasSubscribers) {
99
+ onClientRequestErrorChannel.publish({
100
+ request,
101
+ error,
102
+ });
103
+ }
104
+ request.emit('error', error);
105
+ }
106
+
107
+ const { addAbortSignal, finished } = require('stream');
108
+
109
+ let debug = require('internal/util/debuglog').debuglog('http', (fn) => {
110
+ debug = fn;
111
+ });
112
+
113
+ const INVALID_PATH_REGEX = /[^\u0021-\u00ff]/;
114
+ const kError = Symbol('kError');
115
+
116
+ const kLenientAll = HTTPParser.kLenientAll | 0;
117
+ const kLenientNone = HTTPParser.kLenientNone | 0;
118
+
119
+ const HTTP_CLIENT_TRACE_EVENT_NAME = 'http.client.request';
120
+
121
+ function validateHost(host, name) {
122
+ if (host !== null && host !== undefined && typeof host !== 'string') {
123
+ throw new ERR_INVALID_ARG_TYPE(`options.${name}`,
124
+ ['string', 'undefined', 'null'],
125
+ host);
126
+ }
127
+ return host;
128
+ }
129
+
130
+ class HTTPClientAsyncResource {
131
+ constructor(type, req) {
132
+ this.type = type;
133
+ this.req = req;
134
+ }
135
+ }
136
+
137
+ function ClientRequest(input, options, cb) {
138
+ OutgoingMessage.call(this);
139
+
140
+ if (typeof input === 'string') {
141
+ const urlStr = input;
142
+ input = urlToHttpOptions(new URL(urlStr));
143
+ } else if (isURL(input)) {
144
+ // url.URL instance
145
+ input = urlToHttpOptions(input);
146
+ } else {
147
+ cb = options;
148
+ options = input;
149
+ input = null;
150
+ }
151
+
152
+ if (typeof options === 'function') {
153
+ cb = options;
154
+ options = input || kEmptyObject;
155
+ } else {
156
+ options = ObjectAssign(input || {}, options);
157
+ }
158
+
159
+ let agent = options.agent;
160
+ const defaultAgent = options._defaultAgent || Agent.globalAgent;
161
+ if (agent === false) {
162
+ agent = new defaultAgent.constructor();
163
+ } else if (agent === null || agent === undefined) {
164
+ if (typeof options.createConnection !== 'function') {
165
+ agent = defaultAgent;
166
+ }
167
+ // Explicitly pass through this statement as agent will not be used
168
+ // when createConnection is provided.
169
+ } else if (typeof agent.addRequest !== 'function') {
170
+ throw new ERR_INVALID_ARG_TYPE('options.agent',
171
+ ['Agent-like Object', 'undefined', 'false'],
172
+ agent);
173
+ }
174
+ this.agent = agent;
175
+
176
+ const protocol = options.protocol || defaultAgent.protocol;
177
+ let expectedProtocol = defaultAgent.protocol;
178
+ if (this.agent?.protocol)
179
+ expectedProtocol = this.agent.protocol;
180
+
181
+ if (options.path) {
182
+ const path = String(options.path);
183
+ if (INVALID_PATH_REGEX.test(path)) {
184
+ debug('Path contains unescaped characters: "%s"', path);
185
+ throw new ERR_UNESCAPED_CHARACTERS('Request path');
186
+ }
187
+ }
188
+
189
+ if (protocol !== expectedProtocol) {
190
+ throw new ERR_INVALID_PROTOCOL(protocol, expectedProtocol);
191
+ }
192
+
193
+ const defaultPort = options.defaultPort ||
194
+ (this.agent?.defaultPort);
195
+
196
+ const optsWithoutSignal = { __proto__: null, ...options };
197
+
198
+ const port = optsWithoutSignal.port = options.port || defaultPort || 80;
199
+ const host = optsWithoutSignal.host = validateHost(options.hostname, 'hostname') ||
200
+ validateHost(options.host, 'host') || 'localhost';
201
+
202
+ const setHost = options.setHost !== undefined ?
203
+ Boolean(options.setHost) :
204
+ options.setDefaultHeaders !== false;
205
+
206
+ this._removedConnection = options.setDefaultHeaders === false;
207
+ this._removedContLen = options.setDefaultHeaders === false;
208
+ this._removedTE = options.setDefaultHeaders === false;
209
+
210
+ this.socketPath = options.socketPath;
211
+
212
+ if (options.timeout !== undefined)
213
+ this.timeout = getTimerDuration(options.timeout, 'timeout');
214
+
215
+ const signal = options.signal;
216
+ if (signal) {
217
+ addAbortSignal(signal, this);
218
+ delete optsWithoutSignal.signal;
219
+ }
220
+ let method = options.method;
221
+ const methodIsString = (typeof method === 'string');
222
+ if (method !== null && method !== undefined && !methodIsString) {
223
+ throw new ERR_INVALID_ARG_TYPE('options.method', 'string', method);
224
+ }
225
+
226
+ if (methodIsString && method) {
227
+ if (!checkIsHttpToken(method)) {
228
+ throw new ERR_INVALID_HTTP_TOKEN('Method', method);
229
+ }
230
+ method = this.method = method.toUpperCase();
231
+ } else {
232
+ method = this.method = 'GET';
233
+ }
234
+
235
+ const maxHeaderSize = options.maxHeaderSize;
236
+ if (maxHeaderSize !== undefined)
237
+ validateInteger(maxHeaderSize, 'maxHeaderSize', 0);
238
+ this.maxHeaderSize = maxHeaderSize;
239
+
240
+ const insecureHTTPParser = options.insecureHTTPParser;
241
+ if (insecureHTTPParser !== undefined) {
242
+ validateBoolean(insecureHTTPParser, 'options.insecureHTTPParser');
243
+ }
244
+
245
+ this.insecureHTTPParser = insecureHTTPParser;
246
+
247
+ if (options.joinDuplicateHeaders !== undefined) {
248
+ validateBoolean(options.joinDuplicateHeaders, 'options.joinDuplicateHeaders');
249
+ }
250
+
251
+ this.joinDuplicateHeaders = options.joinDuplicateHeaders;
252
+
253
+ this.path = options.path || '/';
254
+ if (cb) {
255
+ this.once('response', cb);
256
+ }
257
+
258
+ if (method === 'GET' ||
259
+ method === 'HEAD' ||
260
+ method === 'DELETE' ||
261
+ method === 'OPTIONS' ||
262
+ method === 'TRACE' ||
263
+ method === 'CONNECT') {
264
+ this.useChunkedEncodingByDefault = false;
265
+ } else {
266
+ this.useChunkedEncodingByDefault = true;
267
+ }
268
+
269
+ this._ended = false;
270
+ this.res = null;
271
+ this.aborted = false;
272
+ this.timeoutCb = null;
273
+ this.upgradeOrConnect = false;
274
+ this.parser = null;
275
+ this.maxHeadersCount = null;
276
+ this.reusedSocket = false;
277
+ this.host = host;
278
+ this.protocol = protocol;
279
+
280
+ if (this.agent) {
281
+ // If there is an agent we should default to Connection:keep-alive,
282
+ // but only if the Agent will actually reuse the connection!
283
+ // If it's not a keepAlive agent, and the maxSockets==Infinity, then
284
+ // there's never a case where this socket will actually be reused
285
+ if (!this.agent.keepAlive && !NumberIsFinite(this.agent.maxSockets)) {
286
+ this._last = true;
287
+ this.shouldKeepAlive = false;
288
+ } else {
289
+ this._last = false;
290
+ this.shouldKeepAlive = true;
291
+ }
292
+ }
293
+
294
+ const headersArray = ArrayIsArray(options.headers);
295
+ if (!headersArray) {
296
+ if (options.headers) {
297
+ const keys = ObjectKeys(options.headers);
298
+ // Retain for(;;) loop for performance reasons
299
+ // Refs: https://github.com/nodejs/node/pull/30958
300
+ for (let i = 0; i < keys.length; i++) {
301
+ const key = keys[i];
302
+ this.setHeader(key, options.headers[key]);
303
+ }
304
+ }
305
+
306
+ if (host && !this.getHeader('host') && setHost) {
307
+ let hostHeader = host;
308
+
309
+ // For the Host header, ensure that IPv6 addresses are enclosed
310
+ // in square brackets, as defined by URI formatting
311
+ // https://tools.ietf.org/html/rfc3986#section-3.2.2
312
+ const posColon = hostHeader.indexOf(':');
313
+ if (posColon !== -1 &&
314
+ hostHeader.includes(':', posColon + 1) &&
315
+ hostHeader.charCodeAt(0) !== 91/* '[' */) {
316
+ hostHeader = `[${hostHeader}]`;
317
+ }
318
+
319
+ if (port && +port !== defaultPort) {
320
+ hostHeader += ':' + port;
321
+ }
322
+ this.setHeader('Host', hostHeader);
323
+ }
324
+
325
+ if (options.auth && !this.getHeader('Authorization')) {
326
+ this.setHeader('Authorization', 'Basic ' +
327
+ Buffer.from(options.auth).toString('base64'));
328
+ }
329
+
330
+ if (this.getHeader('expect')) {
331
+ if (this._header) {
332
+ throw new ERR_HTTP_HEADERS_SENT('render');
333
+ }
334
+
335
+ this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n',
336
+ this[kOutHeaders]);
337
+ }
338
+ } else {
339
+ this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n',
340
+ options.headers);
341
+ }
342
+
343
+ this[kUniqueHeaders] = parseUniqueHeadersOption(options.uniqueHeaders);
344
+
345
+ // initiate connection
346
+ if (this.agent) {
347
+ this.agent.addRequest(this, optsWithoutSignal);
348
+ } else {
349
+ // No agent, default to Connection:close.
350
+ this._last = true;
351
+ this.shouldKeepAlive = false;
352
+ let opts = optsWithoutSignal;
353
+ if (opts.path || opts.socketPath) {
354
+ opts = { ...optsWithoutSignal };
355
+ if (opts.socketPath) {
356
+ opts.path = opts.socketPath;
357
+ } else {
358
+ opts.path &&= undefined;
359
+ }
360
+ }
361
+ if (typeof opts.createConnection === 'function') {
362
+ const oncreate = once((err, socket) => {
363
+ if (err) {
364
+ process.nextTick(() => emitErrorEvent(this, err));
365
+ } else {
366
+ this.onSocket(socket);
367
+ }
368
+ });
369
+
370
+ try {
371
+ const newSocket = opts.createConnection(opts, oncreate);
372
+ if (newSocket) {
373
+ oncreate(null, newSocket);
374
+ }
375
+ } catch (err) {
376
+ oncreate(err);
377
+ }
378
+ } else {
379
+ debug('CLIENT use net.createConnection', opts);
380
+ this.onSocket(net.createConnection(opts));
381
+ }
382
+ }
383
+ if (onClientRequestCreatedChannel.hasSubscribers) {
384
+ onClientRequestCreatedChannel.publish({
385
+ request: this,
386
+ });
387
+ }
388
+ }
389
+ ObjectSetPrototypeOf(ClientRequest.prototype, OutgoingMessage.prototype);
390
+ ObjectSetPrototypeOf(ClientRequest, OutgoingMessage);
391
+
392
+ ClientRequest.prototype._finish = function _finish() {
393
+ OutgoingMessage.prototype._finish.call(this);
394
+ if (hasObserver('http')) {
395
+ startPerf(this, kClientRequestStatistics, {
396
+ type: 'http',
397
+ name: 'HttpClient',
398
+ detail: {
399
+ req: {
400
+ method: this.method,
401
+ url: `${this.protocol}//${this.host}${this.path}`,
402
+ headers: typeof this.getHeaders === 'function' ? this.getHeaders() : {},
403
+ },
404
+ },
405
+ });
406
+ }
407
+ if (onClientRequestStartChannel.hasSubscribers) {
408
+ onClientRequestStartChannel.publish({
409
+ request: this,
410
+ });
411
+ }
412
+ if (isTraceHTTPEnabled()) {
413
+ this._traceEventId = getNextTraceEventId();
414
+ traceBegin(HTTP_CLIENT_TRACE_EVENT_NAME, this._traceEventId);
415
+ }
416
+ };
417
+
418
+ ClientRequest.prototype._implicitHeader = function _implicitHeader() {
419
+ if (this._header) {
420
+ throw new ERR_HTTP_HEADERS_SENT('render');
421
+ }
422
+ this._storeHeader(this.method + ' ' + this.path + ' HTTP/1.1\r\n',
423
+ this[kOutHeaders]);
424
+ };
425
+
426
+ ClientRequest.prototype.abort = function abort() {
427
+ if (this.aborted) {
428
+ return;
429
+ }
430
+ this.aborted = true;
431
+ process.nextTick(emitAbortNT, this);
432
+ this.destroy();
433
+ };
434
+
435
+ ClientRequest.prototype.destroy = function destroy(err) {
436
+ if (this.destroyed) {
437
+ return this;
438
+ }
439
+ this.destroyed = true;
440
+
441
+ // If we're aborting, we don't care about any more response data.
442
+ if (this.res) {
443
+ this.res._dump();
444
+ }
445
+
446
+ this[kError] = err;
447
+ this.socket?.destroy(err);
448
+
449
+ return this;
450
+ };
451
+
452
+ function emitAbortNT(req) {
453
+ req.emit('abort');
454
+ }
455
+
456
+ function ondrain() {
457
+ const msg = this._httpMessage;
458
+ if (msg && !msg.finished && msg[kNeedDrain]) {
459
+ msg[kNeedDrain] = false;
460
+ msg.emit('drain');
461
+ }
462
+ }
463
+
464
+ function socketCloseListener() {
465
+ const socket = this;
466
+ const req = socket._httpMessage;
467
+ debug('HTTP socket close');
468
+
469
+ // NOTE: It's important to get parser here, because it could be freed by
470
+ // the `socketOnData`.
471
+ const parser = socket.parser;
472
+ const res = req.res;
473
+
474
+ req.destroyed = true;
475
+ if (res) {
476
+ // Socket closed before we emitted 'end' below.
477
+ if (!res.complete) {
478
+ res.destroy(new ConnResetException('aborted'));
479
+ }
480
+ req._closed = true;
481
+ req.emit('close');
482
+ if (!res.aborted && res.readable) {
483
+ res.push(null);
484
+ }
485
+ } else {
486
+ if (!req.socket._hadError) {
487
+ // This socket error fired before we started to
488
+ // receive a response. The error needs to
489
+ // fire on the request.
490
+ req.socket._hadError = true;
491
+ emitErrorEvent(req, new ConnResetException('socket hang up'));
492
+ }
493
+ req._closed = true;
494
+ req.emit('close');
495
+ }
496
+
497
+ // Too bad. That output wasn't getting written.
498
+ // This is pretty terrible that it doesn't raise an error.
499
+ // Fixed better in v0.10
500
+ if (req.outputData)
501
+ req.outputData.length = 0;
502
+
503
+ if (parser) {
504
+ parser.finish();
505
+ freeParser(parser, req, socket);
506
+ }
507
+ }
508
+
509
+ function socketErrorListener(err) {
510
+ const socket = this;
511
+ const req = socket._httpMessage;
512
+ debug('SOCKET ERROR:', err.message, err.stack);
513
+
514
+ if (req) {
515
+ // For Safety. Some additional errors might fire later on
516
+ // and we need to make sure we don't double-fire the error event.
517
+ req.socket._hadError = true;
518
+ emitErrorEvent(req, err);
519
+ }
520
+
521
+ const parser = socket.parser;
522
+ if (parser) {
523
+ parser.finish();
524
+ freeParser(parser, req, socket);
525
+ }
526
+
527
+ // Ensure that no further data will come out of the socket
528
+ socket.removeListener('data', socketOnData);
529
+ socket.removeListener('end', socketOnEnd);
530
+ socket.destroy();
531
+ }
532
+
533
+ function socketOnEnd() {
534
+ const socket = this;
535
+ const req = this._httpMessage;
536
+ const parser = this.parser;
537
+
538
+ if (!req.res && !req.socket._hadError) {
539
+ // If we don't have a response then we know that the socket
540
+ // ended prematurely and we need to emit an error on the request.
541
+ req.socket._hadError = true;
542
+ emitErrorEvent(req, new ConnResetException('socket hang up'));
543
+ }
544
+ if (parser) {
545
+ parser.finish();
546
+ freeParser(parser, req, socket);
547
+ }
548
+ socket.destroy();
549
+ }
550
+
551
+ function socketOnData(d) {
552
+ const socket = this;
553
+ const req = this._httpMessage;
554
+ const parser = this.parser;
555
+
556
+ assert(parser && parser.socket === socket);
557
+
558
+ const ret = parser.execute(d);
559
+ if (ret instanceof Error) {
560
+ prepareError(ret, parser, d);
561
+ debug('parse error', ret);
562
+ freeParser(parser, req, socket);
563
+ socket.removeListener('data', socketOnData);
564
+ socket.removeListener('end', socketOnEnd);
565
+ socket.destroy();
566
+ req.socket._hadError = true;
567
+ emitErrorEvent(req, ret);
568
+ } else if (parser.incoming?.upgrade) {
569
+ // Upgrade (if status code 101) or CONNECT
570
+ const bytesParsed = ret;
571
+ const res = parser.incoming;
572
+ req.res = res;
573
+
574
+ socket.removeListener('data', socketOnData);
575
+ socket.removeListener('end', socketOnEnd);
576
+ socket.removeListener('drain', ondrain);
577
+
578
+ if (req.timeoutCb) socket.removeListener('timeout', req.timeoutCb);
579
+ socket.removeListener('timeout', responseOnTimeout);
580
+
581
+ parser.finish();
582
+ freeParser(parser, req, socket);
583
+
584
+ const bodyHead = d.slice(bytesParsed, d.length);
585
+
586
+ const eventName = req.method === 'CONNECT' ? 'connect' : 'upgrade';
587
+ if (req.listenerCount(eventName) > 0) {
588
+ req.upgradeOrConnect = true;
589
+
590
+ // detach the socket
591
+ socket.emit('agentRemove');
592
+ socket.removeListener('close', socketCloseListener);
593
+ socket.removeListener('error', socketErrorListener);
594
+
595
+ socket._httpMessage = null;
596
+ socket.readableFlowing = null;
597
+
598
+ req.emit(eventName, res, socket, bodyHead);
599
+ req.destroyed = true;
600
+ req._closed = true;
601
+ req.emit('close');
602
+ } else {
603
+ // Requested Upgrade or used CONNECT method, but have no handler.
604
+ socket.destroy();
605
+ }
606
+ } else if (parser.incoming?.complete &&
607
+ // When the status code is informational (100, 102-199),
608
+ // the server will send a final response after this client
609
+ // sends a request body, so we must not free the parser.
610
+ // 101 (Switching Protocols) and all other status codes
611
+ // should be processed normally.
612
+ !statusIsInformational(parser.incoming.statusCode)) {
613
+ socket.removeListener('data', socketOnData);
614
+ socket.removeListener('end', socketOnEnd);
615
+ socket.removeListener('drain', ondrain);
616
+ freeParser(parser, req, socket);
617
+ }
618
+ }
619
+
620
+ function statusIsInformational(status) {
621
+ // 100 (Continue) RFC7231 Section 6.2.1
622
+ // 102 (Processing) RFC2518
623
+ // 103 (Early Hints) RFC8297
624
+ // 104-199 (Unassigned)
625
+ return (status < 200 && status >= 100 && status !== 101);
626
+ }
627
+
628
+ // client
629
+ function parserOnIncomingClient(res, shouldKeepAlive) {
630
+ const socket = this.socket;
631
+ const req = socket._httpMessage;
632
+
633
+ debug('AGENT incoming response!');
634
+
635
+ if (req.res) {
636
+ // We already have a response object, this means the server
637
+ // sent a double response.
638
+ socket.destroy();
639
+ return 0; // No special treatment.
640
+ }
641
+ req.res = res;
642
+
643
+ // Skip body and treat as Upgrade.
644
+ if (res.upgrade)
645
+ return 2;
646
+
647
+ // Responses to CONNECT request is handled as Upgrade.
648
+ const method = req.method;
649
+ if (method === 'CONNECT') {
650
+ res.upgrade = true;
651
+ return 2; // Skip body and treat as Upgrade.
652
+ }
653
+
654
+ if (statusIsInformational(res.statusCode)) {
655
+ // Restart the parser, as this is a 1xx informational message.
656
+ req.res = null; // Clear res so that we don't hit double-responses.
657
+ // Maintain compatibility by sending 100-specific events
658
+ if (res.statusCode === 100) {
659
+ req.emit('continue');
660
+ }
661
+ // Send information events to all 1xx responses except 101 Upgrade.
662
+ req.emit('information', {
663
+ statusCode: res.statusCode,
664
+ statusMessage: res.statusMessage,
665
+ httpVersion: res.httpVersion,
666
+ httpVersionMajor: res.httpVersionMajor,
667
+ httpVersionMinor: res.httpVersionMinor,
668
+ headers: res.headers,
669
+ rawHeaders: res.rawHeaders,
670
+ });
671
+
672
+ return 1; // Skip body but don't treat as Upgrade.
673
+ }
674
+
675
+ if (req.shouldKeepAlive && !shouldKeepAlive && !req.upgradeOrConnect) {
676
+ // Server MUST respond with Connection:keep-alive for us to enable it.
677
+ // If we've been upgraded (via WebSockets) we also shouldn't try to
678
+ // keep the connection open.
679
+ req.shouldKeepAlive = false;
680
+ }
681
+
682
+ if (req[kClientRequestStatistics] && hasObserver('http')) {
683
+ stopPerf(req, kClientRequestStatistics, {
684
+ detail: {
685
+ res: {
686
+ statusCode: res.statusCode,
687
+ statusMessage: res.statusMessage,
688
+ headers: res.headers,
689
+ },
690
+ },
691
+ });
692
+ }
693
+ if (onClientResponseFinishChannel.hasSubscribers) {
694
+ onClientResponseFinishChannel.publish({
695
+ request: req,
696
+ response: res,
697
+ });
698
+ }
699
+ if (isTraceHTTPEnabled() && typeof req._traceEventId === 'number') {
700
+ traceEnd(HTTP_CLIENT_TRACE_EVENT_NAME, req._traceEventId, {
701
+ path: req.path,
702
+ statusCode: res.statusCode,
703
+ });
704
+ }
705
+ req.res = res;
706
+ res.req = req;
707
+
708
+ // Add our listener first, so that we guarantee socket cleanup
709
+ res.on('end', responseOnEnd);
710
+ req.on('finish', requestOnFinish);
711
+ socket.on('timeout', responseOnTimeout);
712
+
713
+ // If the user did not listen for the 'response' event, then they
714
+ // can't possibly read the data, so we ._dump() it into the void
715
+ // so that the socket doesn't hang there in a paused state.
716
+ if (req.aborted || !req.emit('response', res))
717
+ res._dump();
718
+
719
+ if (method === 'HEAD')
720
+ return 1; // Skip body but don't treat as Upgrade.
721
+
722
+ if (res.statusCode === 304) {
723
+ res.complete = true;
724
+ return 1; // Skip body as there won't be any
725
+ }
726
+
727
+ return 0; // No special treatment.
728
+ }
729
+
730
+ // client
731
+ function responseKeepAlive(req) {
732
+ const socket = req.socket;
733
+
734
+ debug('AGENT socket keep-alive');
735
+ if (req.timeoutCb) {
736
+ socket.setTimeout(0, req.timeoutCb);
737
+ req.timeoutCb = null;
738
+ }
739
+ socket.removeListener('close', socketCloseListener);
740
+ socket.removeListener('error', socketErrorListener);
741
+ socket.removeListener('data', socketOnData);
742
+ socket.removeListener('end', socketOnEnd);
743
+
744
+ // TODO(ronag): Between here and emitFreeNT the socket
745
+ // has no 'error' handler.
746
+
747
+ // There are cases where _handle === null. Avoid those. Passing undefined to
748
+ // nextTick() will call getDefaultTriggerAsyncId() to retrieve the id.
749
+ const asyncId = socket._handle ? socket._handle.getAsyncId() : undefined;
750
+ // Mark this socket as available, AFTER user-added end
751
+ // handlers have a chance to run.
752
+ defaultTriggerAsyncIdScope(asyncId, process.nextTick, emitFreeNT, req);
753
+
754
+ req.destroyed = true;
755
+ if (req.res) {
756
+ // Detach socket from IncomingMessage to avoid destroying the freed
757
+ // socket in IncomingMessage.destroy().
758
+ req.res.socket = null;
759
+ }
760
+ }
761
+
762
+ function responseOnEnd() {
763
+ const req = this.req;
764
+ const socket = req.socket;
765
+
766
+ if (socket) {
767
+ if (req.timeoutCb) socket.removeListener('timeout', emitRequestTimeout);
768
+ socket.removeListener('timeout', responseOnTimeout);
769
+ }
770
+
771
+ req._ended = true;
772
+
773
+ if (!req.shouldKeepAlive) {
774
+ if (socket.writable) {
775
+ debug('AGENT socket.destroySoon()');
776
+ if (typeof socket.destroySoon === 'function')
777
+ socket.destroySoon();
778
+ else
779
+ socket.end();
780
+ }
781
+ assert(!socket.writable);
782
+ } else if (req.writableFinished && !this.aborted) {
783
+ assert(req.finished);
784
+ // We can assume `req.finished` means all data has been written since:
785
+ // - `'responseOnEnd'` means we have been assigned a socket.
786
+ // - when we have a socket we write directly to it without buffering.
787
+ // - `req.finished` means `end()` has been called and no further data.
788
+ // can be written
789
+ // In addition, `req.writableFinished` means all data written has been
790
+ // accepted by the kernel. (i.e. the `req.socket` is drained).Without
791
+ // this constraint, we may assign a non drained socket to a request.
792
+ responseKeepAlive(req);
793
+ }
794
+ }
795
+
796
+ function responseOnTimeout() {
797
+ const req = this._httpMessage;
798
+ if (!req) return;
799
+ const res = req.res;
800
+ if (!res) return;
801
+ res.emit('timeout');
802
+ }
803
+
804
+ // This function is necessary in the case where we receive the entire response
805
+ // from the server before we finish sending out the request.
806
+ function requestOnFinish() {
807
+ const req = this;
808
+
809
+ if (req.shouldKeepAlive && req._ended)
810
+ responseKeepAlive(req);
811
+ }
812
+
813
+ function emitFreeNT(req) {
814
+ req._closed = true;
815
+ req.emit('close');
816
+ if (req.socket) {
817
+ req.socket.emit('free');
818
+ }
819
+ }
820
+
821
+ function tickOnSocket(req, socket) {
822
+ const parser = parsers.alloc();
823
+ req.socket = socket;
824
+ const lenient = req.insecureHTTPParser === undefined ?
825
+ isLenient() : req.insecureHTTPParser;
826
+ parser.initialize(HTTPParser.RESPONSE,
827
+ new HTTPClientAsyncResource('HTTPINCOMINGMESSAGE', req),
828
+ req.maxHeaderSize || 0,
829
+ lenient ? kLenientAll : kLenientNone);
830
+ parser.socket = socket;
831
+ parser.outgoing = req;
832
+ req.parser = parser;
833
+
834
+ socket.parser = parser;
835
+ socket._httpMessage = req;
836
+
837
+ // Propagate headers limit from request object to parser
838
+ if (typeof req.maxHeadersCount === 'number') {
839
+ parser.maxHeaderPairs = req.maxHeadersCount << 1;
840
+ }
841
+
842
+ parser.joinDuplicateHeaders = req.joinDuplicateHeaders;
843
+
844
+ parser.onIncoming = parserOnIncomingClient;
845
+ socket.on('error', socketErrorListener);
846
+ socket.on('data', socketOnData);
847
+ socket.on('end', socketOnEnd);
848
+ socket.on('close', socketCloseListener);
849
+ socket.on('drain', ondrain);
850
+
851
+ if (
852
+ req.timeout !== undefined ||
853
+ (req.agent?.options?.timeout)
854
+ ) {
855
+ listenSocketTimeout(req);
856
+ }
857
+ req.emit('socket', socket);
858
+ }
859
+
860
+ function emitRequestTimeout() {
861
+ const req = this._httpMessage;
862
+ if (req) {
863
+ req.emit('timeout');
864
+ }
865
+ }
866
+
867
+ function listenSocketTimeout(req) {
868
+ if (req.timeoutCb) {
869
+ return;
870
+ }
871
+ // Set timeoutCb so it will get cleaned up on request end.
872
+ req.timeoutCb = emitRequestTimeout;
873
+ // Delegate socket timeout event.
874
+ if (req.socket) {
875
+ req.socket.once('timeout', emitRequestTimeout);
876
+ } else {
877
+ req.on('socket', (socket) => {
878
+ socket.once('timeout', emitRequestTimeout);
879
+ });
880
+ }
881
+ }
882
+
883
+ ClientRequest.prototype.onSocket = function onSocket(socket, err) {
884
+ // TODO(ronag): Between here and onSocketNT the socket
885
+ // has no 'error' handler.
886
+ process.nextTick(onSocketNT, this, socket, err);
887
+ };
888
+
889
+ function onSocketNT(req, socket, err) {
890
+ if (req.destroyed || err) {
891
+ req.destroyed = true;
892
+
893
+ function _destroy(req, err) {
894
+ if (!req.aborted && !err) {
895
+ err = new ConnResetException('socket hang up');
896
+ }
897
+ if (err) {
898
+ emitErrorEvent(req, err);
899
+ }
900
+ req._closed = true;
901
+ req.emit('close');
902
+ }
903
+
904
+ if (socket) {
905
+ if (!err && req.agent && !socket.destroyed) {
906
+ socket.emit('free');
907
+ } else {
908
+ finished(socket.destroy(err || req[kError]), (er) => {
909
+ if (er?.code === 'ERR_STREAM_PREMATURE_CLOSE') {
910
+ er = null;
911
+ }
912
+ _destroy(req, er || err);
913
+ });
914
+ return;
915
+ }
916
+ }
917
+
918
+ _destroy(req, err || req[kError]);
919
+ } else {
920
+ tickOnSocket(req, socket);
921
+ req._flush();
922
+ }
923
+ }
924
+
925
+ ClientRequest.prototype._deferToConnect = _deferToConnect;
926
+ function _deferToConnect(method, arguments_) {
927
+ // This function is for calls that need to happen once the socket is
928
+ // assigned to this request and writable. It's an important promisy
929
+ // thing for all the socket calls that happen either now
930
+ // (when a socket is assigned) or in the future (when a socket gets
931
+ // assigned out of the pool and is eventually writable).
932
+
933
+ const callSocketMethod = () => {
934
+ if (method)
935
+ ReflectApply(this.socket[method], this.socket, arguments_);
936
+ };
937
+
938
+ const onSocket = () => {
939
+ if (this.socket.writable) {
940
+ callSocketMethod();
941
+ } else {
942
+ this.socket.once('connect', callSocketMethod);
943
+ }
944
+ };
945
+
946
+ if (!this.socket) {
947
+ this.once('socket', onSocket);
948
+ } else {
949
+ onSocket();
950
+ }
951
+ }
952
+
953
+ ClientRequest.prototype.setTimeout = function setTimeout(msecs, callback) {
954
+ if (this._ended) {
955
+ return this;
956
+ }
957
+
958
+ listenSocketTimeout(this);
959
+ msecs = getTimerDuration(msecs, 'msecs');
960
+ if (callback) this.once('timeout', callback);
961
+
962
+ if (this.socket) {
963
+ setSocketTimeout(this.socket, msecs);
964
+ } else {
965
+ this.once('socket', (sock) => setSocketTimeout(sock, msecs));
966
+ }
967
+
968
+ return this;
969
+ };
970
+
971
+ function setSocketTimeout(sock, msecs) {
972
+ if (sock.connecting) {
973
+ sock.once('connect', function() {
974
+ sock.setTimeout(msecs);
975
+ });
976
+ } else {
977
+ sock.setTimeout(msecs);
978
+ }
979
+ }
980
+
981
+ ClientRequest.prototype.setNoDelay = function setNoDelay(noDelay) {
982
+ this._deferToConnect('setNoDelay', [noDelay]);
983
+ };
984
+
985
+ ClientRequest.prototype.setSocketKeepAlive =
986
+ function setSocketKeepAlive(enable, initialDelay) {
987
+ this._deferToConnect('setKeepAlive', [enable, initialDelay]);
988
+ };
989
+
990
+ ClientRequest.prototype.clearTimeout = function clearTimeout(cb) {
991
+ this.setTimeout(0, cb);
992
+ };
993
+
994
+ module.exports = {
995
+ ClientRequest,
996
+ };