@openclaw/anthropic-vertex-provider 2026.7.1 → 2026.7.2-beta.2

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 (216) hide show
  1. package/dist/index.js +2 -2
  2. package/dist/provider-catalog.js +2 -2
  3. package/dist/region.js +17 -9
  4. package/dist/stream-runtime.js +22 -3
  5. package/node_modules/undici/LICENSE +21 -0
  6. package/node_modules/undici/README.md +791 -0
  7. package/node_modules/undici/docs/docs/GettingStarted.md +278 -0
  8. package/node_modules/undici/docs/docs/api/Agent.md +87 -0
  9. package/node_modules/undici/docs/docs/api/BalancedPool.md +99 -0
  10. package/node_modules/undici/docs/docs/api/CacheStorage.md +30 -0
  11. package/node_modules/undici/docs/docs/api/CacheStore.md +164 -0
  12. package/node_modules/undici/docs/docs/api/Client.md +326 -0
  13. package/node_modules/undici/docs/docs/api/ClientStats.md +27 -0
  14. package/node_modules/undici/docs/docs/api/Connector.md +116 -0
  15. package/node_modules/undici/docs/docs/api/ContentType.md +57 -0
  16. package/node_modules/undici/docs/docs/api/Cookies.md +128 -0
  17. package/node_modules/undici/docs/docs/api/Debug.md +62 -0
  18. package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +315 -0
  19. package/node_modules/undici/docs/docs/api/Dispatcher.md +1444 -0
  20. package/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +156 -0
  21. package/node_modules/undici/docs/docs/api/Errors.md +61 -0
  22. package/node_modules/undici/docs/docs/api/EventSource.md +92 -0
  23. package/node_modules/undici/docs/docs/api/Fetch.md +62 -0
  24. package/node_modules/undici/docs/docs/api/GlobalInstallation.md +141 -0
  25. package/node_modules/undici/docs/docs/api/H2CClient.md +263 -0
  26. package/node_modules/undici/docs/docs/api/MockAgent.md +603 -0
  27. package/node_modules/undici/docs/docs/api/MockCallHistory.md +197 -0
  28. package/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +43 -0
  29. package/node_modules/undici/docs/docs/api/MockClient.md +81 -0
  30. package/node_modules/undici/docs/docs/api/MockErrors.md +12 -0
  31. package/node_modules/undici/docs/docs/api/MockPool.md +555 -0
  32. package/node_modules/undici/docs/docs/api/Pool.md +87 -0
  33. package/node_modules/undici/docs/docs/api/PoolStats.md +35 -0
  34. package/node_modules/undici/docs/docs/api/ProxyAgent.md +229 -0
  35. package/node_modules/undici/docs/docs/api/RedirectHandler.md +101 -0
  36. package/node_modules/undici/docs/docs/api/RetryAgent.md +49 -0
  37. package/node_modules/undici/docs/docs/api/RetryHandler.md +116 -0
  38. package/node_modules/undici/docs/docs/api/RoundRobinPool.md +145 -0
  39. package/node_modules/undici/docs/docs/api/SnapshotAgent.md +639 -0
  40. package/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +275 -0
  41. package/node_modules/undici/docs/docs/api/Util.md +25 -0
  42. package/node_modules/undici/docs/docs/api/WebSocket.md +141 -0
  43. package/node_modules/undici/docs/docs/api/api-lifecycle.md +91 -0
  44. package/node_modules/undici/docs/docs/best-practices/client-certificate.md +64 -0
  45. package/node_modules/undici/docs/docs/best-practices/crawling.md +58 -0
  46. package/node_modules/undici/docs/docs/best-practices/migrating-from-v7-to-v8.md +231 -0
  47. package/node_modules/undici/docs/docs/best-practices/mocking-request.md +190 -0
  48. package/node_modules/undici/docs/docs/best-practices/proxy.md +127 -0
  49. package/node_modules/undici/docs/docs/best-practices/undici-vs-builtin-fetch.md +224 -0
  50. package/node_modules/undici/docs/docs/best-practices/writing-tests.md +63 -0
  51. package/node_modules/undici/index-fetch.js +65 -0
  52. package/node_modules/undici/index.d.ts +3 -0
  53. package/node_modules/undici/index.js +236 -0
  54. package/node_modules/undici/lib/api/abort-signal.js +59 -0
  55. package/node_modules/undici/lib/api/api-connect.js +112 -0
  56. package/node_modules/undici/lib/api/api-pipeline.js +265 -0
  57. package/node_modules/undici/lib/api/api-request.js +238 -0
  58. package/node_modules/undici/lib/api/api-stream.js +270 -0
  59. package/node_modules/undici/lib/api/api-upgrade.js +121 -0
  60. package/node_modules/undici/lib/api/index.js +7 -0
  61. package/node_modules/undici/lib/api/readable.js +581 -0
  62. package/node_modules/undici/lib/cache/memory-cache-store.js +234 -0
  63. package/node_modules/undici/lib/cache/sqlite-cache-store.js +463 -0
  64. package/node_modules/undici/lib/core/connect.js +178 -0
  65. package/node_modules/undici/lib/core/constants.js +120 -0
  66. package/node_modules/undici/lib/core/diagnostics.js +227 -0
  67. package/node_modules/undici/lib/core/errors.js +477 -0
  68. package/node_modules/undici/lib/core/request.js +535 -0
  69. package/node_modules/undici/lib/core/socks5-client.js +422 -0
  70. package/node_modules/undici/lib/core/socks5-utils.js +212 -0
  71. package/node_modules/undici/lib/core/symbols.js +76 -0
  72. package/node_modules/undici/lib/core/tree.js +160 -0
  73. package/node_modules/undici/lib/core/util.js +1021 -0
  74. package/node_modules/undici/lib/dispatcher/agent.js +172 -0
  75. package/node_modules/undici/lib/dispatcher/balanced-pool.js +214 -0
  76. package/node_modules/undici/lib/dispatcher/client-h1.js +1736 -0
  77. package/node_modules/undici/lib/dispatcher/client-h2.js +1449 -0
  78. package/node_modules/undici/lib/dispatcher/client.js +695 -0
  79. package/node_modules/undici/lib/dispatcher/dispatcher-base.js +185 -0
  80. package/node_modules/undici/lib/dispatcher/dispatcher.js +44 -0
  81. package/node_modules/undici/lib/dispatcher/dispatcher1-wrapper.js +107 -0
  82. package/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +146 -0
  83. package/node_modules/undici/lib/dispatcher/fixed-queue.js +135 -0
  84. package/node_modules/undici/lib/dispatcher/h2c-client.js +51 -0
  85. package/node_modules/undici/lib/dispatcher/pool-base.js +232 -0
  86. package/node_modules/undici/lib/dispatcher/pool.js +143 -0
  87. package/node_modules/undici/lib/dispatcher/proxy-agent.js +344 -0
  88. package/node_modules/undici/lib/dispatcher/retry-agent.js +35 -0
  89. package/node_modules/undici/lib/dispatcher/round-robin-pool.js +159 -0
  90. package/node_modules/undici/lib/dispatcher/socks5-proxy-agent.js +266 -0
  91. package/node_modules/undici/lib/encoding/index.js +33 -0
  92. package/node_modules/undici/lib/global.js +62 -0
  93. package/node_modules/undici/lib/handler/cache-handler.js +586 -0
  94. package/node_modules/undici/lib/handler/cache-revalidation-handler.js +124 -0
  95. package/node_modules/undici/lib/handler/decorator-handler.js +66 -0
  96. package/node_modules/undici/lib/handler/deduplication-handler.js +460 -0
  97. package/node_modules/undici/lib/handler/redirect-handler.js +217 -0
  98. package/node_modules/undici/lib/handler/retry-handler.js +407 -0
  99. package/node_modules/undici/lib/interceptor/cache.js +508 -0
  100. package/node_modules/undici/lib/interceptor/decompress.js +285 -0
  101. package/node_modules/undici/lib/interceptor/deduplicate.js +117 -0
  102. package/node_modules/undici/lib/interceptor/dns.js +575 -0
  103. package/node_modules/undici/lib/interceptor/dump.js +112 -0
  104. package/node_modules/undici/lib/interceptor/redirect.js +21 -0
  105. package/node_modules/undici/lib/interceptor/response-error.js +95 -0
  106. package/node_modules/undici/lib/interceptor/retry.js +19 -0
  107. package/node_modules/undici/lib/llhttp/constants.d.ts +195 -0
  108. package/node_modules/undici/lib/llhttp/constants.js +531 -0
  109. package/node_modules/undici/lib/llhttp/llhttp-wasm.js +15 -0
  110. package/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +15 -0
  111. package/node_modules/undici/lib/llhttp/utils.d.ts +2 -0
  112. package/node_modules/undici/lib/llhttp/utils.js +12 -0
  113. package/node_modules/undici/lib/mock/mock-agent.js +232 -0
  114. package/node_modules/undici/lib/mock/mock-call-history.js +248 -0
  115. package/node_modules/undici/lib/mock/mock-client.js +68 -0
  116. package/node_modules/undici/lib/mock/mock-errors.js +29 -0
  117. package/node_modules/undici/lib/mock/mock-interceptor.js +209 -0
  118. package/node_modules/undici/lib/mock/mock-pool.js +68 -0
  119. package/node_modules/undici/lib/mock/mock-symbols.js +32 -0
  120. package/node_modules/undici/lib/mock/mock-utils.js +501 -0
  121. package/node_modules/undici/lib/mock/pending-interceptors-formatter.js +43 -0
  122. package/node_modules/undici/lib/mock/snapshot-agent.js +371 -0
  123. package/node_modules/undici/lib/mock/snapshot-recorder.js +623 -0
  124. package/node_modules/undici/lib/mock/snapshot-utils.js +158 -0
  125. package/node_modules/undici/lib/util/cache.js +414 -0
  126. package/node_modules/undici/lib/util/date.js +653 -0
  127. package/node_modules/undici/lib/util/runtime-features.js +93 -0
  128. package/node_modules/undici/lib/util/stats.js +32 -0
  129. package/node_modules/undici/lib/util/timers.js +425 -0
  130. package/node_modules/undici/lib/web/cache/cache.js +862 -0
  131. package/node_modules/undici/lib/web/cache/cachestorage.js +152 -0
  132. package/node_modules/undici/lib/web/cache/util.js +45 -0
  133. package/node_modules/undici/lib/web/cookies/constants.js +12 -0
  134. package/node_modules/undici/lib/web/cookies/index.js +199 -0
  135. package/node_modules/undici/lib/web/cookies/parse.js +314 -0
  136. package/node_modules/undici/lib/web/cookies/util.js +282 -0
  137. package/node_modules/undici/lib/web/eventsource/eventsource-stream.js +494 -0
  138. package/node_modules/undici/lib/web/eventsource/eventsource.js +490 -0
  139. package/node_modules/undici/lib/web/eventsource/util.js +60 -0
  140. package/node_modules/undici/lib/web/fetch/LICENSE +21 -0
  141. package/node_modules/undici/lib/web/fetch/body.js +546 -0
  142. package/node_modules/undici/lib/web/fetch/constants.js +131 -0
  143. package/node_modules/undici/lib/web/fetch/data-url.js +596 -0
  144. package/node_modules/undici/lib/web/fetch/formdata-parser.js +586 -0
  145. package/node_modules/undici/lib/web/fetch/formdata.js +278 -0
  146. package/node_modules/undici/lib/web/fetch/global.js +40 -0
  147. package/node_modules/undici/lib/web/fetch/headers.js +719 -0
  148. package/node_modules/undici/lib/web/fetch/index.js +2417 -0
  149. package/node_modules/undici/lib/web/fetch/request.js +1145 -0
  150. package/node_modules/undici/lib/web/fetch/response.js +641 -0
  151. package/node_modules/undici/lib/web/fetch/util.js +1522 -0
  152. package/node_modules/undici/lib/web/infra/index.js +229 -0
  153. package/node_modules/undici/lib/web/subresource-integrity/Readme.md +9 -0
  154. package/node_modules/undici/lib/web/subresource-integrity/subresource-integrity.js +307 -0
  155. package/node_modules/undici/lib/web/webidl/index.js +1004 -0
  156. package/node_modules/undici/lib/web/websocket/connection.js +329 -0
  157. package/node_modules/undici/lib/web/websocket/constants.js +126 -0
  158. package/node_modules/undici/lib/web/websocket/events.js +331 -0
  159. package/node_modules/undici/lib/web/websocket/frame.js +127 -0
  160. package/node_modules/undici/lib/web/websocket/permessage-deflate.js +100 -0
  161. package/node_modules/undici/lib/web/websocket/receiver.js +507 -0
  162. package/node_modules/undici/lib/web/websocket/sender.js +109 -0
  163. package/node_modules/undici/lib/web/websocket/stream/websocketerror.js +104 -0
  164. package/node_modules/undici/lib/web/websocket/stream/websocketstream.js +498 -0
  165. package/node_modules/undici/lib/web/websocket/util.js +347 -0
  166. package/node_modules/undici/lib/web/websocket/websocket.js +758 -0
  167. package/node_modules/undici/package.json +152 -0
  168. package/node_modules/undici/scripts/strip-comments.js +10 -0
  169. package/node_modules/undici/types/README.md +6 -0
  170. package/node_modules/undici/types/agent.d.ts +30 -0
  171. package/node_modules/undici/types/api.d.ts +43 -0
  172. package/node_modules/undici/types/balanced-pool.d.ts +30 -0
  173. package/node_modules/undici/types/cache-interceptor.d.ts +179 -0
  174. package/node_modules/undici/types/cache.d.ts +36 -0
  175. package/node_modules/undici/types/client-stats.d.ts +15 -0
  176. package/node_modules/undici/types/client.d.ts +134 -0
  177. package/node_modules/undici/types/connector.d.ts +37 -0
  178. package/node_modules/undici/types/content-type.d.ts +21 -0
  179. package/node_modules/undici/types/cookies.d.ts +30 -0
  180. package/node_modules/undici/types/diagnostics-channel.d.ts +74 -0
  181. package/node_modules/undici/types/dispatcher.d.ts +253 -0
  182. package/node_modules/undici/types/dispatcher1-wrapper.d.ts +7 -0
  183. package/node_modules/undici/types/env-http-proxy-agent.d.ts +22 -0
  184. package/node_modules/undici/types/errors.d.ts +177 -0
  185. package/node_modules/undici/types/eventsource.d.ts +66 -0
  186. package/node_modules/undici/types/fetch.d.ts +235 -0
  187. package/node_modules/undici/types/formdata.d.ts +108 -0
  188. package/node_modules/undici/types/global-dispatcher.d.ts +9 -0
  189. package/node_modules/undici/types/global-origin.d.ts +7 -0
  190. package/node_modules/undici/types/h2c-client.d.ts +73 -0
  191. package/node_modules/undici/types/handlers.d.ts +14 -0
  192. package/node_modules/undici/types/header.d.ts +165 -0
  193. package/node_modules/undici/types/index.d.ts +93 -0
  194. package/node_modules/undici/types/interceptors.d.ts +80 -0
  195. package/node_modules/undici/types/mock-agent.d.ts +68 -0
  196. package/node_modules/undici/types/mock-call-history.d.ts +111 -0
  197. package/node_modules/undici/types/mock-client.d.ts +27 -0
  198. package/node_modules/undici/types/mock-errors.d.ts +12 -0
  199. package/node_modules/undici/types/mock-interceptor.d.ts +94 -0
  200. package/node_modules/undici/types/mock-pool.d.ts +27 -0
  201. package/node_modules/undici/types/patch.d.ts +29 -0
  202. package/node_modules/undici/types/pool-stats.d.ts +19 -0
  203. package/node_modules/undici/types/pool.d.ts +39 -0
  204. package/node_modules/undici/types/proxy-agent.d.ts +29 -0
  205. package/node_modules/undici/types/readable.d.ts +68 -0
  206. package/node_modules/undici/types/retry-agent.d.ts +8 -0
  207. package/node_modules/undici/types/retry-handler.d.ts +125 -0
  208. package/node_modules/undici/types/round-robin-pool.d.ts +39 -0
  209. package/node_modules/undici/types/snapshot-agent.d.ts +113 -0
  210. package/node_modules/undici/types/socks5-proxy-agent.d.ts +25 -0
  211. package/node_modules/undici/types/util.d.ts +18 -0
  212. package/node_modules/undici/types/utility.d.ts +7 -0
  213. package/node_modules/undici/types/webidl.d.ts +346 -0
  214. package/node_modules/undici/types/websocket.d.ts +188 -0
  215. package/npm-shrinkwrap.json +14 -3
  216. package/package.json +10 -6
@@ -0,0 +1,791 @@
1
+ # undici
2
+
3
+ [![Node CI](https://github.com/nodejs/undici/actions/workflows/ci.yml/badge.svg)](https://github.com/nodejs/undici/actions/workflows/nodejs.yml) [![neostandard javascript style](https://img.shields.io/badge/neo-standard-7fffff?style=flat\&labelColor=ff80ff)](https://github.com/neostandard/neostandard) [![npm version](https://badge.fury.io/js/undici.svg)](https://badge.fury.io/js/undici) [![codecov](https://codecov.io/gh/nodejs/undici/branch/main/graph/badge.svg?token=yZL6LtXkOA)](https://codecov.io/gh/nodejs/undici)
4
+
5
+ An HTTP/1.1 client, written from scratch for Node.js.
6
+
7
+ > Undici means eleven in Italian. 1.1 -> 11 -> Eleven -> Undici.
8
+ It is also a Stranger Things reference.
9
+
10
+ ## How to get involved
11
+
12
+ Have a question about using Undici? Open a [Q&A Discussion](https://github.com/nodejs/undici/discussions/new) or join our official OpenJS [Slack](https://openjs-foundation.slack.com/archives/C01QF9Q31QD) channel.
13
+
14
+ Looking to contribute? Start by reading the [contributing guide](./CONTRIBUTING.md)
15
+
16
+ ## Install
17
+
18
+ ```
19
+ npm i undici
20
+ ```
21
+
22
+ ## Benchmarks
23
+
24
+ The benchmark is a simple getting data [example](https://github.com/nodejs/undici/blob/main/benchmarks/benchmark.js) using
25
+ 50 TCP connections with a pipelining depth of 10 running on Node 24.14.1.
26
+
27
+ ### HTTP/1.1
28
+
29
+ ```
30
+ ┌────────────────────────┬─────────┬────────────────────┬────────────┬─────────────────────────┐
31
+ │ Tests │ Samples │ Result │ Tolerance │ Difference with slowest │
32
+ ├────────────────────────┼─────────┼────────────────────┼────────────┼─────────────────────────┤
33
+ │ 'node-fetch' │ 50 │ '4711.86 req/sec' │ '± 2.92 %' │ '-' │
34
+ │ 'undici - fetch' │ 75 │ '5438.50 req/sec' │ '± 2.97 %' │ '+ 15.42 %' │
35
+ │ 'axios' │ 45 │ '5448.08 req/sec' │ '± 2.98 %' │ '+ 15.62 %' │
36
+ │ 'request' │ 65 │ '5809.63 req/sec' │ '± 2.90 %' │ '+ 23.30 %' │
37
+ │ 'http - no keepalive' │ 35 │ '5910.77 req/sec' │ '± 2.87 %' │ '+ 25.44 %' │
38
+ │ 'got' │ 50 │ '6047.80 req/sec' │ '± 2.91 %' │ '+ 28.35 %' │
39
+ │ 'superagent' │ 60 │ '7534.53 req/sec' │ '± 2.97 %' │ '+ 59.91 %' │
40
+ │ 'http - keepalive' │ 75 │ '9343.41 req/sec' │ '± 2.90 %' │ '+ 98.30 %' │
41
+ │ 'undici - pipeline' │ 65 │ '13470.70 req/sec' │ '± 2.93 %' │ '+ 185.89 %' │
42
+ │ 'undici - request' │ 80 │ '16850.87 req/sec' │ '± 2.93 %' │ '+ 257.63 %' │
43
+ │ 'undici - stream' │ 101 │ '18488.56 req/sec' │ '± 3.81 %' │ '+ 292.38 %' │
44
+ │ 'undici - dispatch' │ 101 │ '20786.44 req/sec' │ '± 3.08 %' │ '+ 341.15 %' │
45
+ └────────────────────────┴─────────┴────────────────────┴────────────┴─────────────────────────┘
46
+ ```
47
+
48
+ ### HTTP/1.1 over HTTPS
49
+
50
+ Using [benchmark-https.js](https://github.com/nodejs/undici/blob/main/benchmarks/benchmark-https.js) against an h1-over-TLS server (50 connections, pipelining depth 10, Node 24.14.1).
51
+
52
+ ```
53
+ ┌────────────────────────┬─────────┬───────────────────┬────────────┬─────────────────────────┐
54
+ │ Tests │ Samples │ Result │ Tolerance │ Difference with slowest │
55
+ ├────────────────────────┼─────────┼───────────────────┼────────────┼─────────────────────────┤
56
+ │ 'https - no keepalive'│ 10 │ '1358.40 req/sec' │ '± 1.99 %' │ '-' │
57
+ │ 'undici - fetch' │ 30 │ '3721.76 req/sec' │ '± 2.97 %' │ '+ 173.98 %' │
58
+ │ 'https - keepalive' │ 35 │ '5633.91 req/sec' │ '± 2.84 %' │ '+ 314.75 %' │
59
+ │ 'undici - pipeline' │ 15 │ '6254.05 req/sec' │ '± 2.80 %' │ '+ 360.40 %' │
60
+ │ 'undici - request' │ 25 │ '6669.80 req/sec' │ '± 2.73 %' │ '+ 391.01 %' │
61
+ │ 'undici - stream' │ 25 │ '7019.04 req/sec' │ '± 2.77 %' │ '+ 416.71 %' │
62
+ │ 'undici - dispatch' │ 20 │ '7361.85 req/sec' │ '± 2.90 %' │ '+ 441.95 %' │
63
+ └────────────────────────┴─────────┴───────────────────┴────────────┴─────────────────────────┘
64
+ ```
65
+
66
+ ### HTTP/2
67
+
68
+ Using [benchmark-http2.js](https://github.com/nodejs/undici/blob/main/benchmarks/benchmark-http2.js) against an h2 server (50 connections, pipelining depth 10, Node 24.14.1).
69
+
70
+ ```
71
+ ┌────────────────────────┬─────────┬───────────────────┬────────────┬─────────────────────────┐
72
+ │ Tests │ Samples │ Result │ Tolerance │ Difference with slowest │
73
+ ├────────────────────────┼─────────┼───────────────────┼────────────┼─────────────────────────┤
74
+ │ 'undici - fetch' │ 45 │ '3499.03 req/sec' │ '± 2.93 %' │ '-' │
75
+ │ 'native - http2' │ 25 │ '4904.58 req/sec' │ '± 2.81 %' │ '+ 40.17 %' │
76
+ │ 'undici - pipeline' │ 60 │ '5836.82 req/sec' │ '± 2.99 %' │ '+ 66.81 %' │
77
+ │ 'undici - request' │ 65 │ '6831.25 req/sec' │ '± 2.83 %' │ '+ 95.23 %' │
78
+ │ 'undici - stream' │ 55 │ '6874.30 req/sec' │ '± 2.91 %' │ '+ 96.46 %' │
79
+ │ 'undici - dispatch' │ 55 │ '7791.23 req/sec' │ '± 2.96 %' │ '+ 122.67 %' │
80
+ └────────────────────────┴─────────┴───────────────────┴────────────┴─────────────────────────┘
81
+ ```
82
+
83
+ ## Undici vs. Fetch
84
+
85
+ ### Overview
86
+
87
+ Node.js includes a built-in `fetch()` implementation powered by undici starting from Node.js v18. However, there are important differences between using the built-in fetch and installing undici as a separate module.
88
+
89
+ ### Built-in Fetch (Node.js v18+)
90
+
91
+ Node.js's built-in fetch is powered by a bundled version of undici:
92
+
93
+ ```js
94
+ // Available globally in Node.js v18+
95
+ const response = await fetch('https://api.example.com/data');
96
+ const data = await response.json();
97
+
98
+ // Check the bundled undici version
99
+ console.log(process.versions.undici); // e.g., "5.28.4"
100
+ ```
101
+
102
+ **Pros:**
103
+ - No additional dependencies required
104
+ - Works across different JavaScript runtimes
105
+ - Automatic compression handling (gzip, deflate, br)
106
+ - Built-in caching support (in development)
107
+
108
+ **Cons:**
109
+ - Limited to the undici version bundled with your Node.js version
110
+ - Less control over connection pooling and advanced features
111
+ - Error handling follows Web API standards (errors wrapped in `TypeError`)
112
+ - Performance overhead due to Web Streams implementation
113
+
114
+ ### Undici Module
115
+
116
+ Installing undici as a separate module gives you access to the latest features and APIs:
117
+
118
+ ```bash
119
+ npm install undici
120
+ ```
121
+
122
+ ```js
123
+ import { request, fetch, Agent, setGlobalDispatcher } from 'undici';
124
+
125
+ // Use undici.request for maximum performance
126
+ const { statusCode, headers, body } = await request('https://api.example.com/data');
127
+ const data = await body.json();
128
+
129
+ // Or use undici.fetch with custom configuration
130
+ const agent = new Agent({ keepAliveTimeout: 10000 });
131
+ setGlobalDispatcher(agent);
132
+ const response = await fetch('https://api.example.com/data');
133
+ ```
134
+
135
+ **Pros:**
136
+ - Latest undici features and bug fixes
137
+ - Access to advanced APIs (`request`, `stream`, `pipeline`)
138
+ - Fine-grained control over connection pooling
139
+ - Better error handling with clearer error messages
140
+ - Superior performance, especially with `undici.request`
141
+ - HTTP/1.1 pipelining support
142
+ - Custom interceptors and middleware
143
+ - Advanced features like `ProxyAgent`, `Socks5Agent`, `MockAgent`
144
+
145
+ **Cons:**
146
+ - Additional dependency to manage
147
+ - Larger bundle size
148
+
149
+ ### When to Use Each
150
+
151
+ #### Use Built-in Fetch When:
152
+ - You want zero dependencies
153
+ - Building isomorphic code that runs in browsers and Node.js
154
+ - Publishing to npm and want to maximize compatibility with JS runtimes
155
+ - Simple HTTP requests without advanced configuration
156
+ - You're publishing to npm and you want to maximize compatiblity
157
+ - You don't depend on features from a specific version of undici
158
+
159
+ #### Use Undici Module When:
160
+ - You need the latest undici features and performance improvements
161
+ - You require advanced connection pooling configuration
162
+ - You need APIs not available in the built-in fetch (`ProxyAgent`, `Socks5Agent`, `MockAgent`, etc.)
163
+ - Performance is critical (use `undici.request` for maximum speed)
164
+ - You want better error handling and debugging capabilities
165
+ - You need HTTP/1.1 pipelining or advanced interceptors
166
+ - You prefer decoupled protocol and API interfaces
167
+
168
+ ### Performance Comparison
169
+
170
+ Based on benchmarks, here's the typical performance hierarchy:
171
+
172
+ 1. **`undici.request()`** - Fastest, most efficient
173
+ 2. **`undici.fetch()`** - Good performance, standard compliance
174
+ 3. **Node.js `http`/`https`** - Baseline performance
175
+
176
+ ### Migration Guide
177
+
178
+ If you're currently using built-in fetch and want to migrate to undici:
179
+
180
+ ```js
181
+ // Before: Built-in fetch
182
+ const response = await fetch('https://api.example.com/data');
183
+
184
+ // After: Undici fetch (drop-in replacement)
185
+ import { fetch } from 'undici';
186
+ const response = await fetch('https://api.example.com/data');
187
+
188
+ // Or: Undici request (better performance)
189
+ import { request } from 'undici';
190
+ const { statusCode, body } = await request('https://api.example.com/data');
191
+ const data = await body.json();
192
+ ```
193
+
194
+ ### Keep `fetch` and `FormData` together
195
+
196
+ When you send a `FormData` body, keep `fetch` and `FormData` from the same
197
+ implementation.
198
+
199
+ Use one of these patterns:
200
+
201
+ ```js
202
+ // Built-in globals
203
+ const body = new FormData()
204
+ body.set('name', 'some')
205
+ await fetch('https://example.com', {
206
+ method: 'POST',
207
+ body
208
+ })
209
+ ```
210
+
211
+ ```js
212
+ // undici module imports
213
+ import { fetch, FormData } from 'undici'
214
+
215
+ const body = new FormData()
216
+ body.set('name', 'some')
217
+ await fetch('https://example.com', {
218
+ method: 'POST',
219
+ body
220
+ })
221
+ ```
222
+
223
+ If you want the installed `undici` package to provide the globals, call
224
+ `install()` first:
225
+
226
+ ```js
227
+ import { install } from 'undici'
228
+
229
+ install()
230
+
231
+ const body = new FormData()
232
+ body.set('name', 'some')
233
+ await fetch('https://example.com', {
234
+ method: 'POST',
235
+ body
236
+ })
237
+ ```
238
+
239
+ `install()` replaces the global `fetch`, `Headers`, `Response`, `Request`, and
240
+ `FormData` implementations with undici's versions, so they all match. It also
241
+ installs undici's `WebSocket`, `CloseEvent`, `ErrorEvent`, `MessageEvent`, and
242
+ `EventSource` globals.
243
+
244
+ Avoid mixing a global `FormData` with `undici.fetch()`, or `undici.FormData`
245
+ with the built-in global `fetch()`.
246
+
247
+ ### Version Compatibility
248
+
249
+ You can check which version of undici is bundled with your Node.js version:
250
+
251
+ ```js
252
+ console.log(process.versions.undici);
253
+ ```
254
+
255
+ Installing undici as a module allows you to use a newer version than what's bundled with Node.js, giving you access to the latest features and performance improvements.
256
+
257
+ ## Quick Start
258
+
259
+ ### Basic Request
260
+
261
+ ```js
262
+ import { request } from 'undici'
263
+
264
+ const {
265
+ statusCode,
266
+ headers,
267
+ trailers,
268
+ body
269
+ } = await request('http://localhost:3000/foo')
270
+
271
+ console.log('response received', statusCode)
272
+ console.log('headers', headers)
273
+
274
+ for await (const data of body) { console.log('data', data) }
275
+
276
+ console.log('trailers', trailers)
277
+ ```
278
+
279
+ ### Using Cache Interceptor
280
+
281
+ Undici provides a powerful HTTP caching interceptor that follows HTTP caching best practices. Here's how to use it:
282
+
283
+ ```js
284
+ import { fetch, Agent, interceptors, cacheStores } from 'undici';
285
+
286
+ // Create a client with cache interceptor
287
+ const client = new Agent().compose(interceptors.cache({
288
+ // Optional: Configure cache store (defaults to MemoryCacheStore)
289
+ store: new cacheStores.MemoryCacheStore({
290
+ maxSize: 100 * 1024 * 1024, // 100MB
291
+ maxCount: 1000,
292
+ maxEntrySize: 5 * 1024 * 1024 // 5MB
293
+ }),
294
+
295
+ // Optional: Specify which HTTP methods to cache (default: ['GET', 'HEAD'])
296
+ methods: ['GET', 'HEAD']
297
+ }));
298
+
299
+ // Set the global dispatcher to use our caching client
300
+ setGlobalDispatcher(client);
301
+
302
+ // Now all fetch requests will use the cache
303
+ async function getData() {
304
+ const response = await fetch('https://api.example.com/data');
305
+ // The server should set appropriate Cache-Control headers in the response
306
+ // which the cache will respect based on the cache policy
307
+ return response.json();
308
+ }
309
+
310
+ // First request - fetches from origin
311
+ const data1 = await getData();
312
+
313
+ // Second request - served from cache if within max-age
314
+ const data2 = await getData();
315
+ ```
316
+
317
+ #### Key Features:
318
+ - **Automatic Caching**: Respects `Cache-Control` and `Expires` headers
319
+ - **Validation**: Supports `ETag` and `Last-Modified` validation
320
+ - **Storage Options**: In-memory or persistent SQLite storage
321
+ - **Flexible**: Configure cache size, TTL, and more
322
+
323
+ ## Global Installation
324
+
325
+ Undici provides an `install()` function to add fetch-related and other web API classes to `globalThis`, making them available globally:
326
+
327
+ ```js
328
+ import { install } from 'undici'
329
+
330
+ // Install undici's global web APIs
331
+ install()
332
+
333
+ // Now you can use fetch classes globally without importing
334
+ const response = await fetch('https://api.example.com/data')
335
+ const data = await response.json()
336
+
337
+ // All classes are available globally:
338
+ const headers = new Headers([['content-type', 'application/json']])
339
+ const request = new Request('https://example.com')
340
+ const formData = new FormData()
341
+ const ws = new WebSocket('wss://example.com')
342
+ const eventSource = new EventSource('https://example.com/events')
343
+ ```
344
+
345
+ The `install()` function adds the following classes to `globalThis`:
346
+
347
+ - `fetch` - The fetch function
348
+ - `Headers` - HTTP headers management
349
+ - `Response` - HTTP response representation
350
+ - `Request` - HTTP request representation
351
+ - `FormData` - Form data handling
352
+ - `WebSocket` - WebSocket client
353
+ - `CloseEvent`, `ErrorEvent`, `MessageEvent` - WebSocket events
354
+ - `EventSource` - Server-sent events client
355
+
356
+ When you call `install()`, these globals come from the same undici
357
+ implementation. For example, global `fetch` and global `FormData` will both be
358
+ undici's versions, and `WebSocket` and `EventSource` will also come from
359
+ undici, which is the recommended setup if you want to use undici through
360
+ globals.
361
+
362
+ This is useful for:
363
+ - Polyfilling environments that don't have fetch
364
+ - Ensuring consistent fetch behavior across different Node.js versions
365
+ - Making undici's implementations available globally for libraries that expect them
366
+
367
+ ## Body Mixins
368
+
369
+ The `body` mixins are the most common way to format the request/response body. Mixins include:
370
+
371
+ - [`.arrayBuffer()`](https://fetch.spec.whatwg.org/#dom-body-arraybuffer)
372
+ - [`.blob()`](https://fetch.spec.whatwg.org/#dom-body-blob)
373
+ - [`.bytes()`](https://fetch.spec.whatwg.org/#dom-body-bytes)
374
+ - [`.json()`](https://fetch.spec.whatwg.org/#dom-body-json)
375
+ - [`.text()`](https://fetch.spec.whatwg.org/#dom-body-text)
376
+
377
+ > [!NOTE]
378
+ > The body returned from `undici.request` does not implement `.formData()`.
379
+
380
+ > [!WARNING]
381
+ > Calling `body.formData()` on a fetch response causes undici to buffer and parse the entire body. Since this is dictated by the spec, `body.formData()` must only be called on responses from trusted servers.
382
+
383
+ Example usage:
384
+
385
+ ```js
386
+ import { request } from 'undici'
387
+
388
+ const {
389
+ statusCode,
390
+ headers,
391
+ trailers,
392
+ body
393
+ } = await request('http://localhost:3000/foo')
394
+
395
+ console.log('response received', statusCode)
396
+ console.log('headers', headers)
397
+ console.log('data', await body.json())
398
+ console.log('trailers', trailers)
399
+ ```
400
+
401
+ _Note: Once a mixin has been called then the body cannot be reused, thus calling additional mixins on `.body`, e.g. `.body.json(); .body.text()` will result in an error `TypeError: unusable` being thrown and returned through the `Promise` rejection._
402
+
403
+ Should you need to access the `body` in plain-text after using a mixin, the best practice is to use the `.text()` mixin first and then manually parse the text to the desired format.
404
+
405
+ For more information about their behavior, please reference the body mixin from the [Fetch Standard](https://fetch.spec.whatwg.org/#body-mixin).
406
+
407
+ ## Common API Methods
408
+
409
+ This section documents our most commonly used API methods. Additional APIs are documented in their own files within the [docs](./docs/) folder and are accessible via the navigation list on the left side of the docs site.
410
+
411
+ ### `undici.request([url, options]): Promise`
412
+
413
+ Arguments:
414
+
415
+ * **url** `string | URL | UrlObject`
416
+ * **options** [`RequestOptions`](./docs/docs/api/Dispatcher.md#parameter-requestoptions)
417
+ * **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
418
+ * **method** `String` - Default: `PUT` if `options.body`, otherwise `GET`
419
+
420
+ Returns a promise with the result of the `Dispatcher.request` method.
421
+
422
+ Calls `options.dispatcher.request(options)`.
423
+
424
+ See [Dispatcher.request](./docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback) for more details, and [request examples](./docs/examples/README.md) for examples.
425
+
426
+ ### `undici.stream([url, options, ]factory): Promise`
427
+
428
+ Arguments:
429
+
430
+ * **url** `string | URL | UrlObject`
431
+ * **options** [`StreamOptions`](./docs/docs/api/Dispatcher.md#parameter-streamoptions)
432
+ * **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
433
+ * **method** `String` - Default: `PUT` if `options.body`, otherwise `GET`
434
+ * **factory** `Dispatcher.stream.factory`
435
+
436
+ Returns a promise with the result of the `Dispatcher.stream` method.
437
+
438
+ Calls `options.dispatcher.stream(options, factory)`.
439
+
440
+ See [Dispatcher.stream](./docs/docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback) for more details.
441
+
442
+ ### `undici.pipeline([url, options, ]handler): Duplex`
443
+
444
+ Arguments:
445
+
446
+ * **url** `string | URL | UrlObject`
447
+ * **options** [`PipelineOptions`](./docs/docs/api/Dispatcher.md#parameter-pipelineoptions)
448
+ * **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
449
+ * **method** `String` - Default: `PUT` if `options.body`, otherwise `GET`
450
+ * **handler** `Dispatcher.pipeline.handler`
451
+
452
+ Returns: `stream.Duplex`
453
+
454
+ Calls `options.dispatch.pipeline(options, handler)`.
455
+
456
+ See [Dispatcher.pipeline](./docs/docs/api/Dispatcher.md#dispatcherpipelineoptions-handler) for more details.
457
+
458
+ ### `undici.connect([url, options]): Promise`
459
+
460
+ Starts two-way communications with the requested resource using [HTTP CONNECT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT).
461
+
462
+ Arguments:
463
+
464
+ * **url** `string | URL | UrlObject`
465
+ * **options** [`ConnectOptions`](./docs/docs/api/Dispatcher.md#parameter-connectoptions)
466
+ * **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
467
+ * **callback** `(err: Error | null, data: ConnectData | null) => void` (optional)
468
+
469
+ Returns a promise with the result of the `Dispatcher.connect` method.
470
+
471
+ Calls `options.dispatch.connect(options)`.
472
+
473
+ See [Dispatcher.connect](./docs/docs/api/Dispatcher.md#dispatcherconnectoptions-callback) for more details.
474
+
475
+ ### `undici.fetch(input[, init]): Promise`
476
+
477
+ Implements [fetch](https://fetch.spec.whatwg.org/#fetch-method).
478
+
479
+ * https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch
480
+ * https://fetch.spec.whatwg.org/#fetch-method
481
+
482
+ Basic usage example:
483
+
484
+ ```js
485
+ import { fetch } from 'undici'
486
+
487
+
488
+ const res = await fetch('https://example.com')
489
+ const json = await res.json()
490
+ console.log(json)
491
+ ```
492
+
493
+ You can pass an optional dispatcher to `fetch` as:
494
+
495
+ ```js
496
+ import { fetch, Agent } from 'undici'
497
+
498
+ const res = await fetch('https://example.com', {
499
+ // Mocks are also supported
500
+ dispatcher: new Agent({
501
+ keepAliveTimeout: 10,
502
+ keepAliveMaxTimeout: 10
503
+ })
504
+ })
505
+ const json = await res.json()
506
+ console.log(json)
507
+ ```
508
+
509
+ #### `request.body`
510
+
511
+ A body can be of the following types:
512
+
513
+ - ArrayBuffer
514
+ - ArrayBufferView
515
+ - AsyncIterables
516
+ - Blob
517
+ - Iterables
518
+ - String
519
+ - URLSearchParams
520
+ - FormData
521
+
522
+ In this implementation of fetch, ```request.body``` now accepts ```Async Iterables```. It is not present in the [Fetch Standard](https://fetch.spec.whatwg.org).
523
+
524
+ ```js
525
+ import { fetch } from 'undici'
526
+
527
+ const data = {
528
+ async *[Symbol.asyncIterator]() {
529
+ yield 'hello'
530
+ yield 'world'
531
+ },
532
+ }
533
+
534
+ await fetch('https://example.com', { body: data, method: 'POST', duplex: 'half' })
535
+ ```
536
+
537
+ [FormData](https://developer.mozilla.org/en-US/docs/Web/API/FormData) besides text data and buffers can also utilize streams via [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) objects:
538
+
539
+ ```js
540
+ import { openAsBlob } from 'node:fs'
541
+
542
+ const file = await openAsBlob('./big.csv')
543
+ const body = new FormData()
544
+ body.set('file', file, 'big.csv')
545
+
546
+ await fetch('http://example.com', { method: 'POST', body })
547
+ ```
548
+
549
+ #### `request.duplex`
550
+
551
+ - `'half'`
552
+
553
+ In this implementation of fetch, `request.duplex` must be set if `request.body` is `ReadableStream` or `Async Iterables`, however, even though the value must be set to `'half'`, it is actually a _full_ duplex. For more detail refer to the [Fetch Standard](https://fetch.spec.whatwg.org/#dom-requestinit-duplex).
554
+
555
+ #### `response.body`
556
+
557
+ Nodejs has two kinds of streams: [web streams](https://nodejs.org/api/webstreams.html), which follow the API of the WHATWG web standard found in browsers, and an older Node-specific [streams API](https://nodejs.org/api/stream.html). `response.body` returns a readable web stream. If you would prefer to work with a Node stream you can convert a web stream using `.fromWeb()`.
558
+
559
+ ```js
560
+ import { fetch } from 'undici'
561
+ import { Readable } from 'node:stream'
562
+
563
+ const response = await fetch('https://example.com')
564
+ const readableWebStream = response.body
565
+ const readableNodeStream = Readable.fromWeb(readableWebStream)
566
+ ```
567
+
568
+ ## Specification Compliance
569
+
570
+ This section documents parts of the [HTTP/1.1](https://www.rfc-editor.org/rfc/rfc9110.html) and [Fetch Standard](https://fetch.spec.whatwg.org) that Undici does
571
+ not support or does not fully implement.
572
+
573
+ #### CORS
574
+
575
+ Unlike browsers, Undici does not implement CORS (Cross-Origin Resource Sharing) checks by default. This means:
576
+
577
+ - No preflight requests are automatically sent for cross-origin requests
578
+ - No validation of `Access-Control-Allow-Origin` headers is performed
579
+ - Requests to any origin are allowed regardless of the source
580
+
581
+ This behavior is intentional for server-side environments where CORS restrictions are typically unnecessary. If your application requires CORS-like protections, you will need to implement these checks manually.
582
+
583
+ #### Garbage Collection
584
+
585
+ * https://fetch.spec.whatwg.org/#garbage-collection
586
+
587
+ The [Fetch Standard](https://fetch.spec.whatwg.org) allows users to skip consuming the response body by relying on
588
+ [garbage collection](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Memory_Management#garbage_collection) to release connection resources.
589
+
590
+ Garbage collection in Node is less aggressive and deterministic
591
+ (due to the lack of clear idle periods that browsers have through the rendering refresh rate)
592
+ which means that leaving the release of connection resources to the garbage collector can lead
593
+ to excessive connection usage, reduced performance (due to less connection re-use), and even
594
+ stalls or deadlocks when running out of connections.
595
+ Therefore, __it is important to always either consume or cancel the response body anyway__.
596
+
597
+ ```js
598
+ // Do
599
+ const { body, headers } = await fetch(url);
600
+ for await (const chunk of body) {
601
+ // force consumption of body
602
+ }
603
+
604
+ // Do not
605
+ const { headers } = await fetch(url);
606
+ ```
607
+
608
+ However, if you want to get only headers, it might be better to use `HEAD` request method. Usage of this method will obviate the need for consumption or cancelling of the response body. See [MDN - HTTP - HTTP request methods - HEAD](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) for more details.
609
+
610
+ ```js
611
+ const headers = await fetch(url, { method: 'HEAD' })
612
+ .then(res => res.headers)
613
+ ```
614
+
615
+ Note that consuming the response body is _mandatory_ for `request`:
616
+
617
+ ```js
618
+ // Do
619
+ const { body, headers } = await request(url);
620
+ await body.dump(); // force consumption of body
621
+
622
+ // Do not
623
+ const { headers } = await request(url);
624
+ ```
625
+
626
+ #### Forbidden and Safelisted Header Names
627
+
628
+ * https://fetch.spec.whatwg.org/#cors-safelisted-response-header-name
629
+ * https://fetch.spec.whatwg.org/#forbidden-header-name
630
+ * https://fetch.spec.whatwg.org/#forbidden-response-header-name
631
+ * https://github.com/wintercg/fetch/issues/6
632
+
633
+ The [Fetch Standard](https://fetch.spec.whatwg.org) requires implementations to exclude certain headers from requests and responses. In browser environments, some headers are forbidden so the user agent remains in full control over them. In Undici, these constraints are removed to give more control to the user.
634
+
635
+ #### Content-Encoding
636
+
637
+ * https://www.rfc-editor.org/rfc/rfc9110#field.content-encoding
638
+
639
+ Undici limits the number of `Content-Encoding` layers in a response to **5** to prevent resource exhaustion attacks. If a server responds with more than 5 content-encodings (e.g., `Content-Encoding: gzip, gzip, gzip, gzip, gzip, gzip`), the fetch will be rejected with an error. This limit matches the approach taken by [curl](https://curl.se/docs/CVE-2022-32206.html) and [urllib3](https://github.com/advisories/GHSA-gm62-xv2j-4rw9).
640
+
641
+ #### `undici.upgrade([url, options]): Promise`
642
+
643
+ Upgrade to a different protocol. See [MDN - HTTP - Protocol upgrade mechanism](https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism) for more details.
644
+
645
+ Arguments:
646
+
647
+ * **url** `string | URL | UrlObject`
648
+ * **options** [`UpgradeOptions`](./docs/docs/api/Dispatcher.md#parameter-upgradeoptions)
649
+ * **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
650
+ * **callback** `(error: Error | null, data: UpgradeData) => void` (optional)
651
+
652
+ Returns a promise with the result of the `Dispatcher.upgrade` method.
653
+
654
+ Calls `options.dispatcher.upgrade(options)`.
655
+
656
+ See [Dispatcher.upgrade](./docs/docs/api/Dispatcher.md#dispatcherupgradeoptions-callback) for more details.
657
+
658
+ ### `undici.setGlobalDispatcher(dispatcher)`
659
+
660
+ * dispatcher `Dispatcher`
661
+
662
+ Sets the global dispatcher used by Common API Methods. Global dispatcher is shared among compatible undici modules,
663
+ including undici that is bundled internally with node.js.
664
+
665
+ Undici stores this dispatcher under `Symbol.for('undici.globalDispatcher.2')`.
666
+
667
+ `setGlobalDispatcher()` also mirrors the configured dispatcher to
668
+ `Symbol.for('undici.globalDispatcher.1')` using `Dispatcher1Wrapper`, so Node.js built-in `fetch`
669
+ can keep using the legacy handler contract while Undici uses the new handler API.
670
+
671
+ ### `undici.getGlobalDispatcher()`
672
+
673
+ Gets the global dispatcher used by Common API Methods.
674
+
675
+ Returns: `Dispatcher`
676
+
677
+ ### `undici.setGlobalOrigin(origin)`
678
+
679
+ * origin `string | URL | undefined`
680
+
681
+ Sets the global origin used in `fetch`.
682
+
683
+ If `undefined` is passed, the global origin will be reset. This will cause `Response.redirect`, `new Request()`, and `fetch` to throw an error when a relative path is passed.
684
+
685
+ ```js
686
+ setGlobalOrigin('http://localhost:3000')
687
+
688
+ const response = await fetch('/api/ping')
689
+
690
+ console.log(response.url) // http://localhost:3000/api/ping
691
+ ```
692
+
693
+ ### `undici.getGlobalOrigin()`
694
+
695
+ Gets the global origin used in `fetch`.
696
+
697
+ Returns: `URL`
698
+
699
+ ### `UrlObject`
700
+
701
+ * **port** `string | number` (optional)
702
+ * **path** `string` (optional)
703
+ * **pathname** `string` (optional)
704
+ * **hostname** `string` (optional)
705
+ * **origin** `string` (optional)
706
+ * **protocol** `string` (optional)
707
+ * **search** `string` (optional)
708
+
709
+ #### Expect
710
+
711
+ Undici does not support the `Expect` request header field. The request
712
+ body is always immediately sent and the `100 Continue` response will be
713
+ ignored.
714
+
715
+ Refs: https://tools.ietf.org/html/rfc7231#section-5.1.1
716
+
717
+ #### Pipelining
718
+
719
+ Undici will only use pipelining if configured with a `pipelining` factor
720
+ greater than `1`. Also it is important to pass `blocking: false` to the
721
+ request options to properly pipeline requests.
722
+
723
+ Undici always assumes that connections are persistent and will immediately
724
+ pipeline requests, without checking whether the connection is persistent.
725
+ Hence, automatic fallback to HTTP/1.0 or HTTP/1.1 without pipelining is
726
+ not supported.
727
+
728
+ Undici will immediately pipeline when retrying requests after a failed
729
+ connection. However, Undici will not retry the first remaining requests in
730
+ the prior pipeline and instead error the corresponding callback/promise/stream.
731
+
732
+ Undici will abort all running requests in the pipeline when any of them are
733
+ aborted.
734
+
735
+ * Refs: https://tools.ietf.org/html/rfc2616#section-8.1.2.2
736
+ * Refs: https://tools.ietf.org/html/rfc7230#section-6.3.2
737
+
738
+ #### Manual Redirect
739
+
740
+ Since it is not possible to manually follow an HTTP redirect on the server-side,
741
+ Undici returns the actual response instead of an `opaqueredirect` filtered one
742
+ when invoked with a `manual` redirect. This aligns `fetch()` with the other
743
+ implementations in Deno and Cloudflare Workers.
744
+
745
+ Refs: https://fetch.spec.whatwg.org/#atomic-http-redirect-handling
746
+
747
+ ### Workarounds
748
+
749
+ #### Network address family autoselection.
750
+
751
+ If you experience problem when connecting to a remote server that is resolved by your DNS servers to a IPv6 (AAAA record)
752
+ first, there are chances that your local router or ISP might have problem connecting to IPv6 networks. In that case
753
+ undici will throw an error with code `UND_ERR_CONNECT_TIMEOUT`.
754
+
755
+ If the target server resolves to both a IPv6 and IPv4 (A records) address and you are using a compatible Node version
756
+ (18.3.0 and above), you can fix the problem by providing the `autoSelectFamily` option (support by both `undici.request`
757
+ and `undici.Agent`) which will enable the family autoselection algorithm when establishing the connection.
758
+
759
+ ## Collaborators
760
+
761
+ * [__Daniele Belardi__](https://github.com/dnlup), <https://www.npmjs.com/~dnlup>
762
+ * [__Ethan Arrowood__](https://github.com/ethan-arrowood), <https://www.npmjs.com/~ethan_arrowood>
763
+ * [__Matteo Collina__](https://github.com/mcollina), <https://www.npmjs.com/~matteo.collina>
764
+ * [__Matthew Aitken__](https://github.com/KhafraDev), <https://www.npmjs.com/~khaf>
765
+ * [__Robert Nagy__](https://github.com/ronag), <https://www.npmjs.com/~ronag>
766
+ * [__Szymon Marczak__](https://github.com/szmarczak), <https://www.npmjs.com/~szmarczak>
767
+
768
+ ## Past Collaborators
769
+ * [__Tomas Della Vedova__](https://github.com/delvedor), <https://www.npmjs.com/~delvedor>
770
+
771
+ ### Releasers
772
+
773
+ * [__Ethan Arrowood__](https://github.com/ethan-arrowood), <https://www.npmjs.com/~ethan_arrowood>
774
+ * [__Matteo Collina__](https://github.com/mcollina), <https://www.npmjs.com/~matteo.collina>
775
+ * [__Robert Nagy__](https://github.com/ronag), <https://www.npmjs.com/~ronag>
776
+ * [__Matthew Aitken__](https://github.com/KhafraDev), <https://www.npmjs.com/~khaf>
777
+
778
+ ## Long Term Support
779
+
780
+ Undici aligns with the Node.js LTS schedule. The following table shows the supported versions:
781
+
782
+ | Undici Version | Bundled in Node.js | Node.js Versions Supported | End of Life |
783
+ |----------------|--------------------|----------------------------|-------------|
784
+ | 5.x | 18.x | ≥14.0 (tested: 14, 16, 18) | 2024-04-30 |
785
+ | 6.x | 20.x, 22.x | ≥18.17 (tested: 18, 20, 21, 22) | 2027-04-30 |
786
+ | 7.x | 24.x | ≥20.18.1 (tested: 20, 22, 24) | 2028-04-30 |
787
+ | 8.x | 26.x | ≥22.19.0 (tested: 22, 24, 26) | 2029-04-30 |
788
+
789
+ ## License
790
+
791
+ MIT