Skip to content

Commit 2497216

Browse files
nodejs-github-botBethGriggs
authored andcommitted
deps: update undici to 5.20.0
PR-URL: #46711 Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
1 parent 85f88c6 commit 2497216

File tree

17 files changed

+94
-59
lines changed

17 files changed

+94
-59
lines changed

deps/undici/src/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,18 @@ implementations in Deno and Cloudflare Workers.
405405

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

408+
## Workarounds
409+
410+
### Network address family autoselection.
411+
412+
If you experience problem when connecting to a remote server that is resolved by your DNS servers to a IPv6 (AAAA record)
413+
first, there are chances that your local router or ISP might have problem connecting to IPv6 networks. In that case
414+
undici will throw an error with code `UND_ERR_CONNECT_TIMEOUT`.
415+
416+
If the target server resolves to both a IPv6 and IPv4 (A records) address and you are using a compatible Node version
417+
(18.3.0 and above), you can fix the problem by providing the `autoSelectFamily` option (support by both `undici.request`
418+
and `undici.Agent`) which will enable the family autoselection algorithm when establishing the connection.
419+
408420
## Collaborators
409421

410422
* [__Daniele Belardi__](https://github.com/dnlup), <https://www.npmjs.com/~dnlup>

deps/undici/src/docs/api/Client.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ Returns: `Client`
1717

1818
### Parameter: `ClientOptions`
1919

20-
* **bodyTimeout** `number | null` (optional) - Default: `30e3` - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 30 seconds.
21-
* **headersTimeout** `number | null` (optional) - Default: `30e3` - The amount of time the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 30 seconds.
20+
* **bodyTimeout** `number | null` (optional) - Default: `300e3` - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 300 seconds.
21+
* **headersTimeout** `number | null` (optional) - Default: `300e3` - The amount of time the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.
2222
* **keepAliveMaxTimeout** `number | null` (optional) - Default: `600e3` - The maximum allowed `keepAliveTimeout` when overridden by *keep-alive* hints from the server. Defaults to 10 minutes.
2323
* **keepAliveTimeout** `number | null` (optional) - Default: `4e3` - The timeout after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. See [MDN: HTTP - Headers - Keep-Alive directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details. Defaults to 4 seconds.
2424
* **keepAliveTimeoutThreshold** `number | null` (optional) - Default: `1e3` - A number subtracted from server *keep-alive* hints when overriding `keepAliveTimeout` to account for timing inaccuracies caused by e.g. transport latency. Defaults to 1 second.
@@ -28,6 +28,8 @@ Returns: `Client`
2828
* **connect** `ConnectOptions | Function | null` (optional) - Default: `null`.
2929
* **strictContentLength** `Boolean` (optional) - Default: `true` - Whether to treat request content length mismatches as errors. If true, an error is thrown when the request content-length header doesn't match the length of the request body.
3030
* **interceptors** `{ Client: DispatchInterceptor[] }` - Default: `[RedirectInterceptor]` - A list of interceptors that are applied to the dispatch method. Additional logic can be applied (such as, but not limited to: 302 status code handling, authentication, cookies, compression and caching). Note that the behavior of interceptors is Experimental and might change at any given time.
31+
* **autoSelectFamily**: `boolean` (optional) - Default: depends on local Node version, on Node 18.13.0 and above is `false`. Enables a family autodetection algorithm that loosely implements section 5 of [RFC 8305](https://tools.ietf.org/html/rfc8305#section-5). See [here](https://nodejs.org/api/net.html#socketconnectoptions-connectlistener) for more details. This option is ignored if not supported by the current Node version.
32+
* **autoSelectFamilyAttemptTimeout**: `number` - Default: depends on local Node version, on Node 18.13.0 and above is `250`. The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. See [here](https://nodejs.org/api/net.html#socketconnectoptions-connectlistener) for more details.
3133

3234
#### Parameter: `ConnectOptions`
3335

deps/undici/src/docs/api/Dispatcher.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Returns: `void | Promise<ConnectData>` - Only returns a `Promise` if no `callbac
7474
#### Parameter: `ConnectData`
7575

7676
* **statusCode** `number`
77-
* **headers** `Record<string, string | string[]>`
77+
* **headers** `Record<string, string | string[] | undefined>`
7878
* **socket** `stream.Duplex`
7979
* **opaque** `unknown`
8080

@@ -199,8 +199,8 @@ Returns: `Boolean` - `false` if dispatcher is busy and further dispatch calls wo
199199
* **idempotent** `boolean` (optional) - Default: `true` if `method` is `'HEAD'` or `'GET'` - Whether the requests can be safely retried or not. If `false` the request won't be sent until all preceding requests in the pipeline has completed.
200200
* **blocking** `boolean` (optional) - Default: `false` - Whether the response is expected to take a long time and would end up blocking the pipeline. When this is set to `true` further pipelining will be avoided on the same connection until headers have been received.
201201
* **upgrade** `string | null` (optional) - Default: `null` - Upgrade the request. Should be used to specify the kind of upgrade i.e. `'Websocket'`.
202-
* **bodyTimeout** `number | null` (optional) - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 30 seconds.
203-
* **headersTimeout** `number | null` (optional) - The amount of time the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 30 seconds.
202+
* **bodyTimeout** `number | null` (optional) - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 300 seconds.
203+
* **headersTimeout** `number | null` (optional) - The amount of time the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.
204204
* **throwOnError** `boolean` (optional) - Default: `false` - Whether Undici should throw an error upon receiving a 4xx or 5xx response from the server.
205205

206206
#### Parameter: `DispatchHandler`
@@ -383,7 +383,7 @@ Extends: [`RequestOptions`](#parameter-requestoptions)
383383
#### Parameter: PipelineHandlerData
384384

385385
* **statusCode** `number`
386-
* **headers** `Record<string, string | string[]>`
386+
* **headers** `Record<string, string | string[] | undefined>`
387387
* **opaque** `unknown`
388388
* **body** `stream.Readable`
389389
* **context** `object`
@@ -644,7 +644,7 @@ Returns: `void | Promise<StreamData>` - Only returns a `Promise` if no `callback
644644
#### Parameter: `StreamFactoryData`
645645

646646
* **statusCode** `number`
647-
* **headers** `Record<string, string | string[]>`
647+
* **headers** `Record<string, string | string[] | undefined>`
648648
* **opaque** `unknown`
649649
* **onInfo** `({statusCode: number, headers: Record<string, string | string[]>}) => void | null` (optional) - Default: `null` - Callback collecting all the info headers (HTTP 100-199) received.
650650

@@ -853,9 +853,9 @@ Emitted when dispatcher is no longer busy.
853853

854854
## Parameter: `UndiciHeaders`
855855

856-
* `Record<string, string | string[]> | string[] | null`
856+
* `Record<string, string | string[] | undefined> | string[] | null`
857857

858-
Header arguments such as `options.headers` in [`Client.dispatch`](Client.md#clientdispatchoptions-handlers) can be specified in two forms; either as an object specified by the `Record<string, string | string[]>` (`IncomingHttpHeaders`) type, or an array of strings. An array representation of a header list must have an even length or an `InvalidArgumentError` will be thrown.
858+
Header arguments such as `options.headers` in [`Client.dispatch`](Client.md#clientdispatchoptions-handlers) can be specified in two forms; either as an object specified by the `Record<string, string | string[] | undefined>` (`IncomingHttpHeaders`) type, or an array of strings. An array representation of a header list must have an even length or an `InvalidArgumentError` will be thrown.
859859

860860
Keys are lowercase and values are not modified.
861861

deps/undici/src/index.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ const DecoratorHandler = require('./lib/handler/DecoratorHandler')
2020
const RedirectHandler = require('./lib/handler/RedirectHandler')
2121
const createRedirectInterceptor = require('./lib/interceptor/redirectInterceptor')
2222

23-
const nodeVersion = process.versions.node.split('.')
24-
const nodeMajor = Number(nodeVersion[0])
25-
const nodeMinor = Number(nodeVersion[1])
26-
2723
let hasCrypto
2824
try {
2925
require('crypto')
@@ -100,7 +96,7 @@ function makeDispatcher (fn) {
10096
module.exports.setGlobalDispatcher = setGlobalDispatcher
10197
module.exports.getGlobalDispatcher = getGlobalDispatcher
10298

103-
if (nodeMajor > 16 || (nodeMajor === 16 && nodeMinor >= 8)) {
99+
if (util.nodeMajor > 16 || (util.nodeMajor === 16 && util.nodeMinor >= 8)) {
104100
let fetchImpl = null
105101
module.exports.fetch = async function fetch (resource) {
106102
if (!fetchImpl) {
@@ -127,7 +123,7 @@ if (nodeMajor > 16 || (nodeMajor === 16 && nodeMinor >= 8)) {
127123
module.exports.getGlobalOrigin = getGlobalOrigin
128124
}
129125

130-
if (nodeMajor >= 16) {
126+
if (util.nodeMajor >= 16) {
131127
const { deleteCookie, getCookies, getSetCookies, setCookie } = require('./lib/cookies')
132128

133129
module.exports.deleteCookie = deleteCookie
@@ -141,7 +137,7 @@ if (nodeMajor >= 16) {
141137
module.exports.serializeAMimeType = serializeAMimeType
142138
}
143139

144-
if (nodeMajor >= 18 && hasCrypto) {
140+
if (util.nodeMajor >= 18 && hasCrypto) {
145141
const { WebSocket } = require('./lib/websocket/websocket')
146142

147143
module.exports.WebSocket = WebSocket

deps/undici/src/lib/client.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ class Client extends DispatcherBase {
109109
connect,
110110
maxRequestsPerClient,
111111
localAddress,
112-
maxResponseSize
112+
maxResponseSize,
113+
autoSelectFamily,
114+
autoSelectFamilyAttemptTimeout
113115
} = {}) {
114116
super()
115117

@@ -185,12 +187,20 @@ class Client extends DispatcherBase {
185187
throw new InvalidArgumentError('maxResponseSize must be a positive number')
186188
}
187189

190+
if (
191+
autoSelectFamilyAttemptTimeout != null &&
192+
(!Number.isInteger(autoSelectFamilyAttemptTimeout) || autoSelectFamilyAttemptTimeout < -1)
193+
) {
194+
throw new InvalidArgumentError('autoSelectFamilyAttemptTimeout must be a positive number')
195+
}
196+
188197
if (typeof connect !== 'function') {
189198
connect = buildConnector({
190199
...tls,
191200
maxCachedSessions,
192201
socketPath,
193202
timeout: connectTimeout,
203+
...(util.nodeHasAutoSelectFamily && autoSelectFamily ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined),
194204
...connect
195205
})
196206
}
@@ -212,8 +222,8 @@ class Client extends DispatcherBase {
212222
this[kResuming] = 0 // 0, idle, 1, scheduled, 2 resuming
213223
this[kNeedDrain] = 0 // 0, idle, 1, scheduled, 2 resuming
214224
this[kHostHeader] = `host: ${this[kUrl].hostname}${this[kUrl].port ? `:${this[kUrl].port}` : ''}\r\n`
215-
this[kBodyTimeout] = bodyTimeout != null ? bodyTimeout : 30e3
216-
this[kHeadersTimeout] = headersTimeout != null ? headersTimeout : 30e3
225+
this[kBodyTimeout] = bodyTimeout != null ? bodyTimeout : 300e3
226+
this[kHeadersTimeout] = headersTimeout != null ? headersTimeout : 300e3
217227
this[kStrictContentLength] = strictContentLength == null ? true : strictContentLength
218228
this[kMaxRedirections] = maxRedirections
219229
this[kMaxRequests] = maxRequestsPerClient

deps/undici/src/lib/cookies/parse.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const { maxNameValuePairSize, maxAttributeValueSize } = require('./constants')
44
const { isCTLExcludingHtab } = require('./util')
5-
const { collectASequenceOfCodePoints } = require('../fetch/dataURL')
5+
const { collectASequenceOfCodePointsFast } = require('../fetch/dataURL')
66
const assert = require('assert')
77

88
/**
@@ -32,7 +32,7 @@ function parseSetCookie (header) {
3232
// (including the %x3B (";") in question).
3333
const position = { position: 0 }
3434

35-
nameValuePair = collectASequenceOfCodePoints((char) => char !== ';', header, position)
35+
nameValuePair = collectASequenceOfCodePointsFast(';', header, position)
3636
unparsedAttributes = header.slice(position.position)
3737
} else {
3838
// Otherwise:
@@ -54,8 +54,8 @@ function parseSetCookie (header) {
5454
// empty) value string consists of the characters after the first
5555
// %x3D ("=") character.
5656
const position = { position: 0 }
57-
name = collectASequenceOfCodePoints(
58-
(char) => char !== '=',
57+
name = collectASequenceOfCodePointsFast(
58+
'=',
5959
nameValuePair,
6060
position
6161
)
@@ -106,8 +106,8 @@ function parseUnparsedAttributes (unparsedAttributes, cookieAttributeList = {})
106106
if (unparsedAttributes.includes(';')) {
107107
// 1. Consume the characters of the unparsed-attributes up to, but
108108
// not including, the first %x3B (";") character.
109-
cookieAv = collectASequenceOfCodePoints(
110-
(char) => char !== ';',
109+
cookieAv = collectASequenceOfCodePointsFast(
110+
';',
111111
unparsedAttributes,
112112
{ position: 0 }
113113
)
@@ -134,8 +134,8 @@ function parseUnparsedAttributes (unparsedAttributes, cookieAttributeList = {})
134134
// character.
135135
const position = { position: 0 }
136136

137-
attributeName = collectASequenceOfCodePoints(
138-
(char) => char !== '=',
137+
attributeName = collectASequenceOfCodePointsFast(
138+
'=',
139139
cookieAv,
140140
position
141141
)

deps/undici/src/lib/core/request.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@ const channels = {}
3434

3535
let extractBody
3636

37-
const nodeVersion = process.versions.node.split('.')
38-
const nodeMajor = Number(nodeVersion[0])
39-
const nodeMinor = Number(nodeVersion[1])
40-
4137
try {
4238
const diagnosticsChannel = require('diagnostics_channel')
4339
channels.create = diagnosticsChannel.channel('undici:request:create')
@@ -172,7 +168,7 @@ class Request {
172168
}
173169

174170
if (util.isFormDataLike(this.body)) {
175-
if (nodeMajor < 16 || (nodeMajor === 16 && nodeMinor < 8)) {
171+
if (util.nodeMajor < 16 || (util.nodeMajor === 16 && util.nodeMinor < 8)) {
176172
throw new InvalidArgumentError('Form-Data bodies are only supported in node v16.8 and newer.')
177173
}
178174

deps/undici/src/lib/core/util.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const { Blob } = require('buffer')
1010
const nodeUtil = require('util')
1111
const { stringify } = require('querystring')
1212

13+
const [nodeMajor, nodeMinor] = process.versions.node.split('.').map(v => Number(v))
14+
1315
function nop () {}
1416

1517
function isStream (obj) {
@@ -420,5 +422,8 @@ module.exports = {
420422
validateHandler,
421423
getSocketInfo,
422424
isFormDataLike,
423-
buildURL
425+
buildURL,
426+
nodeMajor,
427+
nodeMinor,
428+
nodeHasAutoSelectFamily: nodeMajor > 18 || (nodeMajor === 18 && nodeMinor >= 13)
424429
}

deps/undici/src/lib/fetch/dataURL.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ module.exports = {
556556
dataURLProcessor,
557557
URLSerializer,
558558
collectASequenceOfCodePoints,
559+
collectASequenceOfCodePointsFast,
559560
stringPercentDecode,
560561
parseMIMEType,
561562
collectAnHTTPQuotedString,

deps/undici/src/lib/fetch/headers.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ class HeadersList {
7575
if (init instanceof HeadersList) {
7676
this[kHeadersMap] = new Map(init[kHeadersMap])
7777
this[kHeadersSortedMap] = init[kHeadersSortedMap]
78+
this.cookies = init.cookies
7879
} else {
7980
this[kHeadersMap] = new Map(init)
8081
this[kHeadersSortedMap] = null

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy