@pnpm/exe 11.0.6 → 11.0.7

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