undici 8.11.2 → 8.12.0

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 (58) hide show
  1. package/README.md +25 -3
  2. package/docs/docs/api/CacheStore.md +24 -9
  3. package/docs/docs/api/Client.md +4 -4
  4. package/docs/docs/api/Dispatcher.md +3 -0
  5. package/docs/docs/api/Errors.md +76 -1
  6. package/docs/docs/api/H2CClient.md +3 -2
  7. package/docs/docs/api/Interceptors.md +13 -6
  8. package/docs/docs/api/RedirectHandler.md +13 -10
  9. package/docs/docs/index.md +12 -12
  10. package/docs/docs/type-map.json +66 -66
  11. package/lib/cache/memory-cache-store.js +48 -13
  12. package/lib/cache/sqlite-cache-store.js +83 -5
  13. package/lib/core/connect.js +10 -4
  14. package/lib/core/constants.js +12 -1
  15. package/lib/core/errors.js +38 -1
  16. package/lib/core/request.js +16 -1
  17. package/lib/core/symbols.js +1 -0
  18. package/lib/core/util.js +26 -1
  19. package/lib/dispatcher/client-h1.js +116 -78
  20. package/lib/dispatcher/client-h2.js +46 -10
  21. package/lib/dispatcher/client.js +4 -1
  22. package/lib/dispatcher/dispatcher-base.js +3 -2
  23. package/lib/dispatcher/dispatcher1-wrapper.js +20 -3
  24. package/lib/dispatcher/parser-h1.js +1064 -0
  25. package/lib/dispatcher/pool-base.js +65 -28
  26. package/lib/dispatcher/pool.js +11 -8
  27. package/lib/dispatcher/proxy-agent.js +18 -8
  28. package/lib/dispatcher/retry-agent.js +10 -0
  29. package/lib/dispatcher/round-robin-pool.js +15 -5
  30. package/lib/handler/cache-handler.js +95 -15
  31. package/lib/handler/deduplication-handler.js +55 -38
  32. package/lib/handler/redirect-handler.js +13 -7
  33. package/lib/handler/retry-handler.js +44 -11
  34. package/lib/interceptor/cache.js +11 -3
  35. package/lib/interceptor/decompress.js +7 -4
  36. package/lib/interceptor/dns.js +11 -0
  37. package/lib/interceptor/response-error.js +72 -28
  38. package/lib/milo/LICENSE.md +7 -0
  39. package/lib/milo/no-simd.js +1002 -0
  40. package/lib/milo/simd.js +1002 -0
  41. package/lib/mock/mock-agent.js +11 -0
  42. package/lib/mock/snapshot-recorder.js +3 -2
  43. package/lib/mock/snapshot-utils.js +3 -2
  44. package/lib/util/cache.js +11 -5
  45. package/lib/web/cookies/util.js +19 -2
  46. package/lib/web/eventsource/eventsource-stream.js +32 -0
  47. package/lib/web/eventsource/eventsource.js +25 -2
  48. package/lib/web/fetch/body.js +47 -38
  49. package/lib/web/fetch/formdata-parser.js +12 -4
  50. package/lib/web/fetch/headers.js +2 -2
  51. package/lib/web/fetch/index.js +5 -1
  52. package/lib/web/websocket/receiver.js +12 -4
  53. package/package.json +6 -5
  54. package/types/cache-interceptor.d.ts +10 -0
  55. package/types/client.d.ts +4 -2
  56. package/types/errors.d.ts +16 -1
  57. package/types/h2c-client.d.ts +1 -1
  58. package/types/interceptors.d.ts +6 -1
package/README.md CHANGED
@@ -86,6 +86,24 @@ Using [benchmark-http2.js](https://github.com/nodejs/undici/blob/main/benchmarks
86
86
 
87
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
88
 
89
+ ### WebAssembly requirement
90
+
91
+ Undici's HTTP/1 parser requires WebAssembly. There is no alternative parser when
92
+ WebAssembly is unavailable, for example in Node.js configurations where
93
+ `--jitless` disables it. The existence of `fetch` does not imply that it can make
94
+ HTTP/1 requests in that environment.
95
+
96
+ When the HTTP/1 parser is needed without WebAssembly, Client and dispatcher
97
+ requests fail with an `Error` whose code is `ERR_WEBASSEMBLY_NOT_SUPPORTED`.
98
+ `fetch` rejects with a `TypeError` carrying that error in `error.cause`. Importing
99
+ Undici, accessing `fetch`, and using `Headers`, `FormData`, `Request`, or `Response`
100
+ do not themselves require the HTTP/1 parser.
101
+
102
+ The error is defined locally in Undici and does not depend on Node.js providing
103
+ that error code. For built-in fetch, this behavior depends on the bundled Undici
104
+ version. Node.js receives upstream fixes through its normal vendored Undici
105
+ update, rather than changes to the generated bundle alone.
106
+
89
107
  ### Built-in Fetch (Node.js v18+)
90
108
 
91
109
  Node.js's built-in fetch is powered by a bundled version of undici:
@@ -773,14 +791,18 @@ and `undici.Agent`) which will enable the family autoselection algorithm when es
773
791
 
774
792
  ## Collaborators
775
793
 
776
- * [__Daniele Belardi__](https://github.com/dnlup), <https://www.npmjs.com/~dnlup>
777
- * [__Ethan Arrowood__](https://github.com/ethan-arrowood), <https://www.npmjs.com/~ethan_arrowood>
794
+ * [__Aras Abbasi__](https://github.com/Uzlopak)
795
+ * [__Carlos Fuentes__](https://github.com/metcoder95), <https://www.npmjs.com/~metcoder95>
796
+ * [__Ethan Arrowood__](https://github.com/Ethan-Arrowood), <https://www.npmjs.com/~ethan_arrowood>
778
797
  * [__Matteo Collina__](https://github.com/mcollina), <https://www.npmjs.com/~matteo.collina>
779
798
  * [__Matthew Aitken__](https://github.com/KhafraDev), <https://www.npmjs.com/~khaf>
799
+ * [__Mert Can Altin__](https://github.com/mertcanaltin), <https://www.npmjs.com/~mertcanaltin>
780
800
  * [__Robert Nagy__](https://github.com/ronag), <https://www.npmjs.com/~ronag>
781
- * [__Szymon Marczak__](https://github.com/szmarczak), <https://www.npmjs.com/~szmarczak>
801
+ * [__Trivikram Kamat__](https://github.com/trivikr), <https://www.npmjs.com/~trivikr>
802
+ * [__tsctx__](https://github.com/tsctx)
782
803
 
783
804
  ## Past Collaborators
805
+ * [__Szymon Marczak__](https://github.com/szmarczak), <https://www.npmjs.com/~szmarczak>
784
806
  * [__Tomas Della Vedova__](https://github.com/delvedor), <https://www.npmjs.com/~delvedor>
785
807
 
786
808
  ### Releasers
@@ -42,7 +42,8 @@ added: v7.0.0
42
42
  Stores cached responses in memory. The store enforces upper bounds on the total
43
43
  number of responses, the total size of all responses, and the size of any single
44
44
  response. When a limit is exceeded, the store evicts approximately half of its
45
- entries and emits a [`'maxSizeExceeded'`](#event-maxsizeexceeded) event.
45
+ entries, least recently used first, and emits a
46
+ [`'maxSizeExceeded'`](#event-maxsizeexceeded) event.
46
47
 
47
48
  ```mjs
48
49
  import { interceptors, cacheStores, Agent, setGlobalDispatcher } from 'undici'
@@ -163,7 +164,9 @@ added: v7.0.0
163
164
  -->
164
165
 
165
166
  Stores cached responses in a SQLite database using the [`node:sqlite`][] API.
166
- The constructor throws when [`node:sqlite`][] is not available.
167
+ The constructor throws when [`node:sqlite`][] is not available. Response bodies
168
+ larger than `compressThreshold` are stored compressed with zstd and
169
+ decompressed when read back, saving database space.
167
170
 
168
171
  ```mjs
169
172
  import { interceptors, cacheStores, Agent, setGlobalDispatcher } from 'undici'
@@ -189,9 +192,16 @@ added: v7.0.0
189
192
  * `maxEntrySize` {number} The maximum size, in bytes, of a single response
190
193
  body. Responses whose body exceeds this value are not cached. Must not
191
194
  exceed `2000000000` (2 GB). **Default:** `2000000000` (2 GB).
195
+ * `compressThreshold` {number} The size, in bytes, above which a response
196
+ body is stored compressed with zstd. Responses with an easily compressible
197
+ Content-Type (e.g. json, xml, plain text) are compressed regardless of
198
+ size. Requires a Node version with zstd
199
+ support (22.19+); when unavailable, bodies are stored uncompressed.
200
+ **Default:** `1048576` (1 MiB).
192
201
 
193
- `maxCount` and `maxEntrySize` must be non-negative integers; a `TypeError` is
194
- thrown otherwise, or if `maxEntrySize` is greater than 2 GB.
202
+ `maxCount`, `maxEntrySize`, and `compressThreshold` must be non-negative
203
+ integers; a `TypeError` is thrown otherwise, or if `maxEntrySize` is greater
204
+ than 2 GB.
195
205
 
196
206
  ### `sqliteCacheStore.close()`
197
207
 
@@ -225,7 +235,8 @@ added: v7.0.0
225
235
  See [`GetResult`](#getresult).
226
236
 
227
237
  Looks up a cached response for `key`, comparing the request method and every
228
- header named in the stored `vary` map.
238
+ header named in the stored `vary` map. A body that was stored compressed is
239
+ decompressed before being returned.
229
240
 
230
241
  ### `sqliteCacheStore.set(key, value)`
231
242
 
@@ -240,9 +251,11 @@ added: v7.0.0
240
251
  * Returns: {undefined}
241
252
 
242
253
  Writes a response into the database directly, without going through a stream. If
243
- the body exceeds `maxEntrySize`, nothing is stored. When an entry already exists
244
- for `key` it is overwritten; otherwise a new row is inserted and old entries are
245
- pruned to honour `maxCount`. This method is used internally by
254
+ the body exceeds `maxEntrySize`, nothing is stored. A body larger than
255
+ `compressThreshold`, or with an easily compressible Content-Type (e.g. json,
256
+ xml, plain text), is compressed with zstd before being written. When an entry
257
+ already exists for `key` it is overwritten; otherwise a new row is inserted and
258
+ old entries are pruned to honour `maxCount`. This method is used internally by
246
259
  [`sqliteCacheStore.createWriteStream()`](#sqlitecachestorecreatewritestreamkey-value).
247
260
 
248
261
  ### `sqliteCacheStore.createWriteStream(key, value)`
@@ -260,7 +273,9 @@ added: v7.0.0
260
273
 
261
274
  Returns a {Writable} stream used to write the response body into the store. When
262
275
  the stream finishes, the buffered body is committed via
263
- [`sqliteCacheStore.set()`](#sqlitecachestoresetkey-value). If the body exceeds
276
+ [`sqliteCacheStore.set()`](#sqlitecachestoresetkey-value), where bodies larger
277
+ than `compressThreshold` or with an easily compressible Content-Type are
278
+ compressed with zstd. If the body exceeds
264
279
  `maxEntrySize`, the stream is destroyed and nothing is stored.
265
280
 
266
281
  ### `sqliteCacheStore.delete(key)`
@@ -116,8 +116,8 @@ added: v1.0.0
116
116
  * `maxConcurrentStreams` {number} _Deprecated: use h2Options.useH2c instead_ The maximum number of concurrent HTTP/2
117
117
  streams for a single session. Once h2 is negotiated this — not `pipelining`,
118
118
  which is HTTP/1.1 only — is the ceiling used to dispatch in-flight requests.
119
- It may be overridden by the server's `SETTINGS_MAX_CONCURRENT_STREAMS`
120
- frame. **Default:** `100`.
119
+ The server's `SETTINGS_MAX_CONCURRENT_STREAMS` can lower this limit, but
120
+ not raise it. **Default:** `100`.
121
121
  * `connectionWindowSize` {number} _Deprecated: use h2Options.connectionWindowSize instead_ The HTTP/2 connection-level flow-control
122
122
  window size set via `ClientHttp2Session.setLocalWindowSize()`. Must be a
123
123
  positive integer. **Default:** `524288`.
@@ -130,8 +130,8 @@ added: v1.0.0
130
130
  * `maxConcurrentStreams` {number} The maximum number of concurrent HTTP/2
131
131
  streams for a single session. Once h2 is negotiated this — not `pipelining`,
132
132
  which is HTTP/1.1 only — is the ceiling used to dispatch in-flight requests.
133
- It may be overridden by the server's `SETTINGS_MAX_CONCURRENT_STREAMS`
134
- frame. **Default:** `100`.
133
+ The server's `SETTINGS_MAX_CONCURRENT_STREAMS` can lower this limit, but
134
+ not raise it. **Default:** `100`.
135
135
  * `connectionWindowSize` {number} The HTTP/2 connection-level flow-control
136
136
  window size set via `ClientHttp2Session.setLocalWindowSize()`. Must be a
137
137
  positive integer. **Default:** `524288`.
@@ -209,6 +209,9 @@ added: v4.0.0
209
209
  * `path` {string} The request path.
210
210
  * `method` {string} The HTTP method, e.g. `'GET'` or `'POST'`.
211
211
  * `body` {string|Buffer|Uint8Array|Readable|FormData|null} The request body.
212
+ Undici's network clients require a `FormData` body created by the same
213
+ undici package instance. A body from another source, including Node.js's
214
+ built-in `FormData`, is rejected with an `InvalidArgumentError`.
212
215
  **Default:** `null`.
213
216
  * `headers` {UndiciHeaders} Request headers. **Default:** `null`.
214
217
  * `query` {Object} Query string parameters embedded into the request URL. Both
@@ -18,7 +18,7 @@ if (err instanceof errors.ConnectTimeoutError) {
18
18
  }
19
19
  ```
20
20
 
21
- All errors, except [`HTTPParserError`][], extend [`UndiciError`][]. Each error
21
+ All errors, except [`HTTPParserError`][] and `WebAssemblyNotSupportedError`, extend [`UndiciError`][]. Each error
22
22
  carries a stable `code` string (for example `UND_ERR_CONNECT_TIMEOUT`) and a
23
23
  `name`.
24
24
 
@@ -32,6 +32,37 @@ if (err.code === 'UND_ERR_CONNECT_TIMEOUT') {
32
32
  }
33
33
  ```
34
34
 
35
+ ## Timeout-related errors
36
+
37
+ The timeout errors below are controlled by dispatcher/client options:
38
+
39
+ | Error code | When it is thrown | Related option |
40
+ | ---------- | ----------------- | -------------- |
41
+ | `UND_ERR_CONNECT_TIMEOUT` | A connection could not be established before the connection timeout elapsed. | [`connect.timeout`](Client.md) |
42
+ | `UND_ERR_HEADERS_TIMEOUT` | The full response headers were not received before the headers timeout elapsed. | [`headersTimeout`](Client.md) |
43
+ | `UND_ERR_BODY_TIMEOUT` | While reading the response body, no new data arrived before the body timeout elapsed. | [`bodyTimeout`](Client.md) |
44
+ | `UND_ERR_SOCKET` | A generic socket-level failure happened. | Inspect `error.socket` for connection details. |
45
+
46
+ ### Configuring timeouts for `fetch`
47
+
48
+ If you are using `fetch` (including Node.js built-in `fetch`), configure timeouts
49
+ through the global dispatcher:
50
+
51
+ ```js
52
+ import { Agent, setGlobalDispatcher, fetch } from 'undici'
53
+
54
+ setGlobalDispatcher(new Agent({
55
+ connect: { timeout: 10_000 }, // connection phase
56
+ headersTimeout: 15_000, // wait for response headers
57
+ bodyTimeout: 30_000 // wait between response body chunks
58
+ }))
59
+
60
+ await fetch('https://example.com/data')
61
+ ```
62
+
63
+ You can inspect timeout error codes from `error.code` or (for wrapped fetch
64
+ errors) from `error.cause?.code`.
65
+
35
66
  ## Class: `UndiciError`
36
67
 
37
68
  <!-- YAML
@@ -52,6 +83,35 @@ on a well-known symbol rather than the prototype chain.
52
83
  * `name` {string} Always `'UndiciError'`.
53
84
  * `code` {string} Always `'UND_ERR'`.
54
85
 
86
+ ## Class: `WebAssemblyNotSupportedError`
87
+
88
+ * Extends: {Error}
89
+
90
+ WebAssembly is unavailable when Undici initializes its HTTP/1 parser. Undici does
91
+ not provide an alternative parser for environments without WebAssembly, including
92
+ Node.js configurations where `--jitless` disables it. The check is performed when
93
+ the parser is needed, not when importing Undici or accessing `fetch`.
94
+
95
+ * `name` {string} Always `'Error'`.
96
+ * `code` {string} Always `'ERR_WEBASSEMBLY_NOT_SUPPORTED'`.
97
+ * `message` {string} By default `'WebAssembly is not supported in this environment, but is required for HTTP/1 parsing'`.
98
+
99
+ Client and dispatcher requests report this error directly. `fetch` rejects with
100
+ a `TypeError` whose `cause` is this error:
101
+
102
+ ```js
103
+ try {
104
+ await fetch('http://localhost:3000')
105
+ } catch (error) {
106
+ if (error.cause?.code === 'ERR_WEBASSEMBLY_NOT_SUPPORTED') {
107
+ // HTTP/1 parsing requires WebAssembly in this environment.
108
+ }
109
+ }
110
+ ```
111
+
112
+ `Headers`, `FormData`, `Request`, `Response`, and other operations that do not need
113
+ the HTTP/1 parser remain usable without WebAssembly.
114
+
55
115
  ## Class: `ConnectTimeoutError`
56
116
 
57
117
  <!-- YAML
@@ -436,6 +496,7 @@ The response returned an error status code. This is raised, for example, when th
436
496
  * `code` {string} Always `'UND_ERR_RESPONSE'`.
437
497
  * `statusCode` {number} The HTTP status code of the response.
438
498
  * `body` {Object|string|null} The response body.
499
+ * `bodyTruncated` {boolean} Whether `body` was truncated by a configured limit.
439
500
  * `headers` {Object|string[]|null} The response headers.
440
501
 
441
502
  ### `new ResponseError(message, code, options)`
@@ -445,6 +506,7 @@ The response returned an error status code. This is raised, for example, when th
445
506
  * `options` {Object}
446
507
  * `headers` {Object|string[]|null} The response headers. (optional)
447
508
  * `body` {Object|string|null} The response body. (optional)
509
+ * `bodyTruncated` {boolean} Whether `body` was truncated. **Default:** `false`.
448
510
 
449
511
  ## Class: `ProxyConnectionError`
450
512
 
@@ -512,6 +574,19 @@ The maximum number of allowed origins has been reached.
512
574
  * `name` {string} Always `'MaxOriginsReachedError'`.
513
575
  * `code` {string} Always `'UND_ERR_MAX_ORIGINS_REACHED'`.
514
576
 
577
+ ## Class: `MaxRedirectsError`
578
+
579
+ <!-- YAML
580
+ added: v8.12.0
581
+ -->
582
+
583
+ * Extends: {UndiciError}
584
+
585
+ The maximum number of redirects has been reached.
586
+
587
+ * `name` {string} Always `'MaxRedirectsError'`.
588
+ * `code` {string} Always `'UND_ERR_REDIRECT_MAX'`.
589
+
515
590
  ## Class: `Socks5ProxyError`
516
591
 
517
592
  <!-- YAML
@@ -55,8 +55,9 @@ added: v7.7.0
55
55
  hostname, and port. Only the `http:` protocol is supported.
56
56
  * `options` {H2CClientOptions} (optional)
57
57
  * `maxConcurrentStreams` {number} The maximum number of concurrent HTTP/2
58
- streams for the session. It is advertised to the server and may be overridden
59
- by a remote `SETTINGS` frame. Must be a positive integer. **Default:** `100`.
58
+ streams for the session. The server's `SETTINGS_MAX_CONCURRENT_STREAMS` can
59
+ lower this limit, but not raise it. Must be a positive integer.
60
+ **Default:** `100`.
60
61
  * `pipelining` {number} The number of concurrent requests multiplexed over the
61
62
  single connection. For an `H2CClient` this is aliased to
62
63
  `maxConcurrentStreams` and may not exceed it. Must be a positive integer.
@@ -163,9 +163,10 @@ Follows HTTP redirects (3xx responses) automatically.
163
163
  * `maxRedirections` {number} Maximum number of redirects to follow. Passing
164
164
  `0` disables redirect following entirely. **Default:** `undefined`
165
165
  (inherits from the per-request `maxRedirections` option).
166
- * `throwOnMaxRedirect` {boolean} When `true`, throws an error once the
167
- redirect limit is reached instead of returning the final redirect response.
168
- **Default:** `false`.
166
+ * `throwOnMaxRedirect` {boolean} When `true`, throws an error when a
167
+ redirect would be followed but the redirect limit has been reached, instead
168
+ of returning that redirect response. A non-redirect response after exactly
169
+ `maxRedirections` redirects is returned normally. **Default:** `false`.
169
170
  * `stripHeadersOnRedirect` {string[]} List of header names to remove from
170
171
  the request when following any redirect. **Default:** `[]`.
171
172
  * `stripHeadersOnCrossOriginRedirect` {string[]} List of header names to
@@ -198,7 +199,10 @@ const agent = new Agent().compose(
198
199
  ## `interceptors.decompress([opts])`
199
200
 
200
201
  Automatically decompresses response bodies encoded with `gzip`, `x-gzip`,
201
- `br` (Brotli), `deflate`, `compress`, `x-compress`, or `zstd`.
202
+ `br` (Brotli), `deflate`, or `zstd`. Any other coding, including `compress`
203
+ and `x-compress`, is left untouched, matching `fetch()`. As required by
204
+ [RFC 9659](https://www.rfc-editor.org/rfc/rfc9659.html), a `zstd` frame that
205
+ requires a window size larger than 8 MB fails to decode.
202
206
 
203
207
  > **Experimental:** This interceptor is experimental and subject to change.
204
208
  > A one-time `ExperimentalWarning` is emitted on first use.
@@ -244,8 +248,11 @@ The error body is automatically decoded for `application/json` and
244
248
 
245
249
  **Parameters**
246
250
 
247
- * `opts` {Object} (optional) — currently reserved for future use; may be
248
- omitted.
251
+ * `opts` {Object} (optional)
252
+ * `maxSize` {number} Maximum number of response body bytes to include in the
253
+ error. If the body exceeds this limit, the resulting `ResponseError`
254
+ contains the retained prefix with `bodyTruncated` set to `true`. Set to `0`
255
+ to disable the limit. **Default:** `1048576` (1 MiB).
249
256
 
250
257
  **Returns:** {Dispatcher.DispatcherComposeInterceptor}
251
258
 
@@ -57,9 +57,10 @@ added: v4.0.0
57
57
  * `opts` {DispatchOptions} The dispatch options for the request. In addition to
58
58
  the standard dispatch options, the following redirect-specific fields are
59
59
  recognized:
60
- * `throwOnMaxRedirect` {boolean} When `true`, an error is thrown once
61
- `maxRedirections` is reached instead of returning the last redirect response.
62
- **Default:** `false`.
60
+ * `throwOnMaxRedirect` {boolean} When `true`, an error is thrown when a
61
+ redirect would be followed but `maxRedirections` has been reached, instead of
62
+ returning that redirect response. A non-redirect response after exactly
63
+ `maxRedirections` redirects is returned normally. **Default:** `false`.
63
64
  * `stripHeadersOnRedirect` {string[]} Header names to remove from the request on
64
65
  every redirect hop. **Default:** `null`.
65
66
  * `stripHeadersOnCrossOriginRedirect` {string[]} Additional header names to
@@ -165,13 +166,15 @@ added: v7.0.0
165
166
  * `statusMessage` {string} The HTTP status message.
166
167
 
167
168
  Inspects the response headers to decide whether to follow a redirect. When the
168
- status code is redirectable, the `maxRedirections` limit has not been reached, and
169
- the request body has not been consumed, the `location` property is set, the method
170
- and headers are adjusted for the next hop, and the response is not forwarded.
171
- Otherwise the event is forwarded to the wrapped `handler`.
172
-
173
- Throws when `throwOnMaxRedirect` is `true` and the number of recorded redirects
174
- has reached `maxRedirections`, and throws an [`InvalidArgumentError`][] if a
169
+ status code is redirectable, the response has a `Location` header, the
170
+ `maxRedirections` limit has not been reached, and the request body has not been
171
+ consumed, the `location` property is set, the method and headers are adjusted
172
+ for the next hop, and the response is not forwarded. Otherwise the event is
173
+ forwarded to the wrapped `handler`.
174
+
175
+ Throws when `throwOnMaxRedirect` is `true` and a redirect that would otherwise be
176
+ followed arrives after `maxRedirections` redirects have already been followed,
177
+ and throws an [`InvalidArgumentError`][] if a
175
178
  redirect loop is detected (for example when a [`Client`][] or [`Pool`][] is used
176
179
  for a cross-origin redirect; use an [`Agent`][] instead).
177
180
 
@@ -13,7 +13,7 @@ It is also a Stranger Things reference.
13
13
 
14
14
  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.
15
15
 
16
- Looking to contribute? Start by reading the [contributing guide](./CONTRIBUTING.md)
16
+ Looking to contribute? Start by reading the [contributing guide](https://github.com/nodejs/undici/blob/main/CONTRIBUTING.md)
17
17
 
18
18
  ## Install
19
19
 
@@ -417,7 +417,7 @@ For more information about their behavior, please reference the body mixin from
417
417
 
418
418
  ## Common API Methods
419
419
 
420
- 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.
420
+ This section documents our most commonly used API methods. Additional APIs are documented in their own files within the [`api`](./api/) folder and are accessible via the navigation list on the left side of the docs site.
421
421
 
422
422
  For the top-level APIs below, the `url` argument supplies the request origin and
423
423
  path. Do not pass `origin` or `path` in the second `options` argument. The linked
@@ -427,19 +427,19 @@ lower-level APIs that do not receive a separate `url` argument.
427
427
  ### `undici.request([url, options])`
428
428
 
429
429
  * `url` {string|URL|UrlObject}
430
- * `options` {RequestOptions} See [`RequestOptions`](./docs/docs/api/Dispatcher.md#parameter-requestoptions).
430
+ * `options` {RequestOptions} See [`RequestOptions`](./api/Dispatcher.md#parameter-requestoptions).
431
431
  * `dispatcher` {Dispatcher} **Default:** [getGlobalDispatcher](#undicigetglobaldispatcher).
432
432
  * `method` {string} **Default:** `PUT` if `options.body`, otherwise `GET`.
433
433
  * Returns: {Promise} A promise with the result of the `Dispatcher.request` method.
434
434
 
435
435
  Calls `options.dispatcher.request(options)`.
436
436
 
437
- See [Dispatcher.request](./docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback) for more details, and [request examples](./docs/examples/README.md) for examples.
437
+ See [Dispatcher.request](./api/Dispatcher.md#dispatcherrequestoptions-callback) for more details, and [request examples](https://github.com/nodejs/undici/blob/main/docs/examples/README.md) for examples.
438
438
 
439
439
  ### `undici.stream([url, options, ]factory)`
440
440
 
441
441
  * `url` {string|URL|UrlObject}
442
- * `options` {StreamOptions} See [`StreamOptions`](./docs/docs/api/Dispatcher.md#parameter-streamoptions).
442
+ * `options` {StreamOptions} See [`StreamOptions`](./api/Dispatcher.md#parameter-streamoptions).
443
443
  * `dispatcher` {Dispatcher} **Default:** [getGlobalDispatcher](#undicigetglobaldispatcher).
444
444
  * `method` {string} **Default:** `PUT` if `options.body`, otherwise `GET`.
445
445
  * `factory` {Function} `Dispatcher.stream.factory`.
@@ -447,12 +447,12 @@ See [Dispatcher.request](./docs/docs/api/Dispatcher.md#dispatcherrequestoptions-
447
447
 
448
448
  Calls `options.dispatcher.stream(options, factory)`.
449
449
 
450
- See [Dispatcher.stream](./docs/docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback) for more details.
450
+ See [Dispatcher.stream](./api/Dispatcher.md#dispatcherstreamoptions-factory-callback) for more details.
451
451
 
452
452
  ### `undici.pipeline([url, options, ]handler)`
453
453
 
454
454
  * `url` {string|URL|UrlObject}
455
- * `options` {PipelineOptions} See [`PipelineOptions`](./docs/docs/api/Dispatcher.md#parameter-pipelineoptions).
455
+ * `options` {PipelineOptions} See [`PipelineOptions`](./api/Dispatcher.md#parameter-pipelineoptions).
456
456
  * `dispatcher` {Dispatcher} **Default:** [getGlobalDispatcher](#undicigetglobaldispatcher).
457
457
  * `method` {string} **Default:** `PUT` if `options.body`, otherwise `GET`.
458
458
  * `handler` {Function} `Dispatcher.pipeline.handler`.
@@ -460,21 +460,21 @@ See [Dispatcher.stream](./docs/docs/api/Dispatcher.md#dispatcherstreamoptions-fa
460
460
 
461
461
  Calls `options.dispatch.pipeline(options, handler)`.
462
462
 
463
- See [Dispatcher.pipeline](./docs/docs/api/Dispatcher.md#dispatcherpipelineoptions-handler) for more details.
463
+ See [Dispatcher.pipeline](./api/Dispatcher.md#dispatcherpipelineoptions-handler) for more details.
464
464
 
465
465
  ### `undici.connect([url, options])`
466
466
 
467
467
  Starts two-way communications with the requested resource using [HTTP CONNECT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT).
468
468
 
469
469
  * `url` {string|URL|UrlObject}
470
- * `options` {ConnectOptions} See [`ConnectOptions`](./docs/docs/api/Dispatcher.md#parameter-connectoptions).
470
+ * `options` {ConnectOptions} See [`ConnectOptions`](./api/Dispatcher.md#parameter-connectoptions).
471
471
  * `dispatcher` {Dispatcher} **Default:** [getGlobalDispatcher](#undicigetglobaldispatcher).
472
472
  * `callback` {Function} (optional) — `(err, data) => void`.
473
473
  * Returns: {Promise} A promise with the result of the `Dispatcher.connect` method.
474
474
 
475
475
  Calls `options.dispatch.connect(options)`.
476
476
 
477
- See [Dispatcher.connect](./docs/docs/api/Dispatcher.md#dispatcherconnectoptions-callback) for more details.
477
+ See [Dispatcher.connect](./api/Dispatcher.md#dispatcherconnectoptions-callback) for more details.
478
478
 
479
479
  ### `undici.fetch(input[, init])`
480
480
 
@@ -647,14 +647,14 @@ Undici limits the number of `Content-Encoding` layers in a response to **5** to
647
647
  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.
648
648
 
649
649
  * `url` {string|URL|UrlObject}
650
- * `options` {UpgradeOptions} See [`UpgradeOptions`](./docs/docs/api/Dispatcher.md#parameter-upgradeoptions).
650
+ * `options` {UpgradeOptions} See [`UpgradeOptions`](./api/Dispatcher.md#parameter-upgradeoptions).
651
651
  * `dispatcher` {Dispatcher} **Default:** [getGlobalDispatcher](#undicigetglobaldispatcher).
652
652
  * `callback` {Function} (optional) — `(error, data) => void`.
653
653
  * Returns: {Promise} A promise with the result of the `Dispatcher.upgrade` method.
654
654
 
655
655
  Calls `options.dispatcher.upgrade(options)`.
656
656
 
657
- See [Dispatcher.upgrade](./docs/docs/api/Dispatcher.md#dispatcherupgradeoptions-callback) for more details.
657
+ See [Dispatcher.upgrade](./api/Dispatcher.md#dispatcherupgradeoptions-callback) for more details.
658
658
 
659
659
  ### `undici.setGlobalDispatcher(dispatcher)`
660
660
 
@@ -1,79 +1,79 @@
1
1
  {
2
- "AbortError": "/api/Errors.md#class-aborterror",
3
- "Agent": "/api/Agent.md#class-agent",
4
- "AgentDispatchOptions": "/api/Agent.md#agentdispatchoptions-handler",
5
- "AgentOptions": "/api/Agent.md#new-agentoptions",
6
- "BalancedPool": "/api/BalancedPool.md#class-balancedpool",
7
- "BalancedPoolOptions": "/api/BalancedPool.md#parameter-balancedpooloptions",
8
- "BodyMixin": "/api/Fetch.md#new-formdata",
2
+ "AbortError": "/api/Errors.html#class-aborterror",
3
+ "Agent": "/api/Agent.html#class-agent",
4
+ "AgentDispatchOptions": "/api/Agent.html#agentdispatchoptions-handler",
5
+ "AgentOptions": "/api/Agent.html#new-agentoptions",
6
+ "BalancedPool": "/api/BalancedPool.html#class-balancedpool",
7
+ "BalancedPoolOptions": "/api/BalancedPool.html#parameter-balancedpooloptions",
8
+ "BodyMixin": "/api/Fetch.html#new-formdata",
9
9
  "Buffer": "https://nodejs.org/api/buffer.html#class-buffer",
10
- "BuildOptions": "/api/Connector.md#buildconnectoroptions",
11
- "CacheKey": "/api/CacheStore.md#cachekey",
12
- "CacheStore": "/api/CacheStore.md#new-memorycachestoreoptions",
13
- "CacheValue": "/api/CacheStore.md#cachevalue",
14
- "ClientDestroyedError": "/api/Errors.md#class-clientdestroyederror",
15
- "ClientOptions": "/api/Client.md#new-clienturl-options",
16
- "ClientStats": "/api/ClientStats.md#class-clientstats",
17
- "ConnectOptions": "/api/Dispatcher.md#class-dispatcher",
18
- "Cookie": "/api/Cookies.md#cookie",
19
- "DispatchController": "/api/Dispatcher.md#class-dispatcher",
20
- "DispatchHandler": "/api/Dispatcher.md#class-dispatcher",
21
- "DispatchOptions": "/api/Dispatcher.md#class-dispatcher",
22
- "Dispatcher": "/api/Dispatcher.md#class-dispatcher",
10
+ "BuildOptions": "/api/Connector.html#buildconnectoroptions",
11
+ "CacheKey": "/api/CacheStore.html#cachekey",
12
+ "CacheStore": "/api/CacheStore.html#new-memorycachestoreoptions",
13
+ "CacheValue": "/api/CacheStore.html#cachevalue",
14
+ "ClientDestroyedError": "/api/Errors.html#class-clientdestroyederror",
15
+ "ClientOptions": "/api/Client.html#new-clienturl-options",
16
+ "ClientStats": "/api/ClientStats.html#class-clientstats",
17
+ "ConnectOptions": "/api/Dispatcher.html#class-dispatcher",
18
+ "Cookie": "/api/Cookies.html#cookie",
19
+ "DispatchController": "/api/Dispatcher.html#class-dispatcher",
20
+ "DispatchHandler": "/api/Dispatcher.html#class-dispatcher",
21
+ "DispatchOptions": "/api/Dispatcher.html#class-dispatcher",
22
+ "Dispatcher": "/api/Dispatcher.html#class-dispatcher",
23
23
  "Duplex": "https://nodejs.org/api/stream.html#class-streamduplex",
24
- "EnvHttpProxyAgent": "/api/EnvHttpProxyAgent.md#class-envhttpproxyagent",
25
- "EnvHttpProxyAgentOptions": "/api/EnvHttpProxyAgent.md#new-envhttpproxyagentoptions",
24
+ "EnvHttpProxyAgent": "/api/EnvHttpProxyAgent.html#class-envhttpproxyagent",
25
+ "EnvHttpProxyAgentOptions": "/api/EnvHttpProxyAgent.html#new-envhttpproxyagentoptions",
26
26
  "EventEmitter": "https://nodejs.org/api/events.html#class-eventemitter",
27
- "GetResult": "/api/CacheStore.md#getresult",
28
- "H2CClientOptions": "/api/H2CClient.md#new-h2cclienturl-options",
27
+ "GetResult": "/api/CacheStore.html#getresult",
28
+ "H2CClientOptions": "/api/H2CClient.html#new-h2cclienturl-options",
29
29
  "HeadersInit": "https://developer.mozilla.org/docs/Web/API/Headers/Headers",
30
- "InvalidArgumentError": "/api/Errors.md#class-invalidargumenterror",
30
+ "InvalidArgumentError": "/api/Errors.html#class-invalidargumenterror",
31
31
  "Iterable": "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Iteration_protocols",
32
- "MaxOriginsReachedError": "/api/Errors.md#class-maxoriginsreachederror",
33
- "MockAgent": "/api/MockAgent.md#class-mockagent",
34
- "MockAgentOptions": "/api/MockAgent.md#parameter-mockagentoptions",
35
- "MockCallHistory": "/api/MockCallHistory.md#class-mockcallhistory",
36
- "MockCallHistoryLog": "/api/MockCallHistoryLog.md#class-mockcallhistorylog",
37
- "MockClient": "/api/MockClient.md#class-mockclient",
38
- "MockClientOptions": "/api/MockClient.md#parameter-mockclientoptions",
39
- "MockInterceptor": "/api/MockPool.md#return-mockinterceptor",
40
- "MockInterceptor.Options": "/api/MockPool.md#parameter-mockpoolinterceptoptions",
41
- "MockPool": "/api/MockPool.md#class-mockpool",
42
- "MockPoolInterceptOptions": "/api/MockPool.md#parameter-mockpoolinterceptoptions",
43
- "MockPoolOptions": "/api/MockPool.md#parameter-mockpooloptions",
44
- "MockResponseOptions": "/api/MockPool.md#parameter-mockresponseoptions",
45
- "MockScope": "/api/MockPool.md#return-mockscope",
46
- "PendingInterceptor": "/api/MockAgent.md#new-mockagentoptions",
47
- "PipelineOptions": "/api/Dispatcher.md#class-dispatcher",
48
- "Pool": "/api/Pool.md#class-pool",
49
- "PoolOptions": "/api/Pool.md#new-poolurl-options",
50
- "PoolStats": "/api/PoolStats.md#class-poolstats",
51
- "ProxyAgent": "/api/ProxyAgent.md#class-proxyagent",
52
- "ProxyAgentOptions": "/api/ProxyAgent.md#new-proxyagentoptions",
32
+ "MaxOriginsReachedError": "/api/Errors.html#class-maxoriginsreachederror",
33
+ "MockAgent": "/api/MockAgent.html#class-mockagent",
34
+ "MockAgentOptions": "/api/MockAgent.html#parameter-mockagentoptions",
35
+ "MockCallHistory": "/api/MockCallHistory.html#class-mockcallhistory",
36
+ "MockCallHistoryLog": "/api/MockCallHistoryLog.html#class-mockcallhistorylog",
37
+ "MockClient": "/api/MockClient.html#class-mockclient",
38
+ "MockClientOptions": "/api/MockClient.html#parameter-mockclientoptions",
39
+ "MockInterceptor": "/api/MockPool.html#return-mockinterceptor",
40
+ "MockInterceptor.Options": "/api/MockPool.html#parameter-mockpoolinterceptoptions",
41
+ "MockPool": "/api/MockPool.html#class-mockpool",
42
+ "MockPoolInterceptOptions": "/api/MockPool.html#parameter-mockpoolinterceptoptions",
43
+ "MockPoolOptions": "/api/MockPool.html#parameter-mockpooloptions",
44
+ "MockResponseOptions": "/api/MockPool.html#parameter-mockresponseoptions",
45
+ "MockScope": "/api/MockPool.html#return-mockscope",
46
+ "PendingInterceptor": "/api/MockAgent.html#new-mockagentoptions",
47
+ "PipelineOptions": "/api/Dispatcher.html#class-dispatcher",
48
+ "Pool": "/api/Pool.html#class-pool",
49
+ "PoolOptions": "/api/Pool.html#new-poolurl-options",
50
+ "PoolStats": "/api/PoolStats.html#class-poolstats",
51
+ "ProxyAgent": "/api/ProxyAgent.html#class-proxyagent",
52
+ "ProxyAgentOptions": "/api/ProxyAgent.html#new-proxyagentoptions",
53
53
  "Readable": "https://nodejs.org/api/stream.html#class-streamreadable",
54
54
  "Record": "https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkeys-type",
55
- "RequestInit": "/api/Fetch.md#new-formdata",
56
- "RequestOptions": "/api/Dispatcher.md#class-dispatcher",
57
- "ResponseInit": "/api/Fetch.md#new-formdata",
58
- "RetryContext": "/api/RetryHandler.md#retrycontext",
59
- "RetryHandler": "/api/RetryHandler.md#class-retryhandler",
60
- "RetryHandlers": "/api/RetryHandler.md#parameter-retryhandlers",
61
- "RetryOptions": "/api/RetryHandler.md#retryoptions",
62
- "RetryState": "/api/RetryHandler.md#retrystate",
63
- "RoundRobinPoolOptions": "/api/RoundRobinPool.md#parameter-roundrobinpooloptions",
64
- "SnapshotRecorder": "/api/SnapshotAgent.md#new-snapshotagentoptions",
55
+ "RequestInit": "/api/Fetch.html#new-formdata",
56
+ "RequestOptions": "/api/Dispatcher.html#class-dispatcher",
57
+ "ResponseInit": "/api/Fetch.html#new-formdata",
58
+ "RetryContext": "/api/RetryHandler.html#retrycontext",
59
+ "RetryHandler": "/api/RetryHandler.html#class-retryhandler",
60
+ "RetryHandlers": "/api/RetryHandler.html#parameter-retryhandlers",
61
+ "RetryOptions": "/api/RetryHandler.html#retryoptions",
62
+ "RetryState": "/api/RetryHandler.html#retrystate",
63
+ "RoundRobinPoolOptions": "/api/RoundRobinPool.html#parameter-roundrobinpooloptions",
64
+ "SnapshotRecorder": "/api/SnapshotAgent.html#new-snapshotagentoptions",
65
65
  "Socket": "https://nodejs.org/api/net.html#class-netsocket",
66
- "SocketInfo": "/api/Errors.md#new-requestretryerrormessage-code-options",
67
- "StreamOptions": "/api/Dispatcher.md#class-dispatcher",
66
+ "SocketInfo": "/api/Errors.html#new-requestretryerrormessage-code-options",
67
+ "StreamOptions": "/api/Dispatcher.html#class-dispatcher",
68
68
  "TLSSocket": "https://nodejs.org/api/tls.html#class-tlstlssocket",
69
- "UndiciError": "/api/Errors.md#class-undicierror",
70
- "UndiciHeaders": "/api/Dispatcher.md#class-dispatcher",
71
- "UpgradeOptions": "/api/Dispatcher.md#class-dispatcher",
72
- "UrlObject": "/index.md#urlobject",
73
- "WebSocketInit": "/api/WebSocket.md#new-websocketurl-protocols",
74
- "WebSocketStreamOptions": "/api/WebSocket.md#new-websocketurl-protocols",
69
+ "UndiciError": "/api/Errors.html#class-undicierror",
70
+ "UndiciHeaders": "/api/Dispatcher.html#class-dispatcher",
71
+ "UpgradeOptions": "/api/Dispatcher.html#class-dispatcher",
72
+ "UrlObject": "/index.html#urlobject",
73
+ "WebSocketInit": "/api/WebSocket.html#new-websocketurl-protocols",
74
+ "WebSocketStreamOptions": "/api/WebSocket.html#new-websocketurl-protocols",
75
75
  "Writable": "https://nodejs.org/api/stream.html#class-streamwritable",
76
- "buildConnector.BuildOptions": "/api/Connector.md#buildconnectoroptions",
76
+ "buildConnector.BuildOptions": "/api/Connector.html#buildconnectoroptions",
77
77
  "net.Socket": "https://nodejs.org/api/net.html#class-netsocket",
78
78
  "stream.Readable": "https://nodejs.org/api/stream.html#class-streamreadable"
79
- }
79
+ }