Skip to content

Commit ba9ec91

Browse files
nodejs-github-bottargos
authored andcommittedMay 2, 2023
deps: update undici to 5.21.1
PR-URL: #47488 Reviewed-By: Debadree Chatterjee <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 26c2462 commit ba9ec91

12 files changed

+196
-94
lines changed
 

‎deps/undici/src/lib/core/symbols.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = {
4141
kClient: Symbol('client'),
4242
kParser: Symbol('parser'),
4343
kOnDestroyed: Symbol('destroy callbacks'),
44-
kPipelining: Symbol('pipelinig'),
44+
kPipelining: Symbol('pipelining'),
4545
kSocket: Symbol('socket'),
4646
kHostHeader: Symbol('host header'),
4747
kConnector: Symbol('connector'),

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

+24-9
Original file line numberDiff line numberDiff line change
@@ -48,38 +48,38 @@ function parseURL (url) {
4848
url = new URL(url)
4949

5050
if (!/^https?:/.test(url.origin || url.protocol)) {
51-
throw new InvalidArgumentError('invalid protocol')
51+
throw new InvalidArgumentError('Invalid URL protocol: the URL must start with `http:` or `https:`.')
5252
}
5353

5454
return url
5555
}
5656

5757
if (!url || typeof url !== 'object') {
58-
throw new InvalidArgumentError('invalid url')
58+
throw new InvalidArgumentError('Invalid URL: The URL argument must be a non-null object.')
5959
}
6060

6161
if (url.port != null && url.port !== '' && !Number.isFinite(parseInt(url.port))) {
62-
throw new InvalidArgumentError('invalid port')
62+
throw new InvalidArgumentError('Invalid URL: port must be a valid integer or a string representation of an integer.')
6363
}
6464

6565
if (url.path != null && typeof url.path !== 'string') {
66-
throw new InvalidArgumentError('invalid path')
66+
throw new InvalidArgumentError('Invalid URL path: the path must be a string or null/undefined.')
6767
}
6868

6969
if (url.pathname != null && typeof url.pathname !== 'string') {
70-
throw new InvalidArgumentError('invalid pathname')
70+
throw new InvalidArgumentError('Invalid URL pathname: the pathname must be a string or null/undefined.')
7171
}
7272

7373
if (url.hostname != null && typeof url.hostname !== 'string') {
74-
throw new InvalidArgumentError('invalid hostname')
74+
throw new InvalidArgumentError('Invalid URL hostname: the hostname must be a string or null/undefined.')
7575
}
7676

7777
if (url.origin != null && typeof url.origin !== 'string') {
78-
throw new InvalidArgumentError('invalid origin')
78+
throw new InvalidArgumentError('Invalid URL origin: the origin must be a string or null/undefined.')
7979
}
8080

8181
if (!/^https?:/.test(url.origin || url.protocol)) {
82-
throw new InvalidArgumentError('invalid protocol')
82+
throw new InvalidArgumentError('Invalid URL protocol: the URL must start with `http:` or `https:`.')
8383
}
8484

8585
if (!(url instanceof URL)) {
@@ -409,6 +409,21 @@ function throwIfAborted (signal) {
409409
}
410410
}
411411

412+
const hasToWellFormed = !!String.prototype.toWellFormed
413+
414+
/**
415+
* @param {string} val
416+
*/
417+
function toUSVString (val) {
418+
if (hasToWellFormed) {
419+
return `${val}`.toWellFormed()
420+
} else if (nodeUtil.toUSVString) {
421+
return nodeUtil.toUSVString(val)
422+
}
423+
424+
return `${val}`
425+
}
426+
412427
const kEnumerableProperty = Object.create(null)
413428
kEnumerableProperty.enumerable = true
414429

@@ -418,7 +433,7 @@ module.exports = {
418433
isDisturbed,
419434
isErrored,
420435
isReadable,
421-
toUSVString: nodeUtil.toUSVString || ((val) => `${val}`),
436+
toUSVString,
422437
isReadableAborted,
423438
isBlobLike,
424439
parseOrigin,

‎deps/undici/src/lib/fetch/constants.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,17 @@ const requestCache = [
4848
'only-if-cached'
4949
]
5050

51+
// https://fetch.spec.whatwg.org/#request-body-header-name
5152
const requestBodyHeader = [
5253
'content-encoding',
5354
'content-language',
5455
'content-location',
55-
'content-type'
56+
'content-type',
57+
// See https://github.com/nodejs/undici/issues/2021
58+
// 'Content-Length' is a forbidden header name, which is typically
59+
// removed in the Headers implementation. However, undici doesn't
60+
// filter out headers, so we add it here.
61+
'content-length'
5662
]
5763

5864
// https://fetch.spec.whatwg.org/#enumdef-requestduplex

‎deps/undici/src/lib/fetch/formdata.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,7 @@ class FormData {
6161

6262
// The delete(name) method steps are to remove all entries whose name
6363
// is name from this’s entry list.
64-
const next = []
65-
for (const entry of this[kState]) {
66-
if (entry.name !== name) {
67-
next.push(entry)
68-
}
69-
}
70-
71-
this[kState] = next
64+
this[kState] = this[kState].filter(entry => entry.name !== name)
7265
}
7366

7467
get (name) {

‎deps/undici/src/lib/fetch/index.js

+22-14
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ const {
3737
isErrorLike,
3838
fullyReadBody,
3939
readableStreamClose,
40-
isomorphicEncode
40+
isomorphicEncode,
41+
urlIsLocal,
42+
urlIsHttpHttpsScheme,
43+
urlHasHttpsScheme
4144
} = require('./util')
4245
const { kState, kHeaders, kGuard, kRealm, kHeadersCaseInsensitive } = require('./symbols')
4346
const assert = require('assert')
@@ -272,7 +275,7 @@ function finalizeAndReportTiming (response, initiatorType = 'other') {
272275
let cacheState = response.cacheState
273276

274277
// 6. If originalURL’s scheme is not an HTTP(S) scheme, then return.
275-
if (!/^https?:/.test(originalURL.protocol)) {
278+
if (!urlIsHttpHttpsScheme(originalURL)) {
276279
return
277280
}
278281

@@ -530,10 +533,7 @@ async function mainFetch (fetchParams, recursive = false) {
530533

531534
// 3. If request’s local-URLs-only flag is set and request’s current URL is
532535
// not local, then set response to a network error.
533-
if (
534-
request.localURLsOnly &&
535-
!/^(about|blob|data):/.test(requestCurrentURL(request).protocol)
536-
) {
536+
if (request.localURLsOnly && !urlIsLocal(requestCurrentURL(request))) {
537537
response = makeNetworkError('local URLs only')
538538
}
539539

@@ -623,7 +623,7 @@ async function mainFetch (fetchParams, recursive = false) {
623623
}
624624

625625
// request’s current URL’s scheme is not an HTTP(S) scheme
626-
if (!/^https?:/.test(requestCurrentURL(request).protocol)) {
626+
if (!urlIsHttpHttpsScheme(requestCurrentURL(request))) {
627627
// Return a network error.
628628
return makeNetworkError('URL scheme must be a HTTP(S) scheme')
629629
}
@@ -1130,7 +1130,7 @@ async function httpRedirectFetch (fetchParams, response) {
11301130

11311131
// 6. If locationURL’s scheme is not an HTTP(S) scheme, then return a network
11321132
// error.
1133-
if (!/^https?:/.test(locationURL.protocol)) {
1133+
if (!urlIsHttpHttpsScheme(locationURL)) {
11341134
return makeNetworkError('URL scheme must be a HTTP(S) scheme')
11351135
}
11361136

@@ -1205,7 +1205,7 @@ async function httpRedirectFetch (fetchParams, response) {
12051205
// 14. If request’s body is non-null, then set request’s body to the first return
12061206
// value of safely extracting request’s body’s source.
12071207
if (request.body != null) {
1208-
assert(request.body.source)
1208+
assert(request.body.source != null)
12091209
request.body = safelyExtractBody(request.body.source)[0]
12101210
}
12111211

@@ -1399,7 +1399,7 @@ async function httpNetworkOrCacheFetch (
13991399
// header if httpRequest’s header list contains that header’s name.
14001400
// TODO: https://github.com/whatwg/fetch/issues/1285#issuecomment-896560129
14011401
if (!httpRequest.headersList.contains('accept-encoding')) {
1402-
if (/^https:/.test(requestCurrentURL(httpRequest).protocol)) {
1402+
if (urlHasHttpsScheme(requestCurrentURL(httpRequest))) {
14031403
httpRequest.headersList.append('accept-encoding', 'br, gzip, deflate')
14041404
} else {
14051405
httpRequest.headersList.append('accept-encoding', 'gzip, deflate')
@@ -1845,6 +1845,7 @@ async function httpNetworkFetch (
18451845
// 4. Set bytes to the result of handling content codings given
18461846
// codings and bytes.
18471847
let bytes
1848+
let isFailure
18481849
try {
18491850
const { done, value } = await fetchParams.controller.next()
18501851

@@ -1859,6 +1860,10 @@ async function httpNetworkFetch (
18591860
bytes = undefined
18601861
} else {
18611862
bytes = err
1863+
1864+
// err may be propagated from the result of calling readablestream.cancel,
1865+
// which might not be an error. https://github.com/nodejs/undici/issues/2009
1866+
isFailure = true
18621867
}
18631868
}
18641869

@@ -1878,7 +1883,7 @@ async function httpNetworkFetch (
18781883
timingInfo.decodedBodySize += bytes?.byteLength ?? 0
18791884

18801885
// 6. If bytes is failure, then terminate fetchParams’s controller.
1881-
if (isErrorLike(bytes)) {
1886+
if (isFailure) {
18821887
fetchParams.controller.terminate(bytes)
18831888
return
18841889
}
@@ -1979,7 +1984,9 @@ async function httpNetworkFetch (
19791984
const val = headersList[n + 1].toString('latin1')
19801985

19811986
if (key.toLowerCase() === 'content-encoding') {
1982-
codings = val.split(',').map((x) => x.trim())
1987+
// https://www.rfc-editor.org/rfc/rfc7231#section-3.1.2.1
1988+
// "All content-coding values are case-insensitive..."
1989+
codings = val.toLowerCase().split(',').map((x) => x.trim())
19831990
} else if (key.toLowerCase() === 'location') {
19841991
location = val
19851992
}
@@ -1998,9 +2005,10 @@ async function httpNetworkFetch (
19982005
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
19992006
if (request.method !== 'HEAD' && request.method !== 'CONNECT' && !nullBodyStatus.includes(status) && !willFollow) {
20002007
for (const coding of codings) {
2001-
if (/(x-)?gzip/.test(coding)) {
2008+
// https://www.rfc-editor.org/rfc/rfc9112.html#section-7.2
2009+
if (coding === 'x-gzip' || coding === 'gzip') {
20022010
decoders.push(zlib.createGunzip())
2003-
} else if (/(x-)?deflate/.test(coding)) {
2011+
} else if (coding === 'deflate') {
20042012
decoders.push(zlib.createInflate())
20052013
} else if (coding === 'br') {
20062014
decoders.push(zlib.createBrotliDecompress())

‎deps/undici/src/lib/fetch/request.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const { setMaxListeners, getEventListeners, defaultMaxListeners } = require('eve
3434
let TransformStream = globalThis.TransformStream
3535

3636
const kInit = Symbol('init')
37+
const kAbortController = Symbol('abortController')
3738

3839
const requestFinalizer = new FinalizationRegistry(({ signal, abort }) => {
3940
signal.removeEventListener('abort', abort)
@@ -128,12 +129,12 @@ class Request {
128129
}
129130

130131
// 10. If init["window"] exists and is non-null, then throw a TypeError.
131-
if (init.window !== undefined && init.window != null) {
132+
if (init.window != null) {
132133
throw new TypeError(`'window' option '${window}' must be null`)
133134
}
134135

135136
// 11. If init["window"] exists, then set window to "no-window".
136-
if (init.window !== undefined) {
137+
if ('window' in init) {
137138
window = 'no-window'
138139
}
139140

@@ -354,20 +355,30 @@ class Request {
354355
if (signal.aborted) {
355356
ac.abort(signal.reason)
356357
} else {
358+
// Keep a strong ref to ac while request object
359+
// is alive. This is needed to prevent AbortController
360+
// from being prematurely garbage collected.
361+
// See, https://github.com/nodejs/undici/issues/1926.
362+
this[kAbortController] = ac
363+
364+
const acRef = new WeakRef(ac)
357365
const abort = function () {
358-
ac.abort(this.reason)
366+
const ac = acRef.deref()
367+
if (ac !== undefined) {
368+
ac.abort(this.reason)
369+
}
359370
}
360371

361372
// Third-party AbortControllers may not work with these.
362-
// See https://github.com/nodejs/undici/pull/1910#issuecomment-1464495619
373+
// See, https://github.com/nodejs/undici/pull/1910#issuecomment-1464495619.
363374
try {
364375
if (getEventListeners(signal, 'abort').length >= defaultMaxListeners) {
365376
setMaxListeners(100, signal)
366377
}
367378
} catch {}
368379

369380
signal.addEventListener('abort', abort, { once: true })
370-
requestFinalizer.register(this, { signal, abort })
381+
requestFinalizer.register(ac, { signal, abort })
371382
}
372383
}
373384

@@ -427,7 +438,7 @@ class Request {
427438
// non-null, and request’s method is `GET` or `HEAD`, then throw a
428439
// TypeError.
429440
if (
430-
((init.body !== undefined && init.body != null) || inputBody != null) &&
441+
(init.body != null || inputBody != null) &&
431442
(request.method === 'GET' || request.method === 'HEAD')
432443
) {
433444
throw new TypeError('Request with GET/HEAD method cannot have body.')
@@ -437,7 +448,7 @@ class Request {
437448
let initBody = null
438449

439450
// 36. If init["body"] exists and is non-null, then:
440-
if (init.body !== undefined && init.body != null) {
451+
if (init.body != null) {
441452
// 1. Let Content-Type be null.
442453
// 2. Set initBody and Content-Type to the result of extracting
443454
// init["body"], with keepalive set to request’s keepalive.

‎deps/undici/src/lib/fetch/response.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,7 @@ function makeNetworkError (reason) {
348348
status: 0,
349349
error: isError
350350
? reason
351-
: new Error(reason ? String(reason) : reason, {
352-
cause: isError ? reason : undefined
353-
}),
351+
: new Error(reason ? String(reason) : reason),
354352
aborted: reason && reason.name === 'AbortError'
355353
})
356354
}

‎deps/undici/src/lib/fetch/util.js

+41-3
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function requestBadPort (request) {
6464

6565
// 2. If url’s scheme is an HTTP(S) scheme and url’s port is a bad port,
6666
// then return blocked.
67-
if (/^https?:/.test(url.protocol) && badPorts.includes(url.port)) {
67+
if (urlIsHttpHttpsScheme(url) && badPorts.includes(url.port)) {
6868
return 'blocked'
6969
}
7070

@@ -285,7 +285,7 @@ function appendRequestOriginHeader (request) {
285285
case 'strict-origin':
286286
case 'strict-origin-when-cross-origin':
287287
// If request’s origin is a tuple origin, its scheme is "https", and request’s current URL’s scheme is not "https", then set serializedOrigin to `null`.
288-
if (/^https:/.test(request.origin) && !/^https:/.test(requestCurrentURL(request))) {
288+
if (request.origin && urlHasHttpsScheme(request.origin) && !urlHasHttpsScheme(requestCurrentURL(request))) {
289289
serializedOrigin = null
290290
}
291291
break
@@ -944,6 +944,41 @@ async function readAllBytes (reader, successSteps, failureSteps) {
944944
}
945945
}
946946

947+
/**
948+
* @see https://fetch.spec.whatwg.org/#is-local
949+
* @param {URL} url
950+
*/
951+
function urlIsLocal (url) {
952+
assert('protocol' in url) // ensure it's a url object
953+
954+
const protocol = url.protocol
955+
956+
return protocol === 'about:' || protocol === 'blob:' || protocol === 'data:'
957+
}
958+
959+
/**
960+
* @param {string|URL} url
961+
*/
962+
function urlHasHttpsScheme (url) {
963+
if (typeof url === 'string') {
964+
return url.startsWith('https:')
965+
}
966+
967+
return url.protocol === 'https:'
968+
}
969+
970+
/**
971+
* @see https://fetch.spec.whatwg.org/#http-scheme
972+
* @param {URL} url
973+
*/
974+
function urlIsHttpHttpsScheme (url) {
975+
assert('protocol' in url) // ensure it's a url object
976+
977+
const protocol = url.protocol
978+
979+
return protocol === 'http:' || protocol === 'https:'
980+
}
981+
947982
/**
948983
* Fetch supports node >= 16.8.0, but Object.hasOwn was added in v16.9.0.
949984
*/
@@ -988,5 +1023,8 @@ module.exports = {
9881023
isReadableStreamLike,
9891024
readableStreamClose,
9901025
isomorphicEncode,
991-
isomorphicDecode
1026+
isomorphicDecode,
1027+
urlIsLocal,
1028+
urlHasHttpsScheme,
1029+
urlIsHttpHttpsScheme
9921030
}

‎deps/undici/src/package.json

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "undici",
3-
"version": "5.21.0",
3+
"version": "5.21.1",
44
"description": "An HTTP/1.1 client, written from scratch for Node.js",
55
"homepage": "https://undici.nodejs.org",
66
"bugs": {
@@ -49,7 +49,7 @@
4949
"test": "npm run test:tap && npm run test:node-fetch && npm run test:fetch && npm run test:cookies && npm run test:wpt && npm run test:websocket && npm run test:jest && tsd",
5050
"test:cookies": "node scripts/verifyVersion 16 || tap test/cookie/*.js",
5151
"test:node-fetch": "node scripts/verifyVersion.js 16 || mocha test/node-fetch",
52-
"test:fetch": "node scripts/verifyVersion.js 16 || (npm run build:node && tap test/fetch/*.js && tap test/webidl/*.js)",
52+
"test:fetch": "node scripts/verifyVersion.js 16 || (npm run build:node && tap --expose-gc test/fetch/*.js && tap test/webidl/*.js)",
5353
"test:jest": "node scripts/verifyVersion.js 14 || jest",
5454
"test:tap": "tap test/*.js test/diagnostics-channel/*.js",
5555
"test:tdd": "tap test/*.js test/diagnostics-channel/*.js -w",
@@ -75,7 +75,7 @@
7575
"chai-as-promised": "^7.1.1",
7676
"chai-iterator": "^3.0.2",
7777
"chai-string": "^1.5.0",
78-
"concurrently": "^7.1.0",
78+
"concurrently": "^8.0.1",
7979
"cronometro": "^1.0.5",
8080
"delay": "^5.0.0",
8181
"dns-packet": "^5.4.0",
@@ -98,9 +98,9 @@
9898
"standard": "^17.0.0",
9999
"table": "^6.8.0",
100100
"tap": "^16.1.0",
101-
"tsd": "^0.25.0",
102-
"typescript": "^4.9.5",
103-
"wait-on": "^6.0.0",
101+
"tsd": "^0.27.0",
102+
"typescript": "^5.0.2",
103+
"wait-on": "^7.0.1",
104104
"ws": "^8.11.0"
105105
},
106106
"engines": {

‎deps/undici/src/types/websocket.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="node" />
22

3+
import type { Blob } from 'buffer'
34
import type { MessagePort } from 'worker_threads'
45
import {
56
EventTarget,

‎deps/undici/undici.js

+73-41
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ var require_symbols = __commonJS({
5050
kClient: Symbol("client"),
5151
kParser: Symbol("parser"),
5252
kOnDestroyed: Symbol("destroy callbacks"),
53-
kPipelining: Symbol("pipelinig"),
53+
kPipelining: Symbol("pipelining"),
5454
kSocket: Symbol("socket"),
5555
kHostHeader: Symbol("host header"),
5656
kConnector: Symbol("connector"),
@@ -319,30 +319,30 @@ var require_util = __commonJS({
319319
if (typeof url === "string") {
320320
url = new URL(url);
321321
if (!/^https?:/.test(url.origin || url.protocol)) {
322-
throw new InvalidArgumentError("invalid protocol");
322+
throw new InvalidArgumentError("Invalid URL protocol: the URL must start with `http:` or `https:`.");
323323
}
324324
return url;
325325
}
326326
if (!url || typeof url !== "object") {
327-
throw new InvalidArgumentError("invalid url");
327+
throw new InvalidArgumentError("Invalid URL: The URL argument must be a non-null object.");
328328
}
329329
if (url.port != null && url.port !== "" && !Number.isFinite(parseInt(url.port))) {
330-
throw new InvalidArgumentError("invalid port");
330+
throw new InvalidArgumentError("Invalid URL: port must be a valid integer or a string representation of an integer.");
331331
}
332332
if (url.path != null && typeof url.path !== "string") {
333-
throw new InvalidArgumentError("invalid path");
333+
throw new InvalidArgumentError("Invalid URL path: the path must be a string or null/undefined.");
334334
}
335335
if (url.pathname != null && typeof url.pathname !== "string") {
336-
throw new InvalidArgumentError("invalid pathname");
336+
throw new InvalidArgumentError("Invalid URL pathname: the pathname must be a string or null/undefined.");
337337
}
338338
if (url.hostname != null && typeof url.hostname !== "string") {
339-
throw new InvalidArgumentError("invalid hostname");
339+
throw new InvalidArgumentError("Invalid URL hostname: the hostname must be a string or null/undefined.");
340340
}
341341
if (url.origin != null && typeof url.origin !== "string") {
342-
throw new InvalidArgumentError("invalid origin");
342+
throw new InvalidArgumentError("Invalid URL origin: the origin must be a string or null/undefined.");
343343
}
344344
if (!/^https?:/.test(url.origin || url.protocol)) {
345-
throw new InvalidArgumentError("invalid protocol");
345+
throw new InvalidArgumentError("Invalid URL protocol: the URL must start with `http:` or `https:`.");
346346
}
347347
if (!(url instanceof URL)) {
348348
const port = url.port != null ? url.port : url.protocol === "https:" ? 443 : 80;
@@ -570,6 +570,15 @@ var require_util = __commonJS({
570570
}
571571
}
572572
}
573+
var hasToWellFormed = !!String.prototype.toWellFormed;
574+
function toUSVString(val) {
575+
if (hasToWellFormed) {
576+
return `${val}`.toWellFormed();
577+
} else if (nodeUtil.toUSVString) {
578+
return nodeUtil.toUSVString(val);
579+
}
580+
return `${val}`;
581+
}
573582
var kEnumerableProperty = /* @__PURE__ */ Object.create(null);
574583
kEnumerableProperty.enumerable = true;
575584
module2.exports = {
@@ -578,7 +587,7 @@ var require_util = __commonJS({
578587
isDisturbed,
579588
isErrored,
580589
isReadable,
581-
toUSVString: nodeUtil.toUSVString || ((val) => `${val}`),
590+
toUSVString,
582591
isReadableAborted,
583592
isBlobLike,
584593
parseOrigin,
@@ -725,7 +734,8 @@ var require_constants = __commonJS({
725734
"content-encoding",
726735
"content-language",
727736
"content-location",
728-
"content-type"
737+
"content-type",
738+
"content-length"
729739
];
730740
var requestDuplex = [
731741
"half"
@@ -863,7 +873,7 @@ var require_util2 = __commonJS({
863873
}
864874
function requestBadPort(request) {
865875
const url = requestCurrentURL(request);
866-
if (/^https?:/.test(url.protocol) && badPorts.includes(url.port)) {
876+
if (urlIsHttpHttpsScheme(url) && badPorts.includes(url.port)) {
867877
return "blocked";
868878
}
869879
return "allowed";
@@ -955,7 +965,7 @@ var require_util2 = __commonJS({
955965
case "no-referrer-when-downgrade":
956966
case "strict-origin":
957967
case "strict-origin-when-cross-origin":
958-
if (/^https:/.test(request.origin) && !/^https:/.test(requestCurrentURL(request))) {
968+
if (request.origin && urlHasHttpsScheme(request.origin) && !urlHasHttpsScheme(requestCurrentURL(request))) {
959969
serializedOrigin = null;
960970
}
961971
break;
@@ -1272,6 +1282,22 @@ var require_util2 = __commonJS({
12721282
byteLength += chunk.length;
12731283
}
12741284
}
1285+
function urlIsLocal(url) {
1286+
assert("protocol" in url);
1287+
const protocol = url.protocol;
1288+
return protocol === "about:" || protocol === "blob:" || protocol === "data:";
1289+
}
1290+
function urlHasHttpsScheme(url) {
1291+
if (typeof url === "string") {
1292+
return url.startsWith("https:");
1293+
}
1294+
return url.protocol === "https:";
1295+
}
1296+
function urlIsHttpHttpsScheme(url) {
1297+
assert("protocol" in url);
1298+
const protocol = url.protocol;
1299+
return protocol === "http:" || protocol === "https:";
1300+
}
12751301
var hasOwn = Object.hasOwn || ((dict, key) => Object.prototype.hasOwnProperty.call(dict, key));
12761302
module2.exports = {
12771303
isAborted,
@@ -1312,7 +1338,10 @@ var require_util2 = __commonJS({
13121338
isReadableStreamLike,
13131339
readableStreamClose,
13141340
isomorphicEncode,
1315-
isomorphicDecode
1341+
isomorphicDecode,
1342+
urlIsLocal,
1343+
urlHasHttpsScheme,
1344+
urlIsHttpHttpsScheme
13161345
};
13171346
}
13181347
});
@@ -6122,13 +6151,7 @@ var require_formdata = __commonJS({
61226151
webidl.brandCheck(this, FormData);
61236152
webidl.argumentLengthCheck(arguments, 1, { header: "FormData.delete" });
61246153
name = webidl.converters.USVString(name);
6125-
const next = [];
6126-
for (const entry of this[kState]) {
6127-
if (entry.name !== name) {
6128-
next.push(entry);
6129-
}
6130-
}
6131-
this[kState] = next;
6154+
this[kState] = this[kState].filter((entry) => entry.name !== name);
61326155
}
61336156
get(name) {
61346157
webidl.brandCheck(this, FormData);
@@ -6799,9 +6822,7 @@ var require_response = __commonJS({
67996822
return makeResponse({
68006823
type: "error",
68016824
status: 0,
6802-
error: isError ? reason : new Error(reason ? String(reason) : reason, {
6803-
cause: isError ? reason : void 0
6804-
}),
6825+
error: isError ? reason : new Error(reason ? String(reason) : reason),
68056826
aborted: reason && reason.name === "AbortError"
68066827
});
68076828
}
@@ -7011,6 +7032,7 @@ var require_request = __commonJS({
70117032
var { setMaxListeners, getEventListeners, defaultMaxListeners } = require("events");
70127033
var TransformStream = globalThis.TransformStream;
70137034
var kInit = Symbol("init");
7035+
var kAbortController = Symbol("abortController");
70147036
var requestFinalizer = new FinalizationRegistry(({ signal, abort }) => {
70157037
signal.removeEventListener("abort", abort);
70167038
});
@@ -7057,10 +7079,10 @@ var require_request = __commonJS({
70577079
if (request.window?.constructor?.name === "EnvironmentSettingsObject" && sameOrigin(request.window, origin)) {
70587080
window = request.window;
70597081
}
7060-
if (init.window !== void 0 && init.window != null) {
7082+
if (init.window != null) {
70617083
throw new TypeError(`'window' option '${window}' must be null`);
70627084
}
7063-
if (init.window !== void 0) {
7085+
if ("window" in init) {
70647086
window = "no-window";
70657087
}
70667088
request = makeRequest({
@@ -7170,8 +7192,13 @@ var require_request = __commonJS({
71707192
if (signal.aborted) {
71717193
ac.abort(signal.reason);
71727194
} else {
7195+
this[kAbortController] = ac;
7196+
const acRef = new WeakRef(ac);
71737197
const abort = function() {
7174-
ac.abort(this.reason);
7198+
const ac2 = acRef.deref();
7199+
if (ac2 !== void 0) {
7200+
ac2.abort(this.reason);
7201+
}
71757202
};
71767203
try {
71777204
if (getEventListeners(signal, "abort").length >= defaultMaxListeners) {
@@ -7180,7 +7207,7 @@ var require_request = __commonJS({
71807207
} catch {
71817208
}
71827209
signal.addEventListener("abort", abort, { once: true });
7183-
requestFinalizer.register(this, { signal, abort });
7210+
requestFinalizer.register(ac, { signal, abort });
71847211
}
71857212
}
71867213
this[kHeaders] = new Headers();
@@ -7208,11 +7235,11 @@ var require_request = __commonJS({
72087235
}
72097236
}
72107237
const inputBody = input instanceof Request ? input[kState].body : null;
7211-
if ((init.body !== void 0 && init.body != null || inputBody != null) && (request.method === "GET" || request.method === "HEAD")) {
7238+
if ((init.body != null || inputBody != null) && (request.method === "GET" || request.method === "HEAD")) {
72127239
throw new TypeError("Request with GET/HEAD method cannot have body.");
72137240
}
72147241
let initBody = null;
7215-
if (init.body !== void 0 && init.body != null) {
7242+
if (init.body != null) {
72167243
const [extractedBody, contentType] = extractBody(init.body, request.keepalive);
72177244
initBody = extractedBody;
72187245
if (contentType && !this[kHeaders][kHeadersList].contains("content-type")) {
@@ -10536,7 +10563,10 @@ var require_fetch = __commonJS({
1053610563
isErrorLike,
1053710564
fullyReadBody,
1053810565
readableStreamClose,
10539-
isomorphicEncode
10566+
isomorphicEncode,
10567+
urlIsLocal,
10568+
urlIsHttpHttpsScheme,
10569+
urlHasHttpsScheme
1054010570
} = require_util2();
1054110571
var { kState, kHeaders, kGuard, kRealm, kHeadersCaseInsensitive } = require_symbols2();
1054210572
var assert = require("assert");
@@ -10659,7 +10689,7 @@ var require_fetch = __commonJS({
1065910689
const originalURL = response.urlList[0];
1066010690
let timingInfo = response.timingInfo;
1066110691
let cacheState = response.cacheState;
10662-
if (!/^https?:/.test(originalURL.protocol)) {
10692+
if (!urlIsHttpHttpsScheme(originalURL)) {
1066310693
return;
1066410694
}
1066510695
if (timingInfo === null) {
@@ -10771,7 +10801,7 @@ var require_fetch = __commonJS({
1077110801
async function mainFetch(fetchParams, recursive = false) {
1077210802
const request = fetchParams.request;
1077310803
let response = null;
10774-
if (request.localURLsOnly && !/^(about|blob|data):/.test(requestCurrentURL(request).protocol)) {
10804+
if (request.localURLsOnly && !urlIsLocal(requestCurrentURL(request))) {
1077510805
response = makeNetworkError("local URLs only");
1077610806
}
1077710807
tryUpgradeRequestToAPotentiallyTrustworthyURL(request);
@@ -10801,7 +10831,7 @@ var require_fetch = __commonJS({
1080110831
request.responseTainting = "opaque";
1080210832
return await schemeFetch(fetchParams);
1080310833
}
10804-
if (!/^https?:/.test(requestCurrentURL(request).protocol)) {
10834+
if (!urlIsHttpHttpsScheme(requestCurrentURL(request))) {
1080510835
return makeNetworkError("URL scheme must be a HTTP(S) scheme");
1080610836
}
1080710837
request.responseTainting = "cors";
@@ -11025,7 +11055,7 @@ var require_fetch = __commonJS({
1102511055
} catch (err) {
1102611056
return makeNetworkError(err);
1102711057
}
11028-
if (!/^https?:/.test(locationURL.protocol)) {
11058+
if (!urlIsHttpHttpsScheme(locationURL)) {
1102911059
return makeNetworkError("URL scheme must be a HTTP(S) scheme");
1103011060
}
1103111061
if (request.redirectCount === 20) {
@@ -11052,7 +11082,7 @@ var require_fetch = __commonJS({
1105211082
request.headersList.delete("authorization");
1105311083
}
1105411084
if (request.body != null) {
11055-
assert(request.body.source);
11085+
assert(request.body.source != null);
1105611086
request.body = safelyExtractBody(request.body.source)[0];
1105711087
}
1105811088
const timingInfo = fetchParams.timingInfo;
@@ -11119,7 +11149,7 @@ var require_fetch = __commonJS({
1111911149
httpRequest.headersList.append("accept-encoding", "identity");
1112011150
}
1112111151
if (!httpRequest.headersList.contains("accept-encoding")) {
11122-
if (/^https:/.test(requestCurrentURL(httpRequest).protocol)) {
11152+
if (urlHasHttpsScheme(requestCurrentURL(httpRequest))) {
1112311153
httpRequest.headersList.append("accept-encoding", "br, gzip, deflate");
1112411154
} else {
1112511155
httpRequest.headersList.append("accept-encoding", "gzip, deflate");
@@ -11279,6 +11309,7 @@ var require_fetch = __commonJS({
1127911309
fetchParams.controller.resume = async () => {
1128011310
while (true) {
1128111311
let bytes;
11312+
let isFailure;
1128211313
try {
1128311314
const { done, value } = await fetchParams.controller.next();
1128411315
if (isAborted(fetchParams)) {
@@ -11290,6 +11321,7 @@ var require_fetch = __commonJS({
1129011321
bytes = void 0;
1129111322
} else {
1129211323
bytes = err;
11324+
isFailure = true;
1129311325
}
1129411326
}
1129511327
if (bytes === void 0) {
@@ -11298,7 +11330,7 @@ var require_fetch = __commonJS({
1129811330
return;
1129911331
}
1130011332
timingInfo.decodedBodySize += bytes?.byteLength ?? 0;
11301-
if (isErrorLike(bytes)) {
11333+
if (isFailure) {
1130211334
fetchParams.controller.terminate(bytes);
1130311335
return;
1130411336
}
@@ -11362,7 +11394,7 @@ var require_fetch = __commonJS({
1136211394
const key = headersList[n + 0].toString("latin1");
1136311395
const val = headersList[n + 1].toString("latin1");
1136411396
if (key.toLowerCase() === "content-encoding") {
11365-
codings = val.split(",").map((x) => x.trim());
11397+
codings = val.toLowerCase().split(",").map((x) => x.trim());
1136611398
} else if (key.toLowerCase() === "location") {
1136711399
location = val;
1136811400
}
@@ -11373,9 +11405,9 @@ var require_fetch = __commonJS({
1137311405
const willFollow = request.redirect === "follow" && location && redirectStatus.includes(status);
1137411406
if (request.method !== "HEAD" && request.method !== "CONNECT" && !nullBodyStatus.includes(status) && !willFollow) {
1137511407
for (const coding of codings) {
11376-
if (/(x-)?gzip/.test(coding)) {
11408+
if (coding === "x-gzip" || coding === "gzip") {
1137711409
decoders.push(zlib.createGunzip());
11378-
} else if (/(x-)?deflate/.test(coding)) {
11410+
} else if (coding === "deflate") {
1137911411
decoders.push(zlib.createInflate());
1138011412
} else if (coding === "br") {
1138111413
decoders.push(zlib.createBrotliDecompress());

‎src/undici_version.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
// Refer to tools/update-undici.sh
33
#ifndef SRC_UNDICI_VERSION_H_
44
#define SRC_UNDICI_VERSION_H_
5-
#define UNDICI_VERSION "5.21.0"
5+
#define UNDICI_VERSION "5.21.1"
66
#endif // SRC_UNDICI_VERSION_H_

0 commit comments

Comments
 (0)
Please sign in to comment.