Skip to content

Commit

Permalink
deps: update undici to v6.21.1
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Collina <[email protected]>
PR-URL: nodejs-private/node-private#654
Reviewed-By: Rafael Gonzaga <[email protected]>
CVE-ID: CVE-2025-22150
  • Loading branch information
mcollina authored and RafaelGSS committed Jan 20, 2025
1 parent 51938f0 commit f2ad4d3
Show file tree
Hide file tree
Showing 13 changed files with 503 additions and 10,146 deletions.
51 changes: 51 additions & 0 deletions deps/undici/src/docs/docs/api/Dispatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -986,6 +986,57 @@ client.dispatch(
);
```

##### `dns`

The `dns` interceptor enables you to cache DNS lookups for a given duration, per origin.

>It is well suited for scenarios where you want to cache DNS lookups to avoid the overhead of resolving the same domain multiple times
**Options**
- `maxTTL` - The maximum time-to-live (in milliseconds) of the DNS cache. It should be a positive integer. Default: `10000`.
- Set `0` to disable TTL.
- `maxItems` - The maximum number of items to cache. It should be a positive integer. Default: `Infinity`.
- `dualStack` - Whether to resolve both IPv4 and IPv6 addresses. Default: `true`.
- It will also attempt a happy-eyeballs-like approach to connect to the available addresses in case of a connection failure.
- `affinity` - Whether to use IPv4 or IPv6 addresses. Default: `4`.
- It can be either `'4` or `6`.
- It will only take effect if `dualStack` is `false`.
- `lookup: (hostname: string, options: LookupOptions, callback: (err: NodeJS.ErrnoException | null, addresses: DNSInterceptorRecord[]) => void) => void` - Custom lookup function. Default: `dns.lookup`.
- For more info see [dns.lookup](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback).
- `pick: (origin: URL, records: DNSInterceptorRecords, affinity: 4 | 6) => DNSInterceptorRecord` - Custom pick function. Default: `RoundRobin`.
- The function should return a single record from the records array.
- By default a simplified version of Round Robin is used.
- The `records` property can be mutated to store the state of the balancing algorithm.

> The `Dispatcher#options` also gets extended with the options `dns.affinity`, `dns.dualStack`, `dns.lookup` and `dns.pick` which can be used to configure the interceptor at a request-per-request basis.

**DNSInterceptorRecord**
It represents a DNS record.
- `family` - (`number`) The IP family of the address. It can be either `4` or `6`.
- `address` - (`string`) The IP address.

**DNSInterceptorOriginRecords**
It represents a map of DNS IP addresses records for a single origin.
- `4.ips` - (`DNSInterceptorRecord[] | null`) The IPv4 addresses.
- `6.ips` - (`DNSInterceptorRecord[] | null`) The IPv6 addresses.

**Example - Basic DNS Interceptor**

```js
const { Client, interceptors } = require("undici");
const { dns } = interceptors;

const client = new Agent().compose([
dns({ ...opts })
])

const response = await client.request({
origin: `http://localhost:3030`,
...requestOpts
})
```

##### `Response Error Interceptor`

**Introduction**
Expand Down
3 changes: 2 additions & 1 deletion deps/undici/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ module.exports.createRedirectInterceptor = createRedirectInterceptor
module.exports.interceptors = {
redirect: require('./lib/interceptor/redirect'),
retry: require('./lib/interceptor/retry'),
dump: require('./lib/interceptor/dump')
dump: require('./lib/interceptor/dump'),
dns: require('./lib/interceptor/dns')
}

module.exports.buildConnector = buildConnector
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/api/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class RequestHandler extends AsyncResource {
this.removeAbortListener = util.addAbortListener(this.signal, () => {
this.reason = this.signal.reason ?? new RequestAbortedError()
if (this.res) {
util.destroy(this.res, this.reason)
util.destroy(this.res.on('error', util.nop), this.reason)
} else if (this.abort) {
this.abort(this.reason)
}
Expand Down
26 changes: 20 additions & 6 deletions deps/undici/src/lib/dispatcher/client-h2.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const {

const kOpenStreams = Symbol('open streams')

let extractBody

// Experimental
let h2ExperimentalWarned = false

Expand Down Expand Up @@ -240,11 +242,12 @@ function onHTTP2GoAway (code) {
util.destroy(this[kSocket], err)

// Fail head of pipeline.
const request = client[kQueue][client[kRunningIdx]]
client[kQueue][client[kRunningIdx]++] = null
util.errorRequest(client, request, err)

client[kPendingIdx] = client[kRunningIdx]
if (client[kRunningIdx] < client[kQueue].length) {
const request = client[kQueue][client[kRunningIdx]]
client[kQueue][client[kRunningIdx]++] = null
util.errorRequest(client, request, err)
client[kPendingIdx] = client[kRunningIdx]
}

assert(client[kRunning] === 0)

Expand All @@ -260,7 +263,8 @@ function shouldSendContentLength (method) {

function writeH2 (client, request) {
const session = client[kHTTP2Session]
const { body, method, path, host, upgrade, expectContinue, signal, headers: reqHeaders } = request
const { method, path, host, upgrade, expectContinue, signal, headers: reqHeaders } = request
let { body } = request

if (upgrade) {
util.errorRequest(client, request, new Error('Upgrade not supported for H2'))
Expand Down Expand Up @@ -381,6 +385,16 @@ function writeH2 (client, request) {

let contentLength = util.bodyLength(body)

if (util.isFormDataLike(body)) {
extractBody ??= require('../web/fetch/body.js').extractBody

const [bodyStream, contentType] = extractBody(body)
headers['content-type'] = contentType

body = bodyStream.stream
contentLength = bodyStream.length
}

if (contentLength == null) {
contentLength = request.contentLength
}
Expand Down
Loading

0 comments on commit f2ad4d3

Please sign in to comment.