Skip to content

deps: update undici to 7.9.0 #58268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2025
Merged
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
35 changes: 20 additions & 15 deletions deps/undici/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,22 @@ const readableWebStream = response.body
const readableNodeStream = Readable.fromWeb(readableWebStream)
```

#### Specification Compliance
## Specification Compliance

This section documents parts of the [Fetch Standard](https://fetch.spec.whatwg.org) that Undici does
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
not support or does not fully implement.

##### Garbage Collection
#### CORS

Unlike browsers, Undici does not implement CORS (Cross-Origin Resource Sharing) checks by default. This means:

- No preflight requests are automatically sent for cross-origin requests
- No validation of `Access-Control-Allow-Origin` headers is performed
- Requests to any origin are allowed regardless of the source

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.

#### Garbage Collection

* https://fetch.spec.whatwg.org/#garbage-collection

Expand Down Expand Up @@ -307,7 +317,7 @@ const headers = await fetch(url, { method: 'HEAD' })
.then(res => res.headers)
```

##### Forbidden and Safelisted Header Names
#### Forbidden and Safelisted Header Names

* https://fetch.spec.whatwg.org/#cors-safelisted-response-header-name
* https://fetch.spec.whatwg.org/#forbidden-header-name
Expand All @@ -316,7 +326,7 @@ const headers = await fetch(url, { method: 'HEAD' })

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.

### `undici.upgrade([url, options]): Promise`
#### `undici.upgrade([url, options]): Promise`

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.

Expand Down Expand Up @@ -378,20 +388,15 @@ Returns: `URL`
* **protocol** `string` (optional)
* **search** `string` (optional)

## Specification Compliance

This section documents parts of the HTTP/1.1 specification that Undici does
not support or does not fully implement.

### Expect
#### Expect

Undici does not support the `Expect` request header field. The request
body is always immediately sent and the `100 Continue` response will be
ignored.

Refs: https://tools.ietf.org/html/rfc7231#section-5.1.1

### Pipelining
#### Pipelining

Undici will only use pipelining if configured with a `pipelining` factor
greater than `1`. Also it is important to pass `blocking: false` to the
Expand All @@ -412,7 +417,7 @@ aborted.
* Refs: https://tools.ietf.org/html/rfc2616#section-8.1.2.2
* Refs: https://tools.ietf.org/html/rfc7230#section-6.3.2

### Manual Redirect
#### Manual Redirect

Since it is not possible to manually follow an HTTP redirect on the server-side,
Undici returns the actual response instead of an `opaqueredirect` filtered one
Expand All @@ -421,9 +426,9 @@ implementations in Deno and Cloudflare Workers.

Refs: https://fetch.spec.whatwg.org/#atomic-http-redirect-handling

## Workarounds
### Workarounds

### Network address family autoselection.
#### Network address family autoselection.

If you experience problem when connecting to a remote server that is resolved by your DNS servers to a IPv6 (AAAA record)
first, there are chances that your local router or ISP might have problem connecting to IPv6 networks. In that case
Expand Down
6 changes: 6 additions & 0 deletions deps/undici/src/docs/docs/api/Agent.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,9 @@ See [`Dispatcher.stream(options, factory[, callback])`](/docs/docs/api/Dispatche
### `Agent.upgrade(options[, callback])`

See [`Dispatcher.upgrade(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherupgradeoptions-callback).

### `Agent.stats()`

Returns an object of stats by origin in the format of `Record<string, TClientStats | TPoolStats>`

See [`PoolStats`](/docs/docs/api/PoolStats.md) and [`ClientStats`](/docs/docs/api/ClientStats.md).
27 changes: 27 additions & 0 deletions deps/undici/src/docs/docs/api/ClientStats.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Class: ClientStats

Stats for a [Client](/docs/docs/api/Client.md).

## `new ClientStats(client)`

Arguments:

* **client** `Client` - Client from which to return stats.

## Instance Properties

### `ClientStats.connected`

Boolean if socket as open connection by this client.

### `ClientStats.pending`

Number of pending requests of this client.

### `ClientStats.running`

Number of currently active requests across this client.

### `ClientStats.size`

Number of active, pending, or queued requests of this clients.
2 changes: 1 addition & 1 deletion deps/undici/src/docs/docs/api/DiagnosticsChannel.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ diagnosticsChannel.channel('undici:request:create').subscribe(({ request }) => {
console.log('completed', request.completed)
console.log('method', request.method)
console.log('path', request.path)
console.log('headers') // array of strings, e.g: ['foo', 'bar']
console.log('headers', request.headers) // array of strings, e.g: ['foo', 'bar']
request.addHeader('hello', 'world')
console.log('headers', request.headers) // e.g. ['foo', 'bar', 'hello', 'world']
})
Expand Down
2 changes: 2 additions & 0 deletions deps/undici/src/docs/docs/api/MockAgent.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Extends: [`AgentOptions`](/docs/docs/api/Agent.md#parameter-agentoptions)

* **ignoreTrailingSlash** `boolean` (optional) - Default: `false` - set the default value for `ignoreTrailingSlash` for interceptors.

* **acceptNonStandardSearchParameters** `boolean` (optional) - Default: `false` - set to `true` if the matcher should also accept non standard search parameters such as multi-value items specified with `[]` (e.g. `param[]=1&param[]=2&param[]=3`) and multi-value items which values are comma separated (e.g. `param=1,2,3`).

### Example - Basic MockAgent instantiation

This will instantiate the MockAgent. It will not do anything until registered as the agent to use with requests and mock interceptions are added.
Expand Down
37 changes: 25 additions & 12 deletions deps/undici/src/lib/cache/memory-cache-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,9 @@ class MemoryCacheStore {
const topLevelKey = `${key.origin}:${key.path}`

const now = Date.now()
const entry = this.#entries.get(topLevelKey)?.find((entry) => (
entry.deleteAt > now &&
entry.method === key.method &&
(entry.vary == null || Object.keys(entry.vary).every(headerName => {
if (entry.vary[headerName] === null) {
return key.headers[headerName] === undefined
}
const entries = this.#entries.get(topLevelKey)

return entry.vary[headerName] === key.headers[headerName]
}))
))
const entry = entries ? findEntry(key, entries, now) : null

return entry == null
? undefined
Expand Down Expand Up @@ -140,10 +132,17 @@ class MemoryCacheStore {
entries = []
store.#entries.set(topLevelKey, entries)
}
entries.push(entry)
const previousEntry = findEntry(key, entries, Date.now())
if (previousEntry) {
const index = entries.indexOf(previousEntry)
entries.splice(index, 1, entry)
store.#size -= previousEntry.size
} else {
entries.push(entry)
store.#count += 1
}

store.#size += entry.size
store.#count += 1

if (store.#size > store.#maxSize || store.#count > store.#maxCount) {
for (const [key, entries] of store.#entries) {
Expand Down Expand Up @@ -180,4 +179,18 @@ class MemoryCacheStore {
}
}

function findEntry (key, entries, now) {
return entries.find((entry) => (
entry.deleteAt > now &&
entry.method === key.method &&
(entry.vary == null || Object.keys(entry.vary).every(headerName => {
if (entry.vary[headerName] === null) {
return key.headers[headerName] === undefined
}

return entry.vary[headerName] === key.headers[headerName]
}))
))
}

module.exports = MemoryCacheStore
12 changes: 11 additions & 1 deletion deps/undici/src/lib/dispatcher/agent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { InvalidArgumentError } = require('../core/errors')
const { kClients, kRunning, kClose, kDestroy, kDispatch } = require('../core/symbols')
const { kClients, kRunning, kClose, kDestroy, kDispatch, kUrl } = require('../core/symbols')
const DispatcherBase = require('./dispatcher-base')
const Pool = require('./pool')
const Client = require('./client')
Expand Down Expand Up @@ -110,6 +110,16 @@ class Agent extends DispatcherBase {

await Promise.all(destroyPromises)
}

get stats () {
const allClientStats = {}
for (const client of this[kClients].values()) {
if (client.stats) {
allClientStats[client[kUrl].origin] = client.stats
}
}
return allClientStats
}
}

module.exports = Agent
4 changes: 3 additions & 1 deletion deps/undici/src/lib/dispatcher/client-h2.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,13 @@ function writeH2 (client, request) {
if (Array.isArray(val)) {
for (let i = 0; i < val.length; i++) {
if (headers[key]) {
headers[key] += `,${val[i]}`
headers[key] += `, ${val[i]}`
} else {
headers[key] = val[i]
}
}
} else if (headers[key]) {
headers[key] += `, ${val}`
} else {
headers[key] = val
}
Expand Down
5 changes: 5 additions & 0 deletions deps/undici/src/lib/dispatcher/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const assert = require('node:assert')
const net = require('node:net')
const http = require('node:http')
const util = require('../core/util.js')
const { ClientStats } = require('../util/stats.js')
const { channels } = require('../core/diagnostics.js')
const Request = require('../core/request.js')
const DispatcherBase = require('./dispatcher-base')
Expand Down Expand Up @@ -260,6 +261,10 @@ class Client extends DispatcherBase {
this[kResume](true)
}

get stats () {
return new ClientStats(this)
}

get [kPending] () {
return this[kQueue].length - this[kPendingIdx]
}
Expand Down
7 changes: 2 additions & 5 deletions deps/undici/src/lib/dispatcher/pool-base.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

const { PoolStats } = require('../util/stats.js')
const DispatcherBase = require('./dispatcher-base')
const FixedQueue = require('./fixed-queue')
const { kConnected, kSize, kRunning, kPending, kQueued, kBusy, kFree, kUrl, kClose, kDestroy, kDispatch } = require('../core/symbols')
const PoolStats = require('./pool-stats')

const kClients = Symbol('clients')
const kNeedDrain = Symbol('needDrain')
Expand All @@ -16,7 +16,6 @@ const kOnConnectionError = Symbol('onConnectionError')
const kGetDispatcher = Symbol('get dispatcher')
const kAddClient = Symbol('add client')
const kRemoveClient = Symbol('remove client')
const kStats = Symbol('stats')

class PoolBase extends DispatcherBase {
constructor () {
Expand Down Expand Up @@ -67,8 +66,6 @@ class PoolBase extends DispatcherBase {
this[kOnConnectionError] = (origin, targets, err) => {
pool.emit('connectionError', origin, [pool, ...targets], err)
}

this[kStats] = new PoolStats(this)
}

get [kBusy] () {
Expand Down Expand Up @@ -108,7 +105,7 @@ class PoolBase extends DispatcherBase {
}

get stats () {
return this[kStats]
return new PoolStats(this)
}

async [kClose] () {
Expand Down
36 changes: 0 additions & 36 deletions deps/undici/src/lib/dispatcher/pool-stats.js

This file was deleted.

14 changes: 12 additions & 2 deletions deps/undici/src/lib/interceptor/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ const { AbortError } = require('../core/errors.js')
*/
function needsRevalidation (result, cacheControlDirectives) {
if (cacheControlDirectives?.['no-cache']) {
// Always revalidate requests with the no-cache directive
// Always revalidate requests with the no-cache request directive
return true
}

if (result.cacheControlDirectives?.['no-cache'] && !Array.isArray(result.cacheControlDirectives['no-cache'])) {
// Always revalidate requests with unqualified no-cache response directive
return true
}

Expand Down Expand Up @@ -233,7 +238,7 @@ function handleResult (
}

let headers = {
...normaliseHeaders(opts),
...opts.headers,
'if-modified-since': new Date(result.cachedAt).toUTCString()
}

Expand Down Expand Up @@ -319,6 +324,11 @@ module.exports = (opts = {}) => {
return dispatch(opts, handler)
}

opts = {
...opts,
headers: normaliseHeaders(opts)
}

const reqCacheControl = opts.headers?.['cache-control']
? parseCacheControlHeader(opts.headers['cache-control'])
: undefined
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/llhttp/wasm_build_env.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

> undici@7.8.0 build:wasm
> undici@7.9.0 build:wasm
> node build/wasm.js --docker

> docker run --rm --platform=linux/x86_64 --user 1001:118 --mount type=bind,source=/home/runner/work/node/node/deps/undici/src/lib/llhttp,target=/home/node/build/lib/llhttp --mount type=bind,source=/home/runner/work/node/node/deps/undici/src/build,target=/home/node/build/build --mount type=bind,source=/home/runner/work/node/node/deps/undici/src/deps,target=/home/node/build/deps -t ghcr.io/nodejs/wasm-builder@sha256:975f391d907e42a75b8c72eb77c782181e941608687d4d8694c3e9df415a0970 node build/wasm.js
Expand Down
Loading
Loading