Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions deps/undici/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,6 @@ and `undici.Agent`) which will enable the family autoselection algorithm when es
* [__Carlos Fuentes__](https://github.com/metcoder95), <https://www.npmjs.com/~metcoder95>
* [__Ethan Arrowood__](https://github.com/Ethan-Arrowood), <https://www.npmjs.com/~ethan_arrowood>
* [__Matteo Collina__](https://github.com/mcollina), <https://www.npmjs.com/~matteo.collina>
* [__Matthew Aitken__](https://github.com/KhafraDev), <https://www.npmjs.com/~khaf>
* [__Mert Can Altin__](https://github.com/mertcanaltin), <https://www.npmjs.com/~mertcanaltin>
* [__Robert Nagy__](https://github.com/ronag), <https://www.npmjs.com/~ronag>
* [__Trivikram Kamat__](https://github.com/trivikr), <https://www.npmjs.com/~trivikr>
Expand All @@ -804,13 +803,13 @@ and `undici.Agent`) which will enable the family autoselection algorithm when es
## Past Collaborators
* [__Szymon Marczak__](https://github.com/szmarczak), <https://www.npmjs.com/~szmarczak>
* [__Tomas Della Vedova__](https://github.com/delvedor), <https://www.npmjs.com/~delvedor>
* [__Matthew Aitken__](https://github.com/KhafraDev), <https://www.npmjs.com/~khaf>

### Releasers

* [__Ethan Arrowood__](https://github.com/ethan-arrowood), <https://www.npmjs.com/~ethan_arrowood>
* [__Matteo Collina__](https://github.com/mcollina), <https://www.npmjs.com/~matteo.collina>
* [__Robert Nagy__](https://github.com/ronag), <https://www.npmjs.com/~ronag>
* [__Matthew Aitken__](https://github.com/KhafraDev), <https://www.npmjs.com/~khaf>

## Long Term Support

Expand Down
8 changes: 5 additions & 3 deletions deps/undici/src/docs/docs/api/Client.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ added: v1.0.0
* `maxResponseSize` {number|null} The maximum length of a response body, in
bytes. Set to `-1` to disable it. **Default:** `-1`.
* `maxRequestsPerClient` {number|null} The maximum number of requests to send
over a single connection before the socket is reset. Use `0` to disable this
limit. **Default:** `null`.
over a single connection. For HTTP/2, once this limit is reached, the client
lets existing streams finish and closes the session before sending queued
requests on a new connection. Use `0` to disable this limit. **Default:**
`null`.
* `localAddress` {string|null} The local IP address the socket should connect
from. **Default:** `null`.
* `pipelining` {number|null} The number of concurrent requests sent over the
Expand Down Expand Up @@ -113,7 +115,7 @@ added: v1.0.0
higher priority through ALPN negotiation. **Default:** `true`.
* `useH2c` {boolean} _Deprecated: use h2Options.useH2c instead_ Enforces h2c (HTTP/2 cleartext) for non-HTTPS
connections. **Default:** `false`.
* `maxConcurrentStreams` {number} _Deprecated: use h2Options.useH2c instead_ The maximum number of concurrent HTTP/2
* `maxConcurrentStreams` {number} _Deprecated: use h2Options.maxConcurrentStreams instead_ The maximum number of concurrent HTTP/2
streams for a single session. Once h2 is negotiated this — not `pipelining`,
which is HTTP/1.1 only — is the ceiling used to dispatch in-flight requests.
The server's `SETTINGS_MAX_CONCURRENT_STREAMS` can lower this limit, but
Expand Down
6 changes: 6 additions & 0 deletions deps/undici/src/docs/docs/api/Dispatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ added: v4.0.0
* `expectContinue` {boolean} For HTTP/2, appends the `expect: 100-continue`
header and halts the request body until a `100 Continue` is received from the
remote server. **Default:** `false`.
* `servername` {string} The TLS server name (SNI) to use for this request on
`https:` origins. **Default:** the hostname of the `host` header, if any
(IP addresses are not used). A client reconnects when the server name of the
next queued request differs from the one of its current connection, and
waits for any running requests to finish first. Set this to share one
connection across requests with different `host` headers.
* `handler` {Object} A set of callbacks invoked over the request lifecycle.
* `onRequestStart` {Function} Invoked before the request is dispatched on the
socket. May be invoked multiple times when the request is retried.
Expand Down
9 changes: 9 additions & 0 deletions deps/undici/src/docs/docs/api/EnvHttpProxyAgent.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ Creates a new `EnvHttpProxyAgent`. Any options other than `httpProxy`,
not affect any request until it is registered as a dispatcher, either globally
with `setGlobalDispatcher()` or per-request through the `dispatcher` option.

The TLS options for the connection to the target server, given as `requestTls`
or as a `connect` object, apply on every route: direct (no proxy configured),
hosts matching `noProxy`, and proxied through an HTTP, HTTPS, or SOCKS5 proxy.
When both are set they are merged key by key, and keys set in `connect` take
precedence over `requestTls` on every route. `proxyTls` applies only to the connection to the
proxy server, and the target TLS options are never applied to it. When `connect`
is a function it is used as-is on direct routes, where `requestTls` is then not
applied, and it is not used on proxied routes.

```mjs
import { EnvHttpProxyAgent } from 'undici'

Expand Down
117 changes: 117 additions & 0 deletions deps/undici/src/docs/docs/api/Fetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,119 @@ const response = await fetch('https://example.com', {
})
```

### Composition and interceptors

undici's [`Dispatcher.compose()`][] composes a chain of interceptors over the
dispatcher's `dispatch()` method, returning a new dispatcher. Passing that
composed dispatcher to `fetch()` via `init.dispatcher` is the supported way
to add retry, cache, custom redirect handling, header dumping, or any
user-defined behaviour around a `fetch()` call — without changing the
WHATWG `fetch()` surface itself.

The following recipes cover the most common questions about `fetch()`
behaviour. Each one builds a dispatcher once and reuses it for every call.

#### Automatic retry

Retry transient network errors and 5xx responses, without manual loops:

```mjs
import { fetch, Agent, interceptors } from 'undici'

const dispatcher = new Agent().compose(interceptors.retry({
maxRetries: 3,
minTimeout: 500,
maxTimeout: 5_000,
timeoutFactor: 2,
// Methods allowed to retry; the default list excludes POST and PATCH
// to avoid replaying non-idempotent side effects.
methods: ['GET', 'HEAD', 'OPTIONS', 'PUT', 'DELETE', 'TRACE', 'QUERY'],
statusCodes: [500, 502, 503, 504, 429],
errorCodes: ['ECONNRESET', 'ECONNREFUSED', 'ENOTFOUND', 'ENETDOWN',
'ENETUNREACH', 'EHOSTDOWN', 'EHOSTUNREACH', 'EPIPE', 'UND_ERR_SOCKET']
}))

const response = await fetch('https://example.com/api', { dispatcher })
```

See [`RetryHandler`][] for the full option reference.

#### HTTP caching

Serve responses from an in-memory or SQLite cache store, honouring
`Cache-Control` and `Vary`:

```mjs
import { fetch, Agent, interceptors, cacheStores } from 'undici'

const dispatcher = new Agent().compose(interceptors.cache({
store: new cacheStores.MemoryCacheStore(),
methods: ['GET', 'HEAD']
}))

const response = await fetch('https://example.com/api', { dispatcher })
```

See [CacheStore][] for store options.

#### Custom redirect handling

Follow redirects a limited number of times, with optional header-stripping on
cross-origin hops:

```mjs
import { fetch, Agent, interceptors } from 'undici'

const dispatcher = new Agent().compose(interceptors.redirect({
maxRedirections: 5,
stripHeadersOnCrossOriginRedirect: ['authorization', 'cookie']
}))

const response = await fetch('https://example.com/old-path', { dispatcher })
```

#### Response error enrichment

Surface a `ResponseError` (with status + headers + body preview) instead of a
raw `Response` when the server returns 4xx/5xx:

```mjs
import { fetch, Agent, interceptors } from 'undici'

const dispatcher = new Agent().compose(interceptors.responseError({
// Max response body bytes buffered into the thrown ResponseError.
maxSize: 128 * 1024
}))

try {
await fetch('https://example.com/missing', { dispatcher })
} catch (err) {
// err is a ResponseError with err.statusCode, err.headers, err.body
}
```

#### Chaining multiple interceptors

`compose()` accepts an array; the order matters — the LAST interceptor in the
array runs FIRST on the outbound request:

```mjs
import { fetch, Agent, interceptors } from 'undici'

const dispatcher = new Agent().compose([
interceptors.retry({ maxRetries: 2 }),
interceptors.redirect({ maxRedirections: 5 }),
interceptors.cache({ store: new cacheStores.MemoryCacheStore() })
])

// On the way out: cache → redirect → retry → network.
// On the way back: network → retry → redirect → cache.
const response = await fetch('https://example.com/api', { dispatcher })
```

See [`Dispatcher.compose()`][] for the full composition semantics, and
[Interceptors][] for the complete list of built-in interceptors.

## Class: `FormData`

<!-- YAML
Expand Down Expand Up @@ -713,9 +826,13 @@ added: v1.0.0
* Type: {boolean} `true` once the body has been read.

[@fastify/busboy]: https://www.npmjs.com/package/@fastify/busboy
[`Dispatcher.compose()`]: ./Dispatcher.md#dispatchercomposeinterceptors-interceptor
[CacheStore]: ./CacheStore.md
[Interceptors]: ./Interceptors.md
[MDN Fetch documentation]: https://developer.mozilla.org/en-US/docs/Web/API/fetch
[MDN `FormData` documentation]: https://developer.mozilla.org/en-US/docs/Web/API/FormData
[MDN `Headers` documentation]: https://developer.mozilla.org/en-US/docs/Web/API/Headers
[MDN `Request` documentation]: https://developer.mozilla.org/en-US/docs/Web/API/Request
[MDN `Response` documentation]: https://developer.mozilla.org/en-US/docs/Web/API/Response
[`RetryHandler`]: ./RetryHandler.md
[WHATWG Fetch Standard]: https://fetch.spec.whatwg.org/
7 changes: 4 additions & 3 deletions deps/undici/src/docs/docs/api/H2CClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ added: v7.7.0
**Default:** `600e3`.
* `keepAliveTimeoutThreshold` {number} A number of milliseconds subtracted from
server _keep-alive_ hints when overriding `keepAliveTimeout`, to account for
timing inaccuracies such as transport latency. **Default:** `1e3`.
timing inaccuracies such as transport latency. **Default:** `2e3`.
* `socketPath` {string} An IPC endpoint, either a Unix domain socket or a
Windows named pipe. **Default:** `null`.
* `strictContentLength` {boolean} If `true`, an error is thrown when the
Expand All @@ -95,8 +95,9 @@ added: v7.7.0
a custom connector function. The `allowH2` option may not be set here.
**Default:** `null`.
* `maxRequestsPerClient` {number} The maximum number of requests to send over
a single connection before it is reset. Use `0` to disable this limit.
**Default:** `null`.
a single connection. Once this limit is reached, the client lets existing
streams finish and closes the session before sending queued requests on a
new connection. Use `0` to disable this limit. **Default:** `null`.
* `localAddress` {string} The local IP address the socket should connect from.
* `maxResponseSize` {number} The maximum allowed response body size in bytes.
Use `-1` to disable. **Default:** `-1`.
Expand Down
36 changes: 22 additions & 14 deletions deps/undici/src/docs/docs/api/Interceptors.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,14 @@ dual-stack (IPv4 + IPv6) and custom lookup/storage implementations.
**Parameters**

* `opts` {Object} (optional)
* `maxTTL` {number} Maximum number of milliseconds a DNS record is cached,
regardless of the TTL returned by the resolver. **Default:** `0`
(use the TTL from the DNS record).
* `maxItems` {number} Maximum number of origins to cache simultaneously.
Oldest entries are evicted when the limit is reached. **Default:**
`Infinity`.
* `maxTTL` {number} Maximum number of milliseconds a DNS record is cached.
A record that `lookup` returns with a shorter TTL keeps its own TTL. A
record without a TTL, which includes every record from the default
lookup, is cached for `maxTTL`. **Default:** `10000` (10 seconds).
* `maxItems` {number} Maximum number of hostnames to cache at the same
time. When the cache is full, cached hostnames stay until their records
expire, and other hostnames are not looked up or cached: their requests
are resolved as if the interceptor were not used. **Default:** `Infinity`.
* `dualStack` {boolean} When `true`, both IPv4 (`A`) and IPv6 (`AAAA`)
records are looked up and the interceptor picks between them based on
`affinity`. **Default:** `true`.
Expand Down Expand Up @@ -435,8 +437,12 @@ const agent = new Agent().compose(

## Composing multiple interceptors

Interceptors are applied in the order they appear in the `compose()` call.
The first interceptor in the array wraps the outermost layer.
Each interceptor passed to `compose()` wraps the dispatcher built from the
interceptors before it. The last interceptor in the array is therefore the
outermost layer: it is the first to see a request and the last to see its
response. The first interceptor is the innermost one, closest to the
underlying dispatcher. See [`Dispatcher.compose()`](./Dispatcher.md) for the
order-sensitive built-in interceptors.

```js
import { Agent, interceptors } from 'undici'
Expand All @@ -450,10 +456,12 @@ const agent = new Agent().compose([
])
```

In the example above the request flow is:
In the example above a request passes through the interceptors from last to
first:

1. **dns** — resolves and caches the target IP
2. **retry** — retries the dispatch on transient failures
3. **redirect** — follows any 3xx redirects
4. **decompress** — decompresses the response body
5. **responseError** — converts 4xx/5xx into thrown errors
1. **responseError** — converts 4xx/5xx into thrown errors
2. **decompress** — decompresses the response body
3. **redirect** — follows any 3xx redirects, sending each hop through the
interceptors below it
4. **retry** — retries the dispatch of each hop on transient failures
5. **dns** — resolves and caches the IP of each hop's origin
4 changes: 3 additions & 1 deletion deps/undici/src/lib/api/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ class RequestHandler extends AsyncResource {
this.res = null
// Ensure all queued handlers are invoked before destroying res.
queueMicrotask(() => {
util.destroy(res.on('error', noop), err)
if (!util.isDestroyed(res)) {
util.destroy(res.on('error', noop), err)
}
})
}

Expand Down
11 changes: 9 additions & 2 deletions deps/undici/src/lib/api/api-stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class StreamHandler extends AsyncResource {
this.trailers = null
this.body = body
this.onInfo = onInfo || null
// Set once the factory's writable is tracked: from then on its lifecycle
// owns the callback, which must not be invoked from onResponseError.
this.responseStarted = false

if (util.isStream(body)) {
body.on('error', (err) => {
Expand Down Expand Up @@ -173,13 +176,17 @@ class StreamHandler extends AsyncResource {
}

this.callback = null
this.runInAsyncScope(callback, null, err || null, { opaque, trailers })
if (callback) {
this.runInAsyncScope(callback, null, err || null, { opaque, trailers })
}

if (err) {
abort(err)
}
})

this.responseStarted = true

res.on('drain', () => controller.resume())

this.res = res
Expand Down Expand Up @@ -231,7 +238,7 @@ class StreamHandler extends AsyncResource {
if (res) {
this.res = null
util.destroy(res, err)
} else if (callback) {
} else if (callback && !this.responseStarted) {
this.callback = null
queueMicrotask(() => {
this.runInAsyncScope(callback, null, err, { opaque })
Expand Down
Loading
Loading