Skip to content

Commit 6bb6a91

Browse files
nodejs-github-botmarco-ippolito
authored andcommitted
deps: update undici to 6.19.0
PR-URL: #53468 Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Chemi Atlow <[email protected]> Reviewed-By: Matthew Aitken <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 1aaaad8 commit 6bb6a91

File tree

16 files changed

+455
-415
lines changed

16 files changed

+455
-415
lines changed

Diff for: deps/undici/src/docs/docs/api/Client.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Returns: `Client`
1919

2020
> ⚠️ Warning: The `H2` support is experimental.
2121
22-
* **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.
22+
* **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. Please note the `timeout` will be reset if you keep writing data to the scoket everytime.
2323
* **headersTimeout** `number | null` (optional) - Default: `300e3` - The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.
2424
* **keepAliveMaxTimeout** `number | null` (optional) - Default: `600e3` - The maximum allowed `keepAliveTimeout`, in milliseconds, when overridden by *keep-alive* hints from the server. Defaults to 10 minutes.
2525
* **keepAliveTimeout** `number | null` (optional) - Default: `4e3` - The timeout, in milliseconds, 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.

Diff for: deps/undici/src/lib/core/connect.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ if (global.FinalizationRegistry && !(process.env.NODE_V8_COVERAGE || process.env
7373
}
7474
}
7575

76-
function buildConnector ({ allowH2, maxCachedSessions, socketPath, timeout, ...opts }) {
76+
function buildConnector ({ allowH2, maxCachedSessions, socketPath, timeout, session: customSession, ...opts }) {
7777
if (maxCachedSessions != null && (!Number.isInteger(maxCachedSessions) || maxCachedSessions < 0)) {
7878
throw new InvalidArgumentError('maxCachedSessions must be a positive integer or zero')
7979
}
@@ -91,7 +91,7 @@ function buildConnector ({ allowH2, maxCachedSessions, socketPath, timeout, ...o
9191
servername = servername || options.servername || util.getServerName(host) || null
9292

9393
const sessionKey = servername || hostname
94-
const session = sessionCache.get(sessionKey) || null
94+
const session = customSession || sessionCache.get(sessionKey) || null
9595

9696
assert(sessionKey)
9797

Diff for: deps/undici/src/lib/core/request.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ const {
1616
isBlobLike,
1717
buildURL,
1818
validateHandler,
19-
getServerName
19+
getServerName,
20+
normalizedMethodRecords
2021
} = require('./util')
2122
const { channels } = require('./diagnostics.js')
2223
const { headerNameLowerCasedRecord } = require('./constants')
@@ -51,13 +52,13 @@ class Request {
5152
method !== 'CONNECT'
5253
) {
5354
throw new InvalidArgumentError('path must be an absolute URL or start with a slash')
54-
} else if (invalidPathRegex.exec(path) !== null) {
55+
} else if (invalidPathRegex.test(path)) {
5556
throw new InvalidArgumentError('invalid request path')
5657
}
5758

5859
if (typeof method !== 'string') {
5960
throw new InvalidArgumentError('method must be a string')
60-
} else if (!isValidHTTPToken(method)) {
61+
} else if (normalizedMethodRecords[method] === undefined && !isValidHTTPToken(method)) {
6162
throw new InvalidArgumentError('invalid request method')
6263
}
6364

Diff for: deps/undici/src/lib/core/util.js

+27
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,31 @@ function errorRequest (client, request, err) {
645645
const kEnumerableProperty = Object.create(null)
646646
kEnumerableProperty.enumerable = true
647647

648+
const normalizedMethodRecordsBase = {
649+
delete: 'DELETE',
650+
DELETE: 'DELETE',
651+
get: 'GET',
652+
GET: 'GET',
653+
head: 'HEAD',
654+
HEAD: 'HEAD',
655+
options: 'OPTIONS',
656+
OPTIONS: 'OPTIONS',
657+
post: 'POST',
658+
POST: 'POST',
659+
put: 'PUT',
660+
PUT: 'PUT'
661+
}
662+
663+
const normalizedMethodRecords = {
664+
...normalizedMethodRecordsBase,
665+
patch: 'patch',
666+
PATCH: 'PATCH'
667+
}
668+
669+
// Note: object prototypes should not be able to be referenced. e.g. `Object#hasOwnProperty`.
670+
Object.setPrototypeOf(normalizedMethodRecordsBase, null)
671+
Object.setPrototypeOf(normalizedMethodRecords, null)
672+
648673
module.exports = {
649674
kEnumerableProperty,
650675
nop,
@@ -683,6 +708,8 @@ module.exports = {
683708
isValidHeaderValue,
684709
isTokenCharCode,
685710
parseRangeHeader,
711+
normalizedMethodRecordsBase,
712+
normalizedMethodRecords,
686713
isValidPort,
687714
isHttpOrHttpsPrefixed,
688715
nodeMajor,

Diff for: deps/undici/src/lib/dispatcher/client-h1.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -978,27 +978,27 @@ function writeH1 (client, request) {
978978

979979
/* istanbul ignore else: assertion */
980980
if (!body || bodyLength === 0) {
981-
writeBuffer({ abort, body: null, client, request, socket, contentLength, header, expectsPayload })
981+
writeBuffer(abort, null, client, request, socket, contentLength, header, expectsPayload)
982982
} else if (util.isBuffer(body)) {
983-
writeBuffer({ abort, body, client, request, socket, contentLength, header, expectsPayload })
983+
writeBuffer(abort, body, client, request, socket, contentLength, header, expectsPayload)
984984
} else if (util.isBlobLike(body)) {
985985
if (typeof body.stream === 'function') {
986-
writeIterable({ abort, body: body.stream(), client, request, socket, contentLength, header, expectsPayload })
986+
writeIterable(abort, body.stream(), client, request, socket, contentLength, header, expectsPayload)
987987
} else {
988-
writeBlob({ abort, body, client, request, socket, contentLength, header, expectsPayload })
988+
writeBlob(abort, body, client, request, socket, contentLength, header, expectsPayload)
989989
}
990990
} else if (util.isStream(body)) {
991-
writeStream({ abort, body, client, request, socket, contentLength, header, expectsPayload })
991+
writeStream(abort, body, client, request, socket, contentLength, header, expectsPayload)
992992
} else if (util.isIterable(body)) {
993-
writeIterable({ abort, body, client, request, socket, contentLength, header, expectsPayload })
993+
writeIterable(abort, body, client, request, socket, contentLength, header, expectsPayload)
994994
} else {
995995
assert(false)
996996
}
997997

998998
return true
999999
}
10001000

1001-
function writeStream ({ abort, body, client, request, socket, contentLength, header, expectsPayload }) {
1001+
function writeStream (abort, body, client, request, socket, contentLength, header, expectsPayload) {
10021002
assert(contentLength !== 0 || client[kRunning] === 0, 'stream body cannot be pipelined')
10031003

10041004
let finished = false
@@ -1101,7 +1101,7 @@ function writeStream ({ abort, body, client, request, socket, contentLength, hea
11011101
}
11021102
}
11031103

1104-
function writeBuffer ({ abort, body, client, request, socket, contentLength, header, expectsPayload }) {
1104+
function writeBuffer (abort, body, client, request, socket, contentLength, header, expectsPayload) {
11051105
try {
11061106
if (!body) {
11071107
if (contentLength === 0) {
@@ -1131,7 +1131,7 @@ function writeBuffer ({ abort, body, client, request, socket, contentLength, hea
11311131
}
11321132
}
11331133

1134-
async function writeBlob ({ abort, body, client, request, socket, contentLength, header, expectsPayload }) {
1134+
async function writeBlob (abort, body, client, request, socket, contentLength, header, expectsPayload) {
11351135
assert(contentLength === body.size, 'blob body must have content length')
11361136

11371137
try {
@@ -1159,7 +1159,7 @@ async function writeBlob ({ abort, body, client, request, socket, contentLength,
11591159
}
11601160
}
11611161

1162-
async function writeIterable ({ abort, body, client, request, socket, contentLength, header, expectsPayload }) {
1162+
async function writeIterable (abort, body, client, request, socket, contentLength, header, expectsPayload) {
11631163
assert(contentLength !== 0 || client[kRunning] === 0, 'iterator body cannot be pipelined')
11641164

11651165
let callback = null

Diff for: deps/undici/src/lib/dispatcher/client-h2.js

+38-40
Original file line numberDiff line numberDiff line change
@@ -477,82 +477,80 @@ function writeH2 (client, request) {
477477
function writeBodyH2 () {
478478
/* istanbul ignore else: assertion */
479479
if (!body || contentLength === 0) {
480-
writeBuffer({
480+
writeBuffer(
481481
abort,
482+
stream,
483+
null,
482484
client,
483485
request,
486+
client[kSocket],
484487
contentLength,
485-
expectsPayload,
486-
h2stream: stream,
487-
body: null,
488-
socket: client[kSocket]
489-
})
488+
expectsPayload
489+
)
490490
} else if (util.isBuffer(body)) {
491-
writeBuffer({
491+
writeBuffer(
492492
abort,
493+
stream,
494+
body,
493495
client,
494496
request,
497+
client[kSocket],
495498
contentLength,
496-
body,
497-
expectsPayload,
498-
h2stream: stream,
499-
socket: client[kSocket]
500-
})
499+
expectsPayload
500+
)
501501
} else if (util.isBlobLike(body)) {
502502
if (typeof body.stream === 'function') {
503-
writeIterable({
503+
writeIterable(
504504
abort,
505+
stream,
506+
body.stream(),
505507
client,
506508
request,
509+
client[kSocket],
507510
contentLength,
508-
expectsPayload,
509-
h2stream: stream,
510-
body: body.stream(),
511-
socket: client[kSocket]
512-
})
511+
expectsPayload
512+
)
513513
} else {
514-
writeBlob({
514+
writeBlob(
515515
abort,
516+
stream,
516517
body,
517518
client,
518519
request,
520+
client[kSocket],
519521
contentLength,
520-
expectsPayload,
521-
h2stream: stream,
522-
socket: client[kSocket]
523-
})
522+
expectsPayload
523+
)
524524
}
525525
} else if (util.isStream(body)) {
526-
writeStream({
526+
writeStream(
527527
abort,
528+
client[kSocket],
529+
expectsPayload,
530+
stream,
528531
body,
529532
client,
530533
request,
531-
contentLength,
532-
expectsPayload,
533-
socket: client[kSocket],
534-
h2stream: stream,
535-
header: ''
536-
})
534+
contentLength
535+
)
537536
} else if (util.isIterable(body)) {
538-
writeIterable({
537+
writeIterable(
539538
abort,
539+
stream,
540540
body,
541541
client,
542542
request,
543+
client[kSocket],
543544
contentLength,
544-
expectsPayload,
545-
header: '',
546-
h2stream: stream,
547-
socket: client[kSocket]
548-
})
545+
expectsPayload
546+
)
549547
} else {
550548
assert(false)
551549
}
552550
}
553551
}
554552

555-
function writeBuffer ({ abort, h2stream, body, client, request, socket, contentLength, expectsPayload }) {
553+
function writeBuffer (abort, h2stream, body, client, request, socket, contentLength, expectsPayload) {
556554
try {
557555
if (body != null && util.isBuffer(body)) {
558556
assert(contentLength === body.byteLength, 'buffer body must have content length')
@@ -575,7 +573,7 @@ function writeBuffer ({ abort, h2stream, body, client, request, socket, contentL
575573
}
576574
}
577575

578-
function writeStream ({ abort, socket, expectsPayload, h2stream, body, client, request, contentLength }) {
576+
function writeStream (abort, socket, expectsPayload, h2stream, body, client, request, contentLength) {
579577
assert(contentLength !== 0 || client[kRunning] === 0, 'stream body cannot be pipelined')
580578

581579
// For HTTP/2, is enough to pipe the stream
@@ -606,7 +604,7 @@ function writeStream ({ abort, socket, expectsPayload, h2stream, body, client, r
606604
}
607605
}
608606

609-
async function writeBlob ({ abort, h2stream, body, client, request, socket, contentLength, expectsPayload }) {
607+
async function writeBlob (abort, h2stream, body, client, request, socket, contentLength, expectsPayload) {
610608
assert(contentLength === body.size, 'blob body must have content length')
611609

612610
try {
@@ -634,7 +632,7 @@ async function writeBlob ({ abort, h2stream, body, client, request, socket, cont
634632
}
635633
}
636634

637-
async function writeIterable ({ abort, h2stream, body, client, request, socket, contentLength, expectsPayload }) {
635+
async function writeIterable (abort, h2stream, body, client, request, socket, contentLength, expectsPayload) {
638636
assert(contentLength !== 0 || client[kRunning] === 0, 'iterator body cannot be pipelined')
639637

640638
let callback = null

Diff for: deps/undici/src/lib/handler/retry-handler.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class RetryHandler {
202202
this.abort(
203203
new RequestRetryError('Content-Range mismatch', statusCode, {
204204
headers,
205-
count: this.retryCount
205+
data: { count: this.retryCount }
206206
})
207207
)
208208
return false
@@ -213,7 +213,7 @@ class RetryHandler {
213213
this.abort(
214214
new RequestRetryError('ETag mismatch', statusCode, {
215215
headers,
216-
count: this.retryCount
216+
data: { count: this.retryCount }
217217
})
218218
)
219219
return false

Diff for: deps/undici/src/lib/web/fetch/request.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const nodeUtil = require('node:util')
1010
const {
1111
isValidHTTPToken,
1212
sameOrigin,
13-
normalizeMethod,
14-
environmentSettingsObject,
15-
normalizeMethodRecord
13+
environmentSettingsObject
1614
} = require('./util')
1715
const {
1816
forbiddenMethodsSet,
@@ -24,7 +22,7 @@ const {
2422
requestCache,
2523
requestDuplex
2624
} = require('./constants')
27-
const { kEnumerableProperty } = util
25+
const { kEnumerableProperty, normalizedMethodRecordsBase, normalizedMethodRecords } = util
2826
const { kHeaders, kSignal, kState, kDispatcher } = require('./symbols')
2927
const { webidl } = require('./webidl')
3028
const { URLSerializer } = require('./data-url')
@@ -349,7 +347,7 @@ class Request {
349347
// 1. Let method be init["method"].
350348
let method = init.method
351349

352-
const mayBeNormalized = normalizeMethodRecord[method]
350+
const mayBeNormalized = normalizedMethodRecords[method]
353351

354352
if (mayBeNormalized !== undefined) {
355353
// Note: Bypass validation DELETE, GET, HEAD, OPTIONS, POST, PUT, PATCH and these lowercase ones
@@ -361,12 +359,16 @@ class Request {
361359
throw new TypeError(`'${method}' is not a valid HTTP method.`)
362360
}
363361

364-
if (forbiddenMethodsSet.has(method.toUpperCase())) {
362+
const upperCase = method.toUpperCase()
363+
364+
if (forbiddenMethodsSet.has(upperCase)) {
365365
throw new TypeError(`'${method}' HTTP method is unsupported.`)
366366
}
367367

368368
// 3. Normalize method.
369-
method = normalizeMethod(method)
369+
// https://fetch.spec.whatwg.org/#concept-method-normalize
370+
// Note: must be in uppercase
371+
method = normalizedMethodRecordsBase[upperCase] ?? method
370372

371373
// 4. Set request’s method to method.
372374
request.method = method

0 commit comments

Comments
 (0)