@pnpm/exe 11.12.0 → 11.13.1

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 (444) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/node-gyp-bin/node-gyp +6 -0
  3. package/dist/node-gyp-bin/node-gyp.cmd +5 -0
  4. package/dist/node_modules/.bin/node-gyp +38 -0
  5. package/dist/node_modules/.bin/node-which +38 -0
  6. package/dist/node_modules/.bin/nopt +38 -0
  7. package/dist/node_modules/.bin/semver +38 -0
  8. package/dist/node_modules/.package-map.json +1 -0
  9. package/dist/node_modules/@isaacs/fs-minipass/LICENSE +15 -0
  10. package/dist/node_modules/@isaacs/fs-minipass/dist/commonjs/index.js +430 -0
  11. package/dist/node_modules/@isaacs/fs-minipass/dist/commonjs/package.json +3 -0
  12. package/dist/node_modules/@isaacs/fs-minipass/dist/esm/index.js +420 -0
  13. package/dist/node_modules/@isaacs/fs-minipass/dist/esm/package.json +3 -0
  14. package/dist/node_modules/@isaacs/fs-minipass/package.json +72 -0
  15. package/dist/node_modules/abbrev/LICENSE +46 -0
  16. package/dist/node_modules/abbrev/lib/index.js +53 -0
  17. package/dist/node_modules/abbrev/package.json +41 -0
  18. package/dist/node_modules/chownr/dist/commonjs/index.js +93 -0
  19. package/dist/node_modules/chownr/dist/commonjs/package.json +3 -0
  20. package/dist/node_modules/chownr/dist/esm/index.js +85 -0
  21. package/dist/node_modules/chownr/dist/esm/package.json +3 -0
  22. package/dist/node_modules/chownr/package.json +69 -0
  23. package/dist/node_modules/env-paths/index.js +74 -0
  24. package/dist/node_modules/env-paths/license +9 -0
  25. package/dist/node_modules/env-paths/package.json +45 -0
  26. package/dist/node_modules/exponential-backoff/LICENSE +202 -0
  27. package/dist/node_modules/exponential-backoff/dist/backoff.js +124 -0
  28. package/dist/node_modules/exponential-backoff/dist/delay/always/always.delay.js +25 -0
  29. package/dist/node_modules/exponential-backoff/dist/delay/delay.base.js +45 -0
  30. package/dist/node_modules/exponential-backoff/dist/delay/delay.factory.js +17 -0
  31. package/dist/node_modules/exponential-backoff/dist/delay/delay.interface.js +3 -0
  32. package/dist/node_modules/exponential-backoff/dist/delay/skip-first/skip-first.delay.js +82 -0
  33. package/dist/node_modules/exponential-backoff/dist/jitter/full/full.jitter.js +8 -0
  34. package/dist/node_modules/exponential-backoff/dist/jitter/jitter.factory.js +15 -0
  35. package/dist/node_modules/exponential-backoff/dist/jitter/no/no.jitter.js +7 -0
  36. package/dist/node_modules/exponential-backoff/dist/options.js +31 -0
  37. package/dist/node_modules/exponential-backoff/package.json +62 -0
  38. package/dist/node_modules/fdir/LICENSE +7 -0
  39. package/dist/node_modules/fdir/dist/index.cjs +588 -0
  40. package/dist/node_modules/fdir/dist/index.d.cts +155 -0
  41. package/dist/node_modules/fdir/dist/index.d.mts +155 -0
  42. package/dist/node_modules/fdir/dist/index.mjs +570 -0
  43. package/dist/node_modules/fdir/package.json +103 -0
  44. package/dist/node_modules/graceful-fs/LICENSE +15 -0
  45. package/dist/node_modules/graceful-fs/clone.js +23 -0
  46. package/dist/node_modules/graceful-fs/graceful-fs.js +448 -0
  47. package/dist/node_modules/graceful-fs/legacy-streams.js +118 -0
  48. package/dist/node_modules/graceful-fs/package.json +53 -0
  49. package/dist/node_modules/graceful-fs/polyfills.js +355 -0
  50. package/dist/node_modules/isexe/dist/commonjs/index.js +56 -0
  51. package/dist/node_modules/isexe/dist/commonjs/index.min.js +2 -0
  52. package/dist/node_modules/isexe/dist/commonjs/options.js +3 -0
  53. package/dist/node_modules/isexe/dist/commonjs/package.json +3 -0
  54. package/dist/node_modules/isexe/dist/commonjs/posix.js +67 -0
  55. package/dist/node_modules/isexe/dist/commonjs/win32.js +63 -0
  56. package/dist/node_modules/isexe/dist/esm/index.js +16 -0
  57. package/dist/node_modules/isexe/dist/esm/index.min.js +2 -0
  58. package/dist/node_modules/isexe/dist/esm/options.js +2 -0
  59. package/dist/node_modules/isexe/dist/esm/package.json +3 -0
  60. package/dist/node_modules/isexe/dist/esm/posix.js +62 -0
  61. package/dist/node_modules/isexe/dist/esm/win32.js +58 -0
  62. package/dist/node_modules/isexe/package.json +78 -0
  63. package/dist/node_modules/minipass/dist/commonjs/index.js +1038 -0
  64. package/dist/node_modules/minipass/dist/commonjs/package.json +3 -0
  65. package/dist/node_modules/minipass/dist/esm/index.js +1020 -0
  66. package/dist/node_modules/minipass/dist/esm/package.json +3 -0
  67. package/dist/node_modules/minipass/package.json +77 -0
  68. package/dist/node_modules/minizlib/LICENSE +26 -0
  69. package/dist/node_modules/minizlib/dist/commonjs/constants.js +123 -0
  70. package/dist/node_modules/minizlib/dist/commonjs/index.js +416 -0
  71. package/dist/node_modules/minizlib/dist/commonjs/package.json +3 -0
  72. package/dist/node_modules/minizlib/dist/esm/constants.js +117 -0
  73. package/dist/node_modules/minizlib/dist/esm/index.js +363 -0
  74. package/dist/node_modules/minizlib/dist/esm/package.json +3 -0
  75. package/dist/node_modules/minizlib/package.json +80 -0
  76. package/dist/node_modules/node-gyp/.release-please-manifest.json +3 -0
  77. package/dist/node_modules/node-gyp/LICENSE +24 -0
  78. package/dist/node_modules/node-gyp/addon.gypi +204 -0
  79. package/dist/node_modules/node-gyp/bin/node-gyp.js +145 -0
  80. package/dist/node_modules/node-gyp/eslint.config.js +3 -0
  81. package/dist/node_modules/node-gyp/gyp/.release-please-manifest.json +3 -0
  82. package/dist/node_modules/node-gyp/gyp/LICENSE +28 -0
  83. package/dist/node_modules/node-gyp/gyp/data/ninja/build.ninja +4 -0
  84. package/dist/node_modules/node-gyp/gyp/data/win/large-pdb-shim.cc +12 -0
  85. package/dist/node_modules/node-gyp/gyp/gyp +8 -0
  86. package/dist/node_modules/node-gyp/gyp/gyp.bat +5 -0
  87. package/dist/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  88. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +365 -0
  89. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  90. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1283 -0
  91. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1545 -0
  92. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  93. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +152 -0
  94. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +270 -0
  95. package/dist/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +607 -0
  96. package/dist/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +706 -0
  97. package/dist/node_modules/node-gyp/gyp/pylib/gyp/common.py +725 -0
  98. package/dist/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +186 -0
  99. package/dist/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +170 -0
  100. package/dist/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +113 -0
  101. package/dist/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  102. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  103. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +805 -0
  104. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1169 -0
  105. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1316 -0
  106. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +128 -0
  107. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +104 -0
  108. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +461 -0
  109. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +88 -0
  110. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +55 -0
  111. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2755 -0
  112. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3970 -0
  113. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  114. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2957 -0
  115. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +77 -0
  116. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1389 -0
  117. package/dist/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +26 -0
  118. package/dist/node_modules/node-gyp/gyp/pylib/gyp/input.py +3097 -0
  119. package/dist/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +99 -0
  120. package/dist/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +765 -0
  121. package/dist/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1255 -0
  122. package/dist/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  123. package/dist/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  124. package/dist/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +371 -0
  125. package/dist/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1936 -0
  126. package/dist/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py +54 -0
  127. package/dist/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +301 -0
  128. package/dist/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3180 -0
  129. package/dist/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +64 -0
  130. package/dist/node_modules/node-gyp/gyp/pylib/packaging/LICENSE +3 -0
  131. package/dist/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.APACHE +177 -0
  132. package/dist/node_modules/node-gyp/gyp/pylib/packaging/LICENSE.BSD +23 -0
  133. package/dist/node_modules/node-gyp/gyp/pylib/packaging/__init__.py +15 -0
  134. package/dist/node_modules/node-gyp/gyp/pylib/packaging/_elffile.py +107 -0
  135. package/dist/node_modules/node-gyp/gyp/pylib/packaging/_manylinux.py +252 -0
  136. package/dist/node_modules/node-gyp/gyp/pylib/packaging/_musllinux.py +83 -0
  137. package/dist/node_modules/node-gyp/gyp/pylib/packaging/_parser.py +359 -0
  138. package/dist/node_modules/node-gyp/gyp/pylib/packaging/_structures.py +61 -0
  139. package/dist/node_modules/node-gyp/gyp/pylib/packaging/_tokenizer.py +192 -0
  140. package/dist/node_modules/node-gyp/gyp/pylib/packaging/markers.py +251 -0
  141. package/dist/node_modules/node-gyp/gyp/pylib/packaging/metadata.py +807 -0
  142. package/dist/node_modules/node-gyp/gyp/pylib/packaging/py.typed +0 -0
  143. package/dist/node_modules/node-gyp/gyp/pylib/packaging/requirements.py +90 -0
  144. package/dist/node_modules/node-gyp/gyp/pylib/packaging/specifiers.py +1030 -0
  145. package/dist/node_modules/node-gyp/gyp/pylib/packaging/tags.py +541 -0
  146. package/dist/node_modules/node-gyp/gyp/pylib/packaging/utils.py +172 -0
  147. package/dist/node_modules/node-gyp/gyp/pylib/packaging/version.py +563 -0
  148. package/dist/node_modules/node-gyp/gyp/pyproject.toml +116 -0
  149. package/dist/node_modules/node-gyp/gyp/release-please-config.json +11 -0
  150. package/dist/node_modules/node-gyp/gyp/test_gyp.py +260 -0
  151. package/dist/node_modules/node-gyp/lib/Find-VisualStudio.cs +250 -0
  152. package/dist/node_modules/node-gyp/lib/build.js +230 -0
  153. package/dist/node_modules/node-gyp/lib/clean.js +15 -0
  154. package/dist/node_modules/node-gyp/lib/configure.js +328 -0
  155. package/dist/node_modules/node-gyp/lib/create-config-gypi.js +153 -0
  156. package/dist/node_modules/node-gyp/lib/download.js +86 -0
  157. package/dist/node_modules/node-gyp/lib/find-node-directory.js +63 -0
  158. package/dist/node_modules/node-gyp/lib/find-python.js +304 -0
  159. package/dist/node_modules/node-gyp/lib/find-visualstudio.js +606 -0
  160. package/dist/node_modules/node-gyp/lib/install.js +411 -0
  161. package/dist/node_modules/node-gyp/lib/list.js +26 -0
  162. package/dist/node_modules/node-gyp/lib/log.js +168 -0
  163. package/dist/node_modules/node-gyp/lib/node-gyp.js +199 -0
  164. package/dist/node_modules/node-gyp/lib/process-release.js +144 -0
  165. package/dist/node_modules/node-gyp/lib/rebuild.js +12 -0
  166. package/dist/node_modules/node-gyp/lib/remove.js +43 -0
  167. package/dist/node_modules/node-gyp/lib/util.js +81 -0
  168. package/dist/node_modules/node-gyp/macOS_Catalina_acid_test.sh +21 -0
  169. package/dist/node_modules/node-gyp/package.json +52 -0
  170. package/dist/node_modules/node-gyp/release-please-config.json +40 -0
  171. package/dist/node_modules/node-gyp/src/win_delay_load_hook.cc +41 -0
  172. package/dist/node_modules/nopt/LICENSE +15 -0
  173. package/dist/node_modules/nopt/bin/nopt.js +29 -0
  174. package/dist/node_modules/nopt/lib/debug.js +5 -0
  175. package/dist/node_modules/nopt/lib/nopt-lib.js +514 -0
  176. package/dist/node_modules/nopt/lib/nopt.js +34 -0
  177. package/dist/node_modules/nopt/lib/type-defs.js +91 -0
  178. package/dist/node_modules/nopt/package.json +52 -0
  179. package/dist/node_modules/picomatch/LICENSE +21 -0
  180. package/dist/node_modules/picomatch/index.js +17 -0
  181. package/dist/node_modules/picomatch/lib/constants.js +184 -0
  182. package/dist/node_modules/picomatch/lib/parse.js +1416 -0
  183. package/dist/node_modules/picomatch/lib/picomatch.js +361 -0
  184. package/dist/node_modules/picomatch/lib/scan.js +391 -0
  185. package/dist/node_modules/picomatch/lib/utils.js +72 -0
  186. package/dist/node_modules/picomatch/package.json +83 -0
  187. package/dist/node_modules/picomatch/posix.js +3 -0
  188. package/dist/node_modules/proc-log/LICENSE +15 -0
  189. package/dist/node_modules/proc-log/lib/index.js +158 -0
  190. package/dist/node_modules/proc-log/package.json +46 -0
  191. package/dist/node_modules/semver/LICENSE +15 -0
  192. package/dist/node_modules/semver/bin/semver.js +195 -0
  193. package/dist/node_modules/semver/classes/comparator.js +143 -0
  194. package/dist/node_modules/semver/classes/index.js +7 -0
  195. package/dist/node_modules/semver/classes/range.js +577 -0
  196. package/dist/node_modules/semver/classes/semver.js +350 -0
  197. package/dist/node_modules/semver/functions/clean.js +8 -0
  198. package/dist/node_modules/semver/functions/cmp.js +54 -0
  199. package/dist/node_modules/semver/functions/coerce.js +62 -0
  200. package/dist/node_modules/semver/functions/compare-build.js +9 -0
  201. package/dist/node_modules/semver/functions/compare-loose.js +5 -0
  202. package/dist/node_modules/semver/functions/compare.js +7 -0
  203. package/dist/node_modules/semver/functions/diff.js +60 -0
  204. package/dist/node_modules/semver/functions/eq.js +5 -0
  205. package/dist/node_modules/semver/functions/gt.js +5 -0
  206. package/dist/node_modules/semver/functions/gte.js +5 -0
  207. package/dist/node_modules/semver/functions/inc.js +21 -0
  208. package/dist/node_modules/semver/functions/lt.js +5 -0
  209. package/dist/node_modules/semver/functions/lte.js +5 -0
  210. package/dist/node_modules/semver/functions/major.js +5 -0
  211. package/dist/node_modules/semver/functions/minor.js +5 -0
  212. package/dist/node_modules/semver/functions/neq.js +5 -0
  213. package/dist/node_modules/semver/functions/parse.js +18 -0
  214. package/dist/node_modules/semver/functions/patch.js +5 -0
  215. package/dist/node_modules/semver/functions/prerelease.js +8 -0
  216. package/dist/node_modules/semver/functions/rcompare.js +5 -0
  217. package/dist/node_modules/semver/functions/rsort.js +5 -0
  218. package/dist/node_modules/semver/functions/satisfies.js +12 -0
  219. package/dist/node_modules/semver/functions/sort.js +5 -0
  220. package/dist/node_modules/semver/functions/truncate.js +48 -0
  221. package/dist/node_modules/semver/functions/valid.js +8 -0
  222. package/dist/node_modules/semver/index.js +93 -0
  223. package/dist/node_modules/semver/internal/constants.js +37 -0
  224. package/dist/node_modules/semver/internal/debug.js +11 -0
  225. package/dist/node_modules/semver/internal/identifiers.js +29 -0
  226. package/dist/node_modules/semver/internal/lrucache.js +42 -0
  227. package/dist/node_modules/semver/internal/parse-options.js +17 -0
  228. package/dist/node_modules/semver/internal/re.js +223 -0
  229. package/dist/node_modules/semver/package.json +78 -0
  230. package/dist/node_modules/semver/preload.js +4 -0
  231. package/dist/node_modules/semver/range.bnf +17 -0
  232. package/dist/node_modules/semver/ranges/gtr.js +6 -0
  233. package/dist/node_modules/semver/ranges/intersects.js +9 -0
  234. package/dist/node_modules/semver/ranges/ltr.js +6 -0
  235. package/dist/node_modules/semver/ranges/max-satisfying.js +27 -0
  236. package/dist/node_modules/semver/ranges/min-satisfying.js +26 -0
  237. package/dist/node_modules/semver/ranges/min-version.js +63 -0
  238. package/dist/node_modules/semver/ranges/outside.js +82 -0
  239. package/dist/node_modules/semver/ranges/simplify.js +49 -0
  240. package/dist/node_modules/semver/ranges/subset.js +249 -0
  241. package/dist/node_modules/semver/ranges/to-comparators.js +10 -0
  242. package/dist/node_modules/semver/ranges/valid.js +13 -0
  243. package/dist/node_modules/tar/dist/commonjs/create.js +82 -0
  244. package/dist/node_modules/tar/dist/commonjs/cwd-error.js +18 -0
  245. package/dist/node_modules/tar/dist/commonjs/extract.js +88 -0
  246. package/dist/node_modules/tar/dist/commonjs/get-write-flag.js +32 -0
  247. package/dist/node_modules/tar/dist/commonjs/header.js +348 -0
  248. package/dist/node_modules/tar/dist/commonjs/index.js +64 -0
  249. package/dist/node_modules/tar/dist/commonjs/index.min.js +4 -0
  250. package/dist/node_modules/tar/dist/commonjs/large-numbers.js +99 -0
  251. package/dist/node_modules/tar/dist/commonjs/list.js +145 -0
  252. package/dist/node_modules/tar/dist/commonjs/make-command.js +52 -0
  253. package/dist/node_modules/tar/dist/commonjs/mkdir.js +187 -0
  254. package/dist/node_modules/tar/dist/commonjs/mode-fix.js +29 -0
  255. package/dist/node_modules/tar/dist/commonjs/normalize-unicode.js +38 -0
  256. package/dist/node_modules/tar/dist/commonjs/normalize-windows-path.js +12 -0
  257. package/dist/node_modules/tar/dist/commonjs/options.js +66 -0
  258. package/dist/node_modules/tar/dist/commonjs/pack.js +544 -0
  259. package/dist/node_modules/tar/dist/commonjs/package.json +3 -0
  260. package/dist/node_modules/tar/dist/commonjs/parse.js +655 -0
  261. package/dist/node_modules/tar/dist/commonjs/path-reservations.js +170 -0
  262. package/dist/node_modules/tar/dist/commonjs/pax.js +182 -0
  263. package/dist/node_modules/tar/dist/commonjs/process-umask.js +7 -0
  264. package/dist/node_modules/tar/dist/commonjs/read-entry.js +136 -0
  265. package/dist/node_modules/tar/dist/commonjs/replace.js +227 -0
  266. package/dist/node_modules/tar/dist/commonjs/strip-absolute-path.js +29 -0
  267. package/dist/node_modules/tar/dist/commonjs/strip-trailing-slashes.js +18 -0
  268. package/dist/node_modules/tar/dist/commonjs/symlink-error.js +19 -0
  269. package/dist/node_modules/tar/dist/commonjs/types.js +70 -0
  270. package/dist/node_modules/tar/dist/commonjs/unpack.js +932 -0
  271. package/dist/node_modules/tar/dist/commonjs/update.js +33 -0
  272. package/dist/node_modules/tar/dist/commonjs/warn-method.js +31 -0
  273. package/dist/node_modules/tar/dist/commonjs/winchars.js +14 -0
  274. package/dist/node_modules/tar/dist/commonjs/write-entry.js +698 -0
  275. package/dist/node_modules/tar/dist/esm/create.js +76 -0
  276. package/dist/node_modules/tar/dist/esm/cwd-error.js +14 -0
  277. package/dist/node_modules/tar/dist/esm/extract.js +49 -0
  278. package/dist/node_modules/tar/dist/esm/get-write-flag.js +26 -0
  279. package/dist/node_modules/tar/dist/esm/header.js +311 -0
  280. package/dist/node_modules/tar/dist/esm/index.js +20 -0
  281. package/dist/node_modules/tar/dist/esm/index.min.js +4 -0
  282. package/dist/node_modules/tar/dist/esm/large-numbers.js +94 -0
  283. package/dist/node_modules/tar/dist/esm/list.js +105 -0
  284. package/dist/node_modules/tar/dist/esm/make-command.js +48 -0
  285. package/dist/node_modules/tar/dist/esm/mkdir.js +179 -0
  286. package/dist/node_modules/tar/dist/esm/mode-fix.js +25 -0
  287. package/dist/node_modules/tar/dist/esm/normalize-unicode.js +34 -0
  288. package/dist/node_modules/tar/dist/esm/normalize-windows-path.js +9 -0
  289. package/dist/node_modules/tar/dist/esm/options.js +54 -0
  290. package/dist/node_modules/tar/dist/esm/pack.js +502 -0
  291. package/dist/node_modules/tar/dist/esm/package.json +3 -0
  292. package/dist/node_modules/tar/dist/esm/parse.js +651 -0
  293. package/dist/node_modules/tar/dist/esm/path-reservations.js +166 -0
  294. package/dist/node_modules/tar/dist/esm/pax.js +178 -0
  295. package/dist/node_modules/tar/dist/esm/process-umask.js +3 -0
  296. package/dist/node_modules/tar/dist/esm/read-entry.js +132 -0
  297. package/dist/node_modules/tar/dist/esm/replace.js +221 -0
  298. package/dist/node_modules/tar/dist/esm/strip-absolute-path.js +25 -0
  299. package/dist/node_modules/tar/dist/esm/strip-trailing-slashes.js +14 -0
  300. package/dist/node_modules/tar/dist/esm/symlink-error.js +15 -0
  301. package/dist/node_modules/tar/dist/esm/types.js +65 -0
  302. package/dist/node_modules/tar/dist/esm/unpack.js +891 -0
  303. package/dist/node_modules/tar/dist/esm/update.js +30 -0
  304. package/dist/node_modules/tar/dist/esm/warn-method.js +27 -0
  305. package/dist/node_modules/tar/dist/esm/winchars.js +9 -0
  306. package/dist/node_modules/tar/dist/esm/write-entry.js +656 -0
  307. package/dist/node_modules/tar/package.json +298 -0
  308. package/dist/node_modules/tinyglobby/LICENSE +21 -0
  309. package/dist/node_modules/tinyglobby/dist/index.cjs +335 -0
  310. package/dist/node_modules/tinyglobby/dist/index.d.cts +148 -0
  311. package/dist/node_modules/tinyglobby/dist/index.d.mts +148 -0
  312. package/dist/node_modules/tinyglobby/dist/index.mjs +307 -0
  313. package/dist/node_modules/tinyglobby/package.json +70 -0
  314. package/dist/node_modules/undici/LICENSE +21 -0
  315. package/dist/node_modules/undici/index-fetch.js +35 -0
  316. package/dist/node_modules/undici/index.js +169 -0
  317. package/dist/node_modules/undici/lib/api/abort-signal.js +57 -0
  318. package/dist/node_modules/undici/lib/api/api-connect.js +108 -0
  319. package/dist/node_modules/undici/lib/api/api-pipeline.js +251 -0
  320. package/dist/node_modules/undici/lib/api/api-request.js +214 -0
  321. package/dist/node_modules/undici/lib/api/api-stream.js +220 -0
  322. package/dist/node_modules/undici/lib/api/api-upgrade.js +108 -0
  323. package/dist/node_modules/undici/lib/api/index.js +7 -0
  324. package/dist/node_modules/undici/lib/api/readable.js +385 -0
  325. package/dist/node_modules/undici/lib/api/util.js +93 -0
  326. package/dist/node_modules/undici/lib/core/connect.js +240 -0
  327. package/dist/node_modules/undici/lib/core/constants.js +118 -0
  328. package/dist/node_modules/undici/lib/core/diagnostics.js +202 -0
  329. package/dist/node_modules/undici/lib/core/errors.js +425 -0
  330. package/dist/node_modules/undici/lib/core/request.js +405 -0
  331. package/dist/node_modules/undici/lib/core/symbols.js +67 -0
  332. package/dist/node_modules/undici/lib/core/tree.js +152 -0
  333. package/dist/node_modules/undici/lib/core/util.js +719 -0
  334. package/dist/node_modules/undici/lib/dispatcher/agent.js +129 -0
  335. package/dist/node_modules/undici/lib/dispatcher/balanced-pool.js +209 -0
  336. package/dist/node_modules/undici/lib/dispatcher/client-h1.js +1487 -0
  337. package/dist/node_modules/undici/lib/dispatcher/client-h2.js +744 -0
  338. package/dist/node_modules/undici/lib/dispatcher/client.js +623 -0
  339. package/dist/node_modules/undici/lib/dispatcher/dispatcher-base.js +199 -0
  340. package/dist/node_modules/undici/lib/dispatcher/dispatcher.js +65 -0
  341. package/dist/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +160 -0
  342. package/dist/node_modules/undici/lib/dispatcher/fixed-queue.js +117 -0
  343. package/dist/node_modules/undici/lib/dispatcher/pool-base.js +194 -0
  344. package/dist/node_modules/undici/lib/dispatcher/pool-stats.js +34 -0
  345. package/dist/node_modules/undici/lib/dispatcher/pool.js +107 -0
  346. package/dist/node_modules/undici/lib/dispatcher/proxy-agent.js +274 -0
  347. package/dist/node_modules/undici/lib/dispatcher/retry-agent.js +35 -0
  348. package/dist/node_modules/undici/lib/global.js +32 -0
  349. package/dist/node_modules/undici/lib/handler/decorator-handler.js +44 -0
  350. package/dist/node_modules/undici/lib/handler/redirect-handler.js +232 -0
  351. package/dist/node_modules/undici/lib/handler/retry-handler.js +374 -0
  352. package/dist/node_modules/undici/lib/interceptor/dns.js +375 -0
  353. package/dist/node_modules/undici/lib/interceptor/dump.js +123 -0
  354. package/dist/node_modules/undici/lib/interceptor/redirect-interceptor.js +21 -0
  355. package/dist/node_modules/undici/lib/interceptor/redirect.js +24 -0
  356. package/dist/node_modules/undici/lib/interceptor/response-error.js +86 -0
  357. package/dist/node_modules/undici/lib/interceptor/retry.js +19 -0
  358. package/dist/node_modules/undici/lib/llhttp/.gitkeep +0 -0
  359. package/dist/node_modules/undici/lib/llhttp/constants.js +278 -0
  360. package/dist/node_modules/undici/lib/llhttp/llhttp-wasm.js +5 -0
  361. package/dist/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +5 -0
  362. package/dist/node_modules/undici/lib/llhttp/utils.js +15 -0
  363. package/dist/node_modules/undici/lib/mock/mock-agent.js +160 -0
  364. package/dist/node_modules/undici/lib/mock/mock-client.js +59 -0
  365. package/dist/node_modules/undici/lib/mock/mock-errors.js +28 -0
  366. package/dist/node_modules/undici/lib/mock/mock-interceptor.js +207 -0
  367. package/dist/node_modules/undici/lib/mock/mock-pool.js +59 -0
  368. package/dist/node_modules/undici/lib/mock/mock-symbols.js +23 -0
  369. package/dist/node_modules/undici/lib/mock/mock-utils.js +367 -0
  370. package/dist/node_modules/undici/lib/mock/pending-interceptors-formatter.js +43 -0
  371. package/dist/node_modules/undici/lib/mock/pluralizer.js +29 -0
  372. package/dist/node_modules/undici/lib/util/timers.js +423 -0
  373. package/dist/node_modules/undici/lib/web/cache/cache.js +859 -0
  374. package/dist/node_modules/undici/lib/web/cache/cachestorage.js +152 -0
  375. package/dist/node_modules/undici/lib/web/cache/symbols.js +5 -0
  376. package/dist/node_modules/undici/lib/web/cache/util.js +45 -0
  377. package/dist/node_modules/undici/lib/web/cookies/constants.js +12 -0
  378. package/dist/node_modules/undici/lib/web/cookies/index.js +184 -0
  379. package/dist/node_modules/undici/lib/web/cookies/parse.js +310 -0
  380. package/dist/node_modules/undici/lib/web/cookies/util.js +282 -0
  381. package/dist/node_modules/undici/lib/web/eventsource/eventsource-stream.js +398 -0
  382. package/dist/node_modules/undici/lib/web/eventsource/eventsource.js +480 -0
  383. package/dist/node_modules/undici/lib/web/eventsource/util.js +37 -0
  384. package/dist/node_modules/undici/lib/web/fetch/LICENSE +21 -0
  385. package/dist/node_modules/undici/lib/web/fetch/body.js +529 -0
  386. package/dist/node_modules/undici/lib/web/fetch/constants.js +124 -0
  387. package/dist/node_modules/undici/lib/web/fetch/data-url.js +744 -0
  388. package/dist/node_modules/undici/lib/web/fetch/dispatcher-weakref.js +46 -0
  389. package/dist/node_modules/undici/lib/web/fetch/file.js +126 -0
  390. package/dist/node_modules/undici/lib/web/fetch/formdata-parser.js +474 -0
  391. package/dist/node_modules/undici/lib/web/fetch/formdata.js +252 -0
  392. package/dist/node_modules/undici/lib/web/fetch/global.js +40 -0
  393. package/dist/node_modules/undici/lib/web/fetch/headers.js +687 -0
  394. package/dist/node_modules/undici/lib/web/fetch/index.js +2272 -0
  395. package/dist/node_modules/undici/lib/web/fetch/request.js +1037 -0
  396. package/dist/node_modules/undici/lib/web/fetch/response.js +610 -0
  397. package/dist/node_modules/undici/lib/web/fetch/symbols.js +9 -0
  398. package/dist/node_modules/undici/lib/web/fetch/util.js +1632 -0
  399. package/dist/node_modules/undici/lib/web/fetch/webidl.js +695 -0
  400. package/dist/node_modules/undici/lib/web/fileapi/encoding.js +290 -0
  401. package/dist/node_modules/undici/lib/web/fileapi/filereader.js +344 -0
  402. package/dist/node_modules/undici/lib/web/fileapi/progressevent.js +78 -0
  403. package/dist/node_modules/undici/lib/web/fileapi/symbols.js +10 -0
  404. package/dist/node_modules/undici/lib/web/fileapi/util.js +391 -0
  405. package/dist/node_modules/undici/lib/web/websocket/connection.js +371 -0
  406. package/dist/node_modules/undici/lib/web/websocket/constants.js +66 -0
  407. package/dist/node_modules/undici/lib/web/websocket/events.js +329 -0
  408. package/dist/node_modules/undici/lib/web/websocket/frame.js +96 -0
  409. package/dist/node_modules/undici/lib/web/websocket/permessage-deflate.js +100 -0
  410. package/dist/node_modules/undici/lib/web/websocket/receiver.js +513 -0
  411. package/dist/node_modules/undici/lib/web/websocket/sender.js +104 -0
  412. package/dist/node_modules/undici/lib/web/websocket/symbols.js +12 -0
  413. package/dist/node_modules/undici/lib/web/websocket/util.js +322 -0
  414. package/dist/node_modules/undici/lib/web/websocket/websocket.js +595 -0
  415. package/dist/node_modules/undici/package.json +160 -0
  416. package/dist/node_modules/undici/scripts/strip-comments.js +8 -0
  417. package/{LICENSE → dist/node_modules/v8-compile-cache/LICENSE} +1 -2
  418. package/dist/node_modules/v8-compile-cache/package.json +34 -0
  419. package/dist/node_modules/v8-compile-cache/v8-compile-cache.js +373 -0
  420. package/dist/node_modules/which/LICENSE +15 -0
  421. package/dist/node_modules/which/bin/which.js +52 -0
  422. package/dist/node_modules/which/lib/index.js +111 -0
  423. package/dist/node_modules/which/package.json +52 -0
  424. package/dist/node_modules/yallist/dist/commonjs/index.js +384 -0
  425. package/dist/node_modules/yallist/dist/commonjs/package.json +3 -0
  426. package/dist/node_modules/yallist/dist/esm/index.js +379 -0
  427. package/dist/node_modules/yallist/dist/esm/package.json +3 -0
  428. package/dist/node_modules/yallist/package.json +68 -0
  429. package/dist/pnpm.mjs +311237 -0
  430. package/dist/pnpmrc +2 -0
  431. package/dist/templates/completion.bash +31 -0
  432. package/dist/templates/completion.fish +22 -0
  433. package/dist/templates/completion.ps1 +193 -0
  434. package/dist/templates/completion.zsh +27 -0
  435. package/dist/vendor/fastlist-0.3.0-x64.exe +0 -0
  436. package/dist/vendor/fastlist-0.3.0-x86.exe +0 -0
  437. package/dist/worker.js +11941 -0
  438. package/package.json +12 -12
  439. package/pn.cmd +2 -0
  440. package/pn.ps1 +1 -0
  441. package/pnpx.cmd +2 -0
  442. package/pnpx.ps1 +1 -0
  443. package/pnx.cmd +2 -0
  444. package/pnx.ps1 +1 -0
@@ -0,0 +1,1487 @@
1
+ 'use strict'
2
+
3
+ /* global WebAssembly */
4
+
5
+ const assert = require('node:assert')
6
+ const util = require('../core/util.js')
7
+ const { channels } = require('../core/diagnostics.js')
8
+ const timers = require('../util/timers.js')
9
+ const {
10
+ RequestContentLengthMismatchError,
11
+ ResponseContentLengthMismatchError,
12
+ RequestAbortedError,
13
+ HeadersTimeoutError,
14
+ HeadersOverflowError,
15
+ SocketError,
16
+ InformationalError,
17
+ BodyTimeoutError,
18
+ HTTPParserError,
19
+ ResponseExceededMaxSizeError
20
+ } = require('../core/errors.js')
21
+ const {
22
+ kUrl,
23
+ kReset,
24
+ kClient,
25
+ kParser,
26
+ kBlocking,
27
+ kRunning,
28
+ kPending,
29
+ kSize,
30
+ kWriting,
31
+ kQueue,
32
+ kNoRef,
33
+ kKeepAliveDefaultTimeout,
34
+ kHostHeader,
35
+ kPendingIdx,
36
+ kRunningIdx,
37
+ kError,
38
+ kPipelining,
39
+ kSocket,
40
+ kKeepAliveTimeoutValue,
41
+ kMaxHeadersSize,
42
+ kKeepAliveMaxTimeout,
43
+ kKeepAliveTimeoutThreshold,
44
+ kHeadersTimeout,
45
+ kBodyTimeout,
46
+ kStrictContentLength,
47
+ kMaxRequests,
48
+ kCounter,
49
+ kMaxResponseSize,
50
+ kOnError,
51
+ kResume,
52
+ kHTTPContext
53
+ } = require('../core/symbols.js')
54
+
55
+ const constants = require('../llhttp/constants.js')
56
+ const EMPTY_BUF = Buffer.alloc(0)
57
+ const FastBuffer = Buffer[Symbol.species]
58
+ const addListener = util.addListener
59
+ const removeAllListeners = util.removeAllListeners
60
+ const kIdleSocketValidation = Symbol('kIdleSocketValidation')
61
+ const kIdleSocketValidationTimeout = Symbol('kIdleSocketValidationTimeout')
62
+ const kSocketUsed = Symbol('kSocketUsed')
63
+
64
+ let extractBody
65
+
66
+ async function lazyllhttp () {
67
+ const llhttpWasmData = process.env.JEST_WORKER_ID ? require('../llhttp/llhttp-wasm.js') : undefined
68
+
69
+ let mod
70
+ try {
71
+ mod = await WebAssembly.compile(require('../llhttp/llhttp_simd-wasm.js'))
72
+ } catch (e) {
73
+ /* istanbul ignore next */
74
+
75
+ // We could check if the error was caused by the simd option not
76
+ // being enabled, but the occurring of this other error
77
+ // * https://github.com/emscripten-core/emscripten/issues/11495
78
+ // got me to remove that check to avoid breaking Node 12.
79
+ mod = await WebAssembly.compile(llhttpWasmData || require('../llhttp/llhttp-wasm.js'))
80
+ }
81
+
82
+ return await WebAssembly.instantiate(mod, {
83
+ env: {
84
+ /* eslint-disable camelcase */
85
+
86
+ wasm_on_url: (p, at, len) => {
87
+ /* istanbul ignore next */
88
+ return 0
89
+ },
90
+ wasm_on_status: (p, at, len) => {
91
+ assert(currentParser.ptr === p)
92
+ const start = at - currentBufferPtr + currentBufferRef.byteOffset
93
+ return currentParser.onStatus(new FastBuffer(currentBufferRef.buffer, start, len)) || 0
94
+ },
95
+ wasm_on_message_begin: (p) => {
96
+ assert(currentParser.ptr === p)
97
+ return currentParser.onMessageBegin() || 0
98
+ },
99
+ wasm_on_header_field: (p, at, len) => {
100
+ assert(currentParser.ptr === p)
101
+ const start = at - currentBufferPtr + currentBufferRef.byteOffset
102
+ return currentParser.onHeaderField(new FastBuffer(currentBufferRef.buffer, start, len)) || 0
103
+ },
104
+ wasm_on_header_value: (p, at, len) => {
105
+ assert(currentParser.ptr === p)
106
+ const start = at - currentBufferPtr + currentBufferRef.byteOffset
107
+ return currentParser.onHeaderValue(new FastBuffer(currentBufferRef.buffer, start, len)) || 0
108
+ },
109
+ wasm_on_headers_complete: (p, statusCode, upgrade, shouldKeepAlive) => {
110
+ assert(currentParser.ptr === p)
111
+ return currentParser.onHeadersComplete(statusCode, Boolean(upgrade), Boolean(shouldKeepAlive)) || 0
112
+ },
113
+ wasm_on_body: (p, at, len) => {
114
+ assert(currentParser.ptr === p)
115
+ const start = at - currentBufferPtr + currentBufferRef.byteOffset
116
+ return currentParser.onBody(new FastBuffer(currentBufferRef.buffer, start, len)) || 0
117
+ },
118
+ wasm_on_message_complete: (p) => {
119
+ assert(currentParser.ptr === p)
120
+ return currentParser.onMessageComplete() || 0
121
+ }
122
+
123
+ /* eslint-enable camelcase */
124
+ }
125
+ })
126
+ }
127
+
128
+ let llhttpInstance = null
129
+ let llhttpPromise = lazyllhttp()
130
+ llhttpPromise.catch()
131
+
132
+ let currentParser = null
133
+ let currentBufferRef = null
134
+ let currentBufferSize = 0
135
+ let currentBufferPtr = null
136
+
137
+ const USE_NATIVE_TIMER = 0
138
+ const USE_FAST_TIMER = 1
139
+
140
+ // Use fast timers for headers and body to take eventual event loop
141
+ // latency into account.
142
+ const TIMEOUT_HEADERS = 2 | USE_FAST_TIMER
143
+ const TIMEOUT_BODY = 4 | USE_FAST_TIMER
144
+
145
+ // Use native timers to ignore event loop latency for keep-alive
146
+ // handling.
147
+ const TIMEOUT_KEEP_ALIVE = 8 | USE_NATIVE_TIMER
148
+
149
+ class Parser {
150
+ constructor (client, socket, { exports }) {
151
+ assert(Number.isFinite(client[kMaxHeadersSize]) && client[kMaxHeadersSize] > 0)
152
+
153
+ this.llhttp = exports
154
+ this.ptr = this.llhttp.llhttp_alloc(constants.TYPE.RESPONSE)
155
+ this.client = client
156
+ this.socket = socket
157
+ this.timeout = null
158
+ this.timeoutValue = null
159
+ this.timeoutType = null
160
+ this.statusCode = null
161
+ this.statusText = ''
162
+ this.upgrade = false
163
+ this.headers = []
164
+ this.headersSize = 0
165
+ this.headersMaxSize = client[kMaxHeadersSize]
166
+ this.shouldKeepAlive = false
167
+ this.paused = false
168
+ this.resume = this.resume.bind(this)
169
+
170
+ this.bytesRead = 0
171
+
172
+ this.keepAlive = ''
173
+ this.contentLength = ''
174
+ this.connection = ''
175
+ this.maxResponseSize = client[kMaxResponseSize]
176
+ }
177
+
178
+ setTimeout (delay, type) {
179
+ // If the existing timer and the new timer are of different timer type
180
+ // (fast or native) or have different delay, we need to clear the existing
181
+ // timer and set a new one.
182
+ if (
183
+ delay !== this.timeoutValue ||
184
+ (type & USE_FAST_TIMER) ^ (this.timeoutType & USE_FAST_TIMER)
185
+ ) {
186
+ // If a timeout is already set, clear it with clearTimeout of the fast
187
+ // timer implementation, as it can clear fast and native timers.
188
+ if (this.timeout) {
189
+ timers.clearTimeout(this.timeout)
190
+ this.timeout = null
191
+ }
192
+
193
+ if (delay) {
194
+ if (type & USE_FAST_TIMER) {
195
+ this.timeout = timers.setFastTimeout(onParserTimeout, delay, new WeakRef(this))
196
+ } else {
197
+ this.timeout = setTimeout(onParserTimeout, delay, new WeakRef(this))
198
+ this.timeout.unref()
199
+ }
200
+ }
201
+
202
+ this.timeoutValue = delay
203
+ } else if (this.timeout) {
204
+ // istanbul ignore else: only for jest
205
+ if (this.timeout.refresh) {
206
+ this.timeout.refresh()
207
+ }
208
+ }
209
+
210
+ this.timeoutType = type
211
+ }
212
+
213
+ resume () {
214
+ if (this.socket.destroyed || !this.paused) {
215
+ return
216
+ }
217
+
218
+ assert(this.ptr != null)
219
+ assert(currentParser == null)
220
+
221
+ this.llhttp.llhttp_resume(this.ptr)
222
+
223
+ assert(this.timeoutType === TIMEOUT_BODY)
224
+ if (this.timeout) {
225
+ // istanbul ignore else: only for jest
226
+ if (this.timeout.refresh) {
227
+ this.timeout.refresh()
228
+ }
229
+ }
230
+
231
+ this.paused = false
232
+ this.execute(this.socket.read() || EMPTY_BUF) // Flush parser.
233
+ this.readMore()
234
+ }
235
+
236
+ readMore () {
237
+ while (!this.paused && this.ptr) {
238
+ const chunk = this.socket.read()
239
+ if (chunk === null) {
240
+ break
241
+ }
242
+ this.execute(chunk)
243
+ }
244
+ }
245
+
246
+ execute (data) {
247
+ assert(this.ptr != null)
248
+ assert(currentParser == null)
249
+ assert(!this.paused)
250
+
251
+ const { socket, llhttp } = this
252
+
253
+ if (data.length > currentBufferSize) {
254
+ if (currentBufferPtr) {
255
+ llhttp.free(currentBufferPtr)
256
+ }
257
+ currentBufferSize = Math.ceil(data.length / 4096) * 4096
258
+ currentBufferPtr = llhttp.malloc(currentBufferSize)
259
+ }
260
+
261
+ new Uint8Array(llhttp.memory.buffer, currentBufferPtr, currentBufferSize).set(data)
262
+
263
+ // Call `execute` on the wasm parser.
264
+ // We pass the `llhttp_parser` pointer address, the pointer address of buffer view data,
265
+ // and finally the length of bytes to parse.
266
+ // The return value is an error code or `constants.ERROR.OK`.
267
+ try {
268
+ let ret
269
+
270
+ try {
271
+ currentBufferRef = data
272
+ currentParser = this
273
+ ret = llhttp.llhttp_execute(this.ptr, currentBufferPtr, data.length)
274
+ /* eslint-disable-next-line no-useless-catch */
275
+ } catch (err) {
276
+ /* istanbul ignore next: difficult to make a test case for */
277
+ throw err
278
+ } finally {
279
+ currentParser = null
280
+ currentBufferRef = null
281
+ }
282
+
283
+ const offset = llhttp.llhttp_get_error_pos(this.ptr) - currentBufferPtr
284
+
285
+ if (ret !== constants.ERROR.OK) {
286
+ const body = data.subarray(offset)
287
+
288
+ if (ret === constants.ERROR.PAUSED_UPGRADE) {
289
+ this.onUpgrade(body)
290
+ } else if (ret === constants.ERROR.PAUSED) {
291
+ this.paused = true
292
+ socket.unshift(body)
293
+ } else {
294
+ throw this.createError(ret, body)
295
+ }
296
+ }
297
+ } catch (err) {
298
+ util.destroy(socket, err)
299
+ }
300
+ }
301
+
302
+ finish () {
303
+ assert(currentParser === null)
304
+ assert(this.ptr != null)
305
+ assert(!this.paused)
306
+
307
+ const { llhttp } = this
308
+
309
+ let ret
310
+
311
+ try {
312
+ currentParser = this
313
+ ret = llhttp.llhttp_finish(this.ptr)
314
+ } finally {
315
+ currentParser = null
316
+ }
317
+
318
+ if (ret === constants.ERROR.OK) {
319
+ return null
320
+ }
321
+
322
+ if (ret === constants.ERROR.PAUSED || ret === constants.ERROR.PAUSED_UPGRADE) {
323
+ this.paused = true
324
+ return null
325
+ }
326
+
327
+ return this.createError(ret, EMPTY_BUF)
328
+ }
329
+
330
+ createError (ret, data) {
331
+ const { llhttp, contentLength, bytesRead } = this
332
+
333
+ if (contentLength && bytesRead !== parseInt(contentLength, 10)) {
334
+ return new ResponseContentLengthMismatchError()
335
+ }
336
+
337
+ const ptr = llhttp.llhttp_get_error_reason(this.ptr)
338
+ let message = ''
339
+ if (ptr) {
340
+ const len = new Uint8Array(llhttp.memory.buffer, ptr).indexOf(0)
341
+ message =
342
+ 'Response does not match the HTTP/1.1 protocol (' +
343
+ Buffer.from(llhttp.memory.buffer, ptr, len).toString() +
344
+ ')'
345
+ }
346
+
347
+ return new HTTPParserError(message, constants.ERROR[ret], data)
348
+ }
349
+
350
+ destroy () {
351
+ assert(this.ptr != null)
352
+ assert(currentParser == null)
353
+
354
+ this.llhttp.llhttp_free(this.ptr)
355
+ this.ptr = null
356
+
357
+ this.timeout && timers.clearTimeout(this.timeout)
358
+ this.timeout = null
359
+ this.timeoutValue = null
360
+ this.timeoutType = null
361
+
362
+ this.paused = false
363
+ }
364
+
365
+ onStatus (buf) {
366
+ this.statusText = buf.toString()
367
+ }
368
+
369
+ onMessageBegin () {
370
+ const { socket, client } = this
371
+
372
+ /* istanbul ignore next: difficult to make a test case for */
373
+ if (socket.destroyed) {
374
+ return -1
375
+ }
376
+
377
+ if (client[kRunning] === 0) {
378
+ util.destroy(socket, new SocketError('bad response', util.getSocketInfo(socket)))
379
+ return -1
380
+ }
381
+
382
+ const request = client[kQueue][client[kRunningIdx]]
383
+ if (!request) {
384
+ return -1
385
+ }
386
+ request.onResponseStarted()
387
+ }
388
+
389
+ onHeaderField (buf) {
390
+ const len = this.headers.length
391
+
392
+ if ((len & 1) === 0) {
393
+ this.headers.push(buf)
394
+ } else {
395
+ this.headers[len - 1] = Buffer.concat([this.headers[len - 1], buf])
396
+ }
397
+
398
+ this.trackHeader(buf.length)
399
+ }
400
+
401
+ onHeaderValue (buf) {
402
+ let len = this.headers.length
403
+
404
+ if ((len & 1) === 1) {
405
+ this.headers.push(buf)
406
+ len += 1
407
+ } else {
408
+ this.headers[len - 1] = Buffer.concat([this.headers[len - 1], buf])
409
+ }
410
+
411
+ const key = this.headers[len - 2]
412
+ if (key.length === 10) {
413
+ const headerName = util.bufferToLowerCasedHeaderName(key)
414
+ if (headerName === 'keep-alive') {
415
+ this.keepAlive += buf.toString()
416
+ } else if (headerName === 'connection') {
417
+ this.connection += buf.toString()
418
+ }
419
+ } else if (key.length === 14 && util.bufferToLowerCasedHeaderName(key) === 'content-length') {
420
+ this.contentLength += buf.toString()
421
+ }
422
+
423
+ this.trackHeader(buf.length)
424
+ }
425
+
426
+ trackHeader (len) {
427
+ this.headersSize += len
428
+ if (this.headersSize >= this.headersMaxSize) {
429
+ util.destroy(this.socket, new HeadersOverflowError())
430
+ }
431
+ }
432
+
433
+ onUpgrade (head) {
434
+ const { upgrade, client, socket, headers, statusCode } = this
435
+
436
+ assert(upgrade)
437
+ assert(client[kSocket] === socket)
438
+ assert(!socket.destroyed)
439
+ assert(!this.paused)
440
+ assert((headers.length & 1) === 0)
441
+
442
+ const request = client[kQueue][client[kRunningIdx]]
443
+ assert(request)
444
+ assert(request.upgrade || request.method === 'CONNECT')
445
+
446
+ this.statusCode = null
447
+ this.statusText = ''
448
+ this.shouldKeepAlive = null
449
+
450
+ this.headers = []
451
+ this.headersSize = 0
452
+
453
+ socket.unshift(head)
454
+
455
+ socket[kParser].destroy()
456
+ socket[kParser] = null
457
+
458
+ socket[kClient] = null
459
+ socket[kError] = null
460
+
461
+ removeAllListeners(socket)
462
+
463
+ client[kSocket] = null
464
+ client[kHTTPContext] = null // TODO (fix): This is hacky...
465
+ client[kQueue][client[kRunningIdx]++] = null
466
+ client.emit('disconnect', client[kUrl], [client], new InformationalError('upgrade'))
467
+
468
+ try {
469
+ request.onUpgrade(statusCode, headers, socket)
470
+ } catch (err) {
471
+ util.destroy(socket, err)
472
+ }
473
+
474
+ client[kResume]()
475
+ }
476
+
477
+ onHeadersComplete (statusCode, upgrade, shouldKeepAlive) {
478
+ const { client, socket, headers, statusText } = this
479
+
480
+ /* istanbul ignore next: difficult to make a test case for */
481
+ if (socket.destroyed) {
482
+ return -1
483
+ }
484
+
485
+ if (client[kRunning] === 0) {
486
+ util.destroy(socket, new SocketError('bad response', util.getSocketInfo(socket)))
487
+ return -1
488
+ }
489
+
490
+ const request = client[kQueue][client[kRunningIdx]]
491
+
492
+ /* istanbul ignore next: difficult to make a test case for */
493
+ if (!request) {
494
+ return -1
495
+ }
496
+
497
+ assert(!this.upgrade)
498
+ assert(this.statusCode < 200)
499
+
500
+ if (statusCode === 100) {
501
+ util.destroy(socket, new SocketError('bad response', util.getSocketInfo(socket)))
502
+ return -1
503
+ }
504
+
505
+ /* this can only happen if server is misbehaving */
506
+ if (upgrade && !request.upgrade) {
507
+ util.destroy(socket, new SocketError('bad upgrade', util.getSocketInfo(socket)))
508
+ return -1
509
+ }
510
+
511
+ assert(this.timeoutType === TIMEOUT_HEADERS)
512
+
513
+ this.statusCode = statusCode
514
+ this.shouldKeepAlive = (
515
+ shouldKeepAlive ||
516
+ // Override llhttp value which does not allow keepAlive for HEAD.
517
+ (request.method === 'HEAD' && !socket[kReset] && this.connection.toLowerCase() === 'keep-alive')
518
+ )
519
+
520
+ if (this.statusCode >= 200) {
521
+ const bodyTimeout = request.bodyTimeout != null
522
+ ? request.bodyTimeout
523
+ : client[kBodyTimeout]
524
+ this.setTimeout(bodyTimeout, TIMEOUT_BODY)
525
+ } else if (this.timeout) {
526
+ // istanbul ignore else: only for jest
527
+ if (this.timeout.refresh) {
528
+ this.timeout.refresh()
529
+ }
530
+ }
531
+
532
+ if (request.method === 'CONNECT') {
533
+ assert(client[kRunning] === 1)
534
+ this.upgrade = true
535
+ return 2
536
+ }
537
+
538
+ if (upgrade) {
539
+ assert(client[kRunning] === 1)
540
+ this.upgrade = true
541
+ return 2
542
+ }
543
+
544
+ assert((this.headers.length & 1) === 0)
545
+ this.headers = []
546
+ this.headersSize = 0
547
+
548
+ if (this.shouldKeepAlive && client[kPipelining]) {
549
+ const keepAliveTimeout = this.keepAlive ? util.parseKeepAliveTimeout(this.keepAlive) : null
550
+
551
+ if (keepAliveTimeout != null) {
552
+ const timeout = Math.min(
553
+ keepAliveTimeout - client[kKeepAliveTimeoutThreshold],
554
+ client[kKeepAliveMaxTimeout]
555
+ )
556
+ if (timeout <= 0) {
557
+ socket[kReset] = true
558
+ } else {
559
+ client[kKeepAliveTimeoutValue] = timeout
560
+ }
561
+ } else {
562
+ client[kKeepAliveTimeoutValue] = client[kKeepAliveDefaultTimeout]
563
+ }
564
+ } else {
565
+ // Stop more requests from being dispatched.
566
+ socket[kReset] = true
567
+ }
568
+
569
+ const pause = request.onHeaders(statusCode, headers, this.resume, statusText) === false
570
+
571
+ if (request.aborted) {
572
+ return -1
573
+ }
574
+
575
+ if (request.method === 'HEAD') {
576
+ return 1
577
+ }
578
+
579
+ if (statusCode < 200) {
580
+ return 1
581
+ }
582
+
583
+ if (socket[kBlocking]) {
584
+ socket[kBlocking] = false
585
+ client[kResume]()
586
+ }
587
+
588
+ return pause ? constants.ERROR.PAUSED : 0
589
+ }
590
+
591
+ onBody (buf) {
592
+ const { client, socket, statusCode, maxResponseSize } = this
593
+
594
+ if (socket.destroyed) {
595
+ return -1
596
+ }
597
+
598
+ const request = client[kQueue][client[kRunningIdx]]
599
+ assert(request)
600
+
601
+ assert(this.timeoutType === TIMEOUT_BODY)
602
+ if (this.timeout) {
603
+ // istanbul ignore else: only for jest
604
+ if (this.timeout.refresh) {
605
+ this.timeout.refresh()
606
+ }
607
+ }
608
+
609
+ assert(statusCode >= 200)
610
+
611
+ if (maxResponseSize > -1 && this.bytesRead + buf.length > maxResponseSize) {
612
+ util.destroy(socket, new ResponseExceededMaxSizeError())
613
+ return -1
614
+ }
615
+
616
+ this.bytesRead += buf.length
617
+
618
+ if (request.onData(buf) === false) {
619
+ return constants.ERROR.PAUSED
620
+ }
621
+ }
622
+
623
+ onMessageComplete () {
624
+ const { client, socket, statusCode, upgrade, headers, contentLength, bytesRead, shouldKeepAlive } = this
625
+
626
+ if (socket.destroyed && (!statusCode || shouldKeepAlive)) {
627
+ return -1
628
+ }
629
+
630
+ if (upgrade) {
631
+ return
632
+ }
633
+
634
+ assert(statusCode >= 100)
635
+ assert((this.headers.length & 1) === 0)
636
+
637
+ const request = client[kQueue][client[kRunningIdx]]
638
+ assert(request)
639
+
640
+ this.statusCode = null
641
+ this.statusText = ''
642
+ this.bytesRead = 0
643
+ this.contentLength = ''
644
+ this.keepAlive = ''
645
+ this.connection = ''
646
+
647
+ this.headers = []
648
+ this.headersSize = 0
649
+
650
+ if (statusCode < 200) {
651
+ return
652
+ }
653
+
654
+ /* istanbul ignore next: should be handled by llhttp? */
655
+ if (request.method !== 'HEAD' && contentLength && bytesRead !== parseInt(contentLength, 10)) {
656
+ util.destroy(socket, new ResponseContentLengthMismatchError())
657
+ return -1
658
+ }
659
+
660
+ request.onComplete(headers)
661
+
662
+ client[kQueue][client[kRunningIdx]++] = null
663
+ socket[kSocketUsed] = true
664
+
665
+ if (socket[kWriting]) {
666
+ assert(client[kRunning] === 0)
667
+ // Response completed before request.
668
+ util.destroy(socket, new InformationalError('reset'))
669
+ return constants.ERROR.PAUSED
670
+ } else if (!shouldKeepAlive) {
671
+ util.destroy(socket, new InformationalError('reset'))
672
+ return constants.ERROR.PAUSED
673
+ } else if (socket[kReset] && client[kRunning] === 0) {
674
+ // Destroy socket once all requests have completed.
675
+ // The request at the tail of the pipeline is the one
676
+ // that requested reset and no further requests should
677
+ // have been queued since then.
678
+ util.destroy(socket, new InformationalError('reset'))
679
+ return constants.ERROR.PAUSED
680
+ } else if (client[kPipelining] == null || client[kPipelining] === 1) {
681
+ // We must wait a full event loop cycle to reuse this socket to make sure
682
+ // that non-spec compliant servers are not closing the connection even if they
683
+ // said they won't.
684
+ setImmediate(() => client[kResume]())
685
+ } else {
686
+ client[kResume]()
687
+ }
688
+ }
689
+ }
690
+
691
+ function onParserTimeout (parser) {
692
+ const { socket, timeoutType, client, paused } = parser.deref()
693
+
694
+ /* istanbul ignore else */
695
+ if (timeoutType === TIMEOUT_HEADERS) {
696
+ if (!socket[kWriting] || socket.writableNeedDrain || client[kRunning] > 1) {
697
+ assert(!paused, 'cannot be paused while waiting for headers')
698
+ util.destroy(socket, new HeadersTimeoutError())
699
+ }
700
+ } else if (timeoutType === TIMEOUT_BODY) {
701
+ if (!paused) {
702
+ util.destroy(socket, new BodyTimeoutError())
703
+ }
704
+ } else if (timeoutType === TIMEOUT_KEEP_ALIVE) {
705
+ assert(client[kRunning] === 0 && client[kKeepAliveTimeoutValue])
706
+ util.destroy(socket, new InformationalError('socket idle timeout'))
707
+ }
708
+ }
709
+
710
+ async function connectH1 (client, socket) {
711
+ client[kSocket] = socket
712
+
713
+ if (!llhttpInstance) {
714
+ llhttpInstance = await llhttpPromise
715
+ llhttpPromise = null
716
+ }
717
+
718
+ socket[kNoRef] = false
719
+ socket[kWriting] = false
720
+ socket[kReset] = false
721
+ socket[kBlocking] = false
722
+ socket[kIdleSocketValidation] = 0
723
+ socket[kIdleSocketValidationTimeout] = null
724
+ socket[kSocketUsed] = false
725
+ socket[kParser] = new Parser(client, socket, llhttpInstance)
726
+
727
+ addListener(socket, 'error', function (err) {
728
+ assert(err.code !== 'ERR_TLS_CERT_ALTNAME_INVALID')
729
+
730
+ const parser = this[kParser]
731
+
732
+ // On Mac OS, we get an ECONNRESET even if there is a full body to be forwarded
733
+ // to the user.
734
+ if (err.code === 'ECONNRESET' && parser.statusCode && !parser.shouldKeepAlive) {
735
+ const parserErr = parser.finish()
736
+ if (parserErr) {
737
+ this[kError] = parserErr
738
+ this[kClient][kOnError](parserErr)
739
+ }
740
+ return
741
+ }
742
+
743
+ this[kError] = err
744
+
745
+ this[kClient][kOnError](err)
746
+ })
747
+ addListener(socket, 'readable', function () {
748
+ const parser = this[kParser]
749
+
750
+ if (parser) {
751
+ parser.readMore()
752
+ }
753
+ })
754
+ addListener(socket, 'end', function () {
755
+ const parser = this[kParser]
756
+
757
+ if (parser.statusCode && !parser.shouldKeepAlive) {
758
+ const parserErr = parser.finish()
759
+ if (parserErr) {
760
+ util.destroy(this, parserErr)
761
+ }
762
+ return
763
+ }
764
+
765
+ util.destroy(this, new SocketError('other side closed', util.getSocketInfo(this)))
766
+ })
767
+ addListener(socket, 'close', function () {
768
+ const client = this[kClient]
769
+ const parser = this[kParser]
770
+
771
+ clearIdleSocketValidation(this)
772
+
773
+ if (parser) {
774
+ if (!this[kError] && parser.statusCode && !parser.shouldKeepAlive) {
775
+ this[kError] = parser.finish() || this[kError]
776
+ }
777
+
778
+ this[kParser].destroy()
779
+ this[kParser] = null
780
+ }
781
+
782
+ const err = this[kError] || new SocketError('closed', util.getSocketInfo(this))
783
+
784
+ client[kSocket] = null
785
+ client[kHTTPContext] = null // TODO (fix): This is hacky...
786
+
787
+ if (client.destroyed) {
788
+ assert(client[kPending] === 0)
789
+
790
+ // Fail entire queue.
791
+ const requests = client[kQueue].splice(client[kRunningIdx])
792
+ for (let i = 0; i < requests.length; i++) {
793
+ const request = requests[i]
794
+ util.errorRequest(client, request, err)
795
+ }
796
+ } else if (client[kRunning] > 0 && err.code !== 'UND_ERR_INFO') {
797
+ // Fail head of pipeline.
798
+ const request = client[kQueue][client[kRunningIdx]]
799
+ client[kQueue][client[kRunningIdx]++] = null
800
+
801
+ util.errorRequest(client, request, err)
802
+ }
803
+
804
+ client[kPendingIdx] = client[kRunningIdx]
805
+
806
+ assert(client[kRunning] === 0)
807
+
808
+ client.emit('disconnect', client[kUrl], [client], err)
809
+
810
+ client[kResume]()
811
+ })
812
+
813
+ let closed = false
814
+ socket.on('close', () => {
815
+ closed = true
816
+ })
817
+
818
+ return {
819
+ version: 'h1',
820
+ defaultPipelining: 1,
821
+ write (...args) {
822
+ return writeH1(client, ...args)
823
+ },
824
+ resume () {
825
+ resumeH1(client)
826
+ },
827
+ destroy (err, callback) {
828
+ if (closed) {
829
+ queueMicrotask(callback)
830
+ } else {
831
+ socket.destroy(err).on('close', callback)
832
+ }
833
+ },
834
+ get destroyed () {
835
+ return socket.destroyed
836
+ },
837
+ busy (request) {
838
+ if (socket[kWriting] || socket[kReset] || socket[kBlocking] || socket[kIdleSocketValidation] === 1) {
839
+ return true
840
+ }
841
+
842
+ if (request) {
843
+ if (client[kRunning] > 0 && !request.idempotent) {
844
+ // Non-idempotent request cannot be retried.
845
+ // Ensure that no other requests are inflight and
846
+ // could cause failure.
847
+ return true
848
+ }
849
+
850
+ if (client[kRunning] > 0 && (request.upgrade || request.method === 'CONNECT')) {
851
+ // Don't dispatch an upgrade until all preceding requests have completed.
852
+ // A misbehaving server might upgrade the connection before all pipelined
853
+ // request has completed.
854
+ return true
855
+ }
856
+
857
+ if (client[kRunning] > 0 && util.bodyLength(request.body) !== 0 &&
858
+ (util.isStream(request.body) || util.isAsyncIterable(request.body) || util.isFormDataLike(request.body))) {
859
+ // Request with stream or iterator body can error while other requests
860
+ // are inflight and indirectly error those as well.
861
+ // Ensure this doesn't happen by waiting for inflight
862
+ // to complete before dispatching.
863
+
864
+ // Request with stream or iterator body cannot be retried.
865
+ // Ensure that no other requests are inflight and
866
+ // could cause failure.
867
+ return true
868
+ }
869
+ }
870
+
871
+ return false
872
+ }
873
+ }
874
+ }
875
+
876
+ function clearIdleSocketValidation (socket) {
877
+ if (socket[kIdleSocketValidationTimeout]) {
878
+ clearTimeout(socket[kIdleSocketValidationTimeout])
879
+ socket[kIdleSocketValidationTimeout] = null
880
+ }
881
+
882
+ socket[kIdleSocketValidation] = 0
883
+ }
884
+
885
+ function scheduleIdleSocketValidation (client, socket) {
886
+ socket[kIdleSocketValidation] = 1
887
+ socket[kIdleSocketValidationTimeout] = setTimeout(() => {
888
+ socket[kIdleSocketValidationTimeout] = null
889
+ socket[kIdleSocketValidation] = 2
890
+
891
+ if (client[kSocket] === socket && !socket.destroyed) {
892
+ client[kResume]()
893
+ }
894
+ }, 0)
895
+ socket[kIdleSocketValidationTimeout].unref?.()
896
+ }
897
+
898
+ /**
899
+ * @param {import('./client.js')} client
900
+ */
901
+ function resumeH1 (client) {
902
+ const socket = client[kSocket]
903
+
904
+ if (socket && !socket.destroyed) {
905
+ if (client[kSize] === 0) {
906
+ if (!socket[kNoRef] && socket.unref) {
907
+ socket.unref()
908
+ socket[kNoRef] = true
909
+ }
910
+ } else if (socket[kNoRef] && socket.ref) {
911
+ socket.ref()
912
+ socket[kNoRef] = false
913
+ }
914
+
915
+ if (client[kRunning] === 0 && client[kPending] > 0 && socket[kSocketUsed]) {
916
+ if (socket[kIdleSocketValidation] === 0) {
917
+ scheduleIdleSocketValidation(client, socket)
918
+ socket[kParser].readMore()
919
+ if (socket.destroyed) {
920
+ return
921
+ }
922
+ return
923
+ }
924
+
925
+ if (socket[kIdleSocketValidation] === 1) {
926
+ socket[kParser].readMore()
927
+ if (socket.destroyed) {
928
+ return
929
+ }
930
+ return
931
+ }
932
+ }
933
+
934
+ if (client[kRunning] === 0) {
935
+ socket[kParser].readMore()
936
+ if (socket.destroyed) {
937
+ return
938
+ }
939
+ }
940
+
941
+ if (client[kSize] === 0) {
942
+ if (socket[kParser].timeoutType !== TIMEOUT_KEEP_ALIVE) {
943
+ socket[kParser].setTimeout(client[kKeepAliveTimeoutValue], TIMEOUT_KEEP_ALIVE)
944
+ }
945
+ } else if (client[kRunning] > 0 && socket[kParser].statusCode < 200) {
946
+ if (socket[kParser].timeoutType !== TIMEOUT_HEADERS) {
947
+ const request = client[kQueue][client[kRunningIdx]]
948
+ const headersTimeout = request.headersTimeout != null
949
+ ? request.headersTimeout
950
+ : client[kHeadersTimeout]
951
+ socket[kParser].setTimeout(headersTimeout, TIMEOUT_HEADERS)
952
+ }
953
+ }
954
+ }
955
+ }
956
+
957
+ // https://www.rfc-editor.org/rfc/rfc7230#section-3.3.2
958
+ function shouldSendContentLength (method) {
959
+ return method !== 'GET' && method !== 'HEAD' && method !== 'OPTIONS' && method !== 'TRACE' && method !== 'CONNECT'
960
+ }
961
+
962
+ function writeH1 (client, request) {
963
+ const { method, path, host, upgrade, blocking, reset } = request
964
+
965
+ let { body, headers, contentLength } = request
966
+
967
+ // https://tools.ietf.org/html/rfc7231#section-4.3.1
968
+ // https://tools.ietf.org/html/rfc7231#section-4.3.2
969
+ // https://tools.ietf.org/html/rfc7231#section-4.3.5
970
+
971
+ // Sending a payload body on a request that does not
972
+ // expect it can cause undefined behavior on some
973
+ // servers and corrupt connection state. Do not
974
+ // re-use the connection for further requests.
975
+
976
+ const expectsPayload = (
977
+ method === 'PUT' ||
978
+ method === 'POST' ||
979
+ method === 'PATCH' ||
980
+ method === 'QUERY' ||
981
+ method === 'PROPFIND' ||
982
+ method === 'PROPPATCH'
983
+ )
984
+
985
+ if (util.isFormDataLike(body)) {
986
+ if (!extractBody) {
987
+ extractBody = require('../web/fetch/body.js').extractBody
988
+ }
989
+
990
+ const [bodyStream, contentType] = extractBody(body)
991
+ if (request.contentType == null) {
992
+ headers.push('content-type', contentType)
993
+ }
994
+ body = bodyStream.stream
995
+ contentLength = bodyStream.length
996
+ } else if (util.isBlobLike(body) && request.contentType == null && body.type) {
997
+ headers.push('content-type', body.type)
998
+ }
999
+
1000
+ if (body && typeof body.read === 'function') {
1001
+ // Try to read EOF in order to get length.
1002
+ body.read(0)
1003
+ }
1004
+
1005
+ const bodyLength = util.bodyLength(body)
1006
+
1007
+ contentLength = bodyLength ?? contentLength
1008
+
1009
+ if (contentLength === null) {
1010
+ contentLength = request.contentLength
1011
+ }
1012
+
1013
+ if (contentLength === 0 && !expectsPayload) {
1014
+ // https://tools.ietf.org/html/rfc7230#section-3.3.2
1015
+ // A user agent SHOULD NOT send a Content-Length header field when
1016
+ // the request message does not contain a payload body and the method
1017
+ // semantics do not anticipate such a body.
1018
+
1019
+ contentLength = null
1020
+ }
1021
+
1022
+ // https://github.com/nodejs/undici/issues/2046
1023
+ // A user agent may send a Content-Length header with 0 value, this should be allowed.
1024
+ if (shouldSendContentLength(method) && contentLength > 0 && request.contentLength !== null && request.contentLength !== contentLength) {
1025
+ if (client[kStrictContentLength]) {
1026
+ util.errorRequest(client, request, new RequestContentLengthMismatchError())
1027
+ return false
1028
+ }
1029
+
1030
+ process.emitWarning(new RequestContentLengthMismatchError())
1031
+ }
1032
+
1033
+ const socket = client[kSocket]
1034
+ clearIdleSocketValidation(socket)
1035
+
1036
+ const abort = (err) => {
1037
+ if (request.aborted || request.completed) {
1038
+ return
1039
+ }
1040
+
1041
+ util.errorRequest(client, request, err || new RequestAbortedError())
1042
+
1043
+ util.destroy(body)
1044
+ util.destroy(socket, new InformationalError('aborted'))
1045
+ }
1046
+
1047
+ try {
1048
+ request.onConnect(abort)
1049
+ } catch (err) {
1050
+ util.errorRequest(client, request, err)
1051
+ }
1052
+
1053
+ if (request.aborted) {
1054
+ return false
1055
+ }
1056
+
1057
+ if (method === 'HEAD') {
1058
+ // https://github.com/mcollina/undici/issues/258
1059
+ // Close after a HEAD request to interop with misbehaving servers
1060
+ // that may send a body in the response.
1061
+
1062
+ socket[kReset] = true
1063
+ }
1064
+
1065
+ if (upgrade || method === 'CONNECT') {
1066
+ // On CONNECT or upgrade, block pipeline from dispatching further
1067
+ // requests on this connection.
1068
+
1069
+ socket[kReset] = true
1070
+ }
1071
+
1072
+ if (reset != null) {
1073
+ socket[kReset] = reset
1074
+ }
1075
+
1076
+ if (client[kMaxRequests] && socket[kCounter]++ >= client[kMaxRequests]) {
1077
+ socket[kReset] = true
1078
+ }
1079
+
1080
+ if (blocking) {
1081
+ socket[kBlocking] = true
1082
+ }
1083
+
1084
+ let header = `${method} ${path} HTTP/1.1\r\n`
1085
+
1086
+ if (typeof host === 'string') {
1087
+ header += `host: ${host}\r\n`
1088
+ } else {
1089
+ header += client[kHostHeader]
1090
+ }
1091
+
1092
+ if (upgrade) {
1093
+ header += `connection: upgrade\r\nupgrade: ${upgrade}\r\n`
1094
+ } else if (client[kPipelining] && !socket[kReset]) {
1095
+ header += 'connection: keep-alive\r\n'
1096
+ } else {
1097
+ header += 'connection: close\r\n'
1098
+ }
1099
+
1100
+ if (Array.isArray(headers)) {
1101
+ for (let n = 0; n < headers.length; n += 2) {
1102
+ const key = headers[n + 0]
1103
+ const val = headers[n + 1]
1104
+
1105
+ if (Array.isArray(val)) {
1106
+ for (let i = 0; i < val.length; i++) {
1107
+ header += `${key}: ${val[i]}\r\n`
1108
+ }
1109
+ } else {
1110
+ header += `${key}: ${val}\r\n`
1111
+ }
1112
+ }
1113
+ }
1114
+
1115
+ if (channels.sendHeaders.hasSubscribers) {
1116
+ channels.sendHeaders.publish({ request, headers: header, socket })
1117
+ }
1118
+
1119
+ /* istanbul ignore else: assertion */
1120
+ if (!body || bodyLength === 0) {
1121
+ writeBuffer(abort, null, client, request, socket, contentLength, header, expectsPayload)
1122
+ } else if (util.isBuffer(body)) {
1123
+ writeBuffer(abort, body, client, request, socket, contentLength, header, expectsPayload)
1124
+ } else if (util.isBlobLike(body)) {
1125
+ if (typeof body.stream === 'function') {
1126
+ writeIterable(abort, body.stream(), client, request, socket, contentLength, header, expectsPayload)
1127
+ } else {
1128
+ writeBlob(abort, body, client, request, socket, contentLength, header, expectsPayload)
1129
+ }
1130
+ } else if (util.isStream(body)) {
1131
+ writeStream(abort, body, client, request, socket, contentLength, header, expectsPayload)
1132
+ } else if (util.isIterable(body)) {
1133
+ writeIterable(abort, body, client, request, socket, contentLength, header, expectsPayload)
1134
+ } else {
1135
+ assert(false)
1136
+ }
1137
+
1138
+ return true
1139
+ }
1140
+
1141
+ function writeStream (abort, body, client, request, socket, contentLength, header, expectsPayload) {
1142
+ assert(contentLength !== 0 || client[kRunning] === 0, 'stream body cannot be pipelined')
1143
+
1144
+ let finished = false
1145
+
1146
+ const writer = new AsyncWriter({ abort, socket, request, contentLength, client, expectsPayload, header })
1147
+
1148
+ const onData = function (chunk) {
1149
+ if (finished) {
1150
+ return
1151
+ }
1152
+
1153
+ try {
1154
+ if (!writer.write(chunk) && this.pause) {
1155
+ this.pause()
1156
+ }
1157
+ } catch (err) {
1158
+ util.destroy(this, err)
1159
+ }
1160
+ }
1161
+ const onDrain = function () {
1162
+ if (finished) {
1163
+ return
1164
+ }
1165
+
1166
+ if (body.resume) {
1167
+ body.resume()
1168
+ }
1169
+ }
1170
+ const onClose = function () {
1171
+ // 'close' might be emitted *before* 'error' for
1172
+ // broken streams. Wait a tick to avoid this case.
1173
+ queueMicrotask(() => {
1174
+ // It's only safe to remove 'error' listener after
1175
+ // 'close'.
1176
+ body.removeListener('error', onFinished)
1177
+ })
1178
+
1179
+ if (!finished) {
1180
+ const err = new RequestAbortedError()
1181
+ queueMicrotask(() => onFinished(err))
1182
+ }
1183
+ }
1184
+ const onFinished = function (err) {
1185
+ if (finished) {
1186
+ return
1187
+ }
1188
+
1189
+ finished = true
1190
+
1191
+ assert(socket.destroyed || (socket[kWriting] && client[kRunning] <= 1))
1192
+
1193
+ socket
1194
+ .off('drain', onDrain)
1195
+ .off('error', onFinished)
1196
+
1197
+ body
1198
+ .removeListener('data', onData)
1199
+ .removeListener('end', onFinished)
1200
+ .removeListener('close', onClose)
1201
+
1202
+ if (!err) {
1203
+ try {
1204
+ writer.end()
1205
+ } catch (er) {
1206
+ err = er
1207
+ }
1208
+ }
1209
+
1210
+ writer.destroy(err)
1211
+
1212
+ if (err && (err.code !== 'UND_ERR_INFO' || err.message !== 'reset')) {
1213
+ util.destroy(body, err)
1214
+ } else {
1215
+ util.destroy(body)
1216
+ }
1217
+ }
1218
+
1219
+ body
1220
+ .on('data', onData)
1221
+ .on('end', onFinished)
1222
+ .on('error', onFinished)
1223
+ .on('close', onClose)
1224
+
1225
+ if (body.resume) {
1226
+ body.resume()
1227
+ }
1228
+
1229
+ socket
1230
+ .on('drain', onDrain)
1231
+ .on('error', onFinished)
1232
+
1233
+ if (body.errorEmitted ?? body.errored) {
1234
+ setImmediate(() => onFinished(body.errored))
1235
+ } else if (body.endEmitted ?? body.readableEnded) {
1236
+ setImmediate(() => onFinished(null))
1237
+ }
1238
+
1239
+ if (body.closeEmitted ?? body.closed) {
1240
+ setImmediate(onClose)
1241
+ }
1242
+ }
1243
+
1244
+ function writeBuffer (abort, body, client, request, socket, contentLength, header, expectsPayload) {
1245
+ try {
1246
+ if (!body) {
1247
+ if (contentLength === 0) {
1248
+ socket.write(`${header}content-length: 0\r\n\r\n`, 'latin1')
1249
+ } else {
1250
+ assert(contentLength === null, 'no body must not have content length')
1251
+ socket.write(`${header}\r\n`, 'latin1')
1252
+ }
1253
+ } else if (util.isBuffer(body)) {
1254
+ assert(contentLength === body.byteLength, 'buffer body must have content length')
1255
+
1256
+ socket.cork()
1257
+ socket.write(`${header}content-length: ${contentLength}\r\n\r\n`, 'latin1')
1258
+ socket.write(body)
1259
+ socket.uncork()
1260
+ request.onBodySent(body)
1261
+
1262
+ if (!expectsPayload && request.reset !== false) {
1263
+ socket[kReset] = true
1264
+ }
1265
+ }
1266
+ request.onRequestSent()
1267
+
1268
+ client[kResume]()
1269
+ } catch (err) {
1270
+ abort(err)
1271
+ }
1272
+ }
1273
+
1274
+ async function writeBlob (abort, body, client, request, socket, contentLength, header, expectsPayload) {
1275
+ assert(contentLength === body.size, 'blob body must have content length')
1276
+
1277
+ try {
1278
+ if (contentLength != null && contentLength !== body.size) {
1279
+ throw new RequestContentLengthMismatchError()
1280
+ }
1281
+
1282
+ const buffer = Buffer.from(await body.arrayBuffer())
1283
+
1284
+ socket.cork()
1285
+ socket.write(`${header}content-length: ${contentLength}\r\n\r\n`, 'latin1')
1286
+ socket.write(buffer)
1287
+ socket.uncork()
1288
+
1289
+ request.onBodySent(buffer)
1290
+ request.onRequestSent()
1291
+
1292
+ if (!expectsPayload && request.reset !== false) {
1293
+ socket[kReset] = true
1294
+ }
1295
+
1296
+ client[kResume]()
1297
+ } catch (err) {
1298
+ abort(err)
1299
+ }
1300
+ }
1301
+
1302
+ async function writeIterable (abort, body, client, request, socket, contentLength, header, expectsPayload) {
1303
+ assert(contentLength !== 0 || client[kRunning] === 0, 'iterator body cannot be pipelined')
1304
+
1305
+ let callback = null
1306
+ function onDrain () {
1307
+ if (callback) {
1308
+ const cb = callback
1309
+ callback = null
1310
+ cb()
1311
+ }
1312
+ }
1313
+
1314
+ const waitForDrain = () => new Promise((resolve, reject) => {
1315
+ assert(callback === null)
1316
+
1317
+ if (socket[kError]) {
1318
+ reject(socket[kError])
1319
+ } else {
1320
+ callback = resolve
1321
+ }
1322
+ })
1323
+
1324
+ socket
1325
+ .on('close', onDrain)
1326
+ .on('drain', onDrain)
1327
+
1328
+ const writer = new AsyncWriter({ abort, socket, request, contentLength, client, expectsPayload, header })
1329
+ try {
1330
+ // It's up to the user to somehow abort the async iterable.
1331
+ for await (const chunk of body) {
1332
+ if (socket[kError]) {
1333
+ throw socket[kError]
1334
+ }
1335
+
1336
+ if (!writer.write(chunk)) {
1337
+ await waitForDrain()
1338
+ }
1339
+ }
1340
+
1341
+ writer.end()
1342
+ } catch (err) {
1343
+ writer.destroy(err)
1344
+ } finally {
1345
+ socket
1346
+ .off('close', onDrain)
1347
+ .off('drain', onDrain)
1348
+ }
1349
+ }
1350
+
1351
+ class AsyncWriter {
1352
+ constructor ({ abort, socket, request, contentLength, client, expectsPayload, header }) {
1353
+ this.socket = socket
1354
+ this.request = request
1355
+ this.contentLength = contentLength
1356
+ this.client = client
1357
+ this.bytesWritten = 0
1358
+ this.expectsPayload = expectsPayload
1359
+ this.header = header
1360
+ this.abort = abort
1361
+
1362
+ socket[kWriting] = true
1363
+ }
1364
+
1365
+ write (chunk) {
1366
+ const { socket, request, contentLength, client, bytesWritten, expectsPayload, header } = this
1367
+
1368
+ if (socket[kError]) {
1369
+ throw socket[kError]
1370
+ }
1371
+
1372
+ if (socket.destroyed) {
1373
+ return false
1374
+ }
1375
+
1376
+ const len = Buffer.byteLength(chunk)
1377
+ if (!len) {
1378
+ return true
1379
+ }
1380
+
1381
+ // We should defer writing chunks.
1382
+ if (contentLength !== null && bytesWritten + len > contentLength) {
1383
+ if (client[kStrictContentLength]) {
1384
+ throw new RequestContentLengthMismatchError()
1385
+ }
1386
+
1387
+ process.emitWarning(new RequestContentLengthMismatchError())
1388
+ }
1389
+
1390
+ socket.cork()
1391
+
1392
+ if (bytesWritten === 0) {
1393
+ if (!expectsPayload && request.reset !== false) {
1394
+ socket[kReset] = true
1395
+ }
1396
+
1397
+ if (contentLength === null) {
1398
+ socket.write(`${header}transfer-encoding: chunked\r\n`, 'latin1')
1399
+ } else {
1400
+ socket.write(`${header}content-length: ${contentLength}\r\n\r\n`, 'latin1')
1401
+ }
1402
+ }
1403
+
1404
+ if (contentLength === null) {
1405
+ socket.write(`\r\n${len.toString(16)}\r\n`, 'latin1')
1406
+ }
1407
+
1408
+ this.bytesWritten += len
1409
+
1410
+ const ret = socket.write(chunk)
1411
+
1412
+ socket.uncork()
1413
+
1414
+ request.onBodySent(chunk)
1415
+
1416
+ if (!ret) {
1417
+ if (socket[kParser].timeout && socket[kParser].timeoutType === TIMEOUT_HEADERS) {
1418
+ // istanbul ignore else: only for jest
1419
+ if (socket[kParser].timeout.refresh) {
1420
+ socket[kParser].timeout.refresh()
1421
+ }
1422
+ }
1423
+ }
1424
+
1425
+ return ret
1426
+ }
1427
+
1428
+ end () {
1429
+ const { socket, contentLength, client, bytesWritten, expectsPayload, header, request } = this
1430
+ request.onRequestSent()
1431
+
1432
+ socket[kWriting] = false
1433
+
1434
+ if (socket[kError]) {
1435
+ throw socket[kError]
1436
+ }
1437
+
1438
+ if (socket.destroyed) {
1439
+ return
1440
+ }
1441
+
1442
+ if (bytesWritten === 0) {
1443
+ if (expectsPayload) {
1444
+ // https://tools.ietf.org/html/rfc7230#section-3.3.2
1445
+ // A user agent SHOULD send a Content-Length in a request message when
1446
+ // no Transfer-Encoding is sent and the request method defines a meaning
1447
+ // for an enclosed payload body.
1448
+
1449
+ socket.write(`${header}content-length: 0\r\n\r\n`, 'latin1')
1450
+ } else {
1451
+ socket.write(`${header}\r\n`, 'latin1')
1452
+ }
1453
+ } else if (contentLength === null) {
1454
+ socket.write('\r\n0\r\n\r\n', 'latin1')
1455
+ }
1456
+
1457
+ if (contentLength !== null && bytesWritten !== contentLength) {
1458
+ if (client[kStrictContentLength]) {
1459
+ throw new RequestContentLengthMismatchError()
1460
+ } else {
1461
+ process.emitWarning(new RequestContentLengthMismatchError())
1462
+ }
1463
+ }
1464
+
1465
+ if (socket[kParser].timeout && socket[kParser].timeoutType === TIMEOUT_HEADERS) {
1466
+ // istanbul ignore else: only for jest
1467
+ if (socket[kParser].timeout.refresh) {
1468
+ socket[kParser].timeout.refresh()
1469
+ }
1470
+ }
1471
+
1472
+ client[kResume]()
1473
+ }
1474
+
1475
+ destroy (err) {
1476
+ const { socket, client, abort } = this
1477
+
1478
+ socket[kWriting] = false
1479
+
1480
+ if (err) {
1481
+ assert(client[kRunning] <= 1, 'pipeline should only contain this request')
1482
+ abort(err)
1483
+ }
1484
+ }
1485
+ }
1486
+
1487
+ module.exports = connectH1