Skip to content

Commit 9158b91

Browse files
nodejs-github-botjuanarbol
authored andcommitted
deps: update undici to 4.16.0
PR-URL: #42414 Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Mestery <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 26d5e58 commit 9158b91

23 files changed

+124
-77
lines changed

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

+2
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ The `RequestOptions.method` property should not be value `'CONNECT'`.
489489
- `body`
490490
- `bodyUsed`
491491

492+
`body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.
493+
492494
`body` contains the following additional extensions:
493495

494496
- `dump({ limit: Integer })`, dump the response by reading up to `limit` bytes without killing the socket (optional) - Default: 262144.

deps/undici/src/lib/balanced-pool.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const kFactory = Symbol('factory')
2020
const kOptions = Symbol('options')
2121

2222
function defaultFactory (origin, opts) {
23-
return new Pool(origin, opts);
23+
return new Pool(origin, opts)
2424
}
2525

2626
class BalancedPool extends PoolBase {

deps/undici/src/lib/client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ class Parser {
794794
return -1
795795
}
796796

797-
/* istanbul ignore if: this can only happen if server is misbehaving */
797+
/* this can only happen if server is misbehaving */
798798
if (upgrade && !request.upgrade) {
799799
util.destroy(socket, new SocketError('bad upgrade', util.getSocketInfo(socket)))
800800
return -1

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function buildConnector ({ maxCachedSessions, socketPath, timeout, ...opts }) {
2525
let socket
2626
if (protocol === 'https:') {
2727
if (!tls) {
28-
tls = require('tls')
28+
tls = require('tls')
2929
}
3030
servername = servername || options.servername || util.getServerName(host) || null
3131

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ function parseHeaders (headers, obj = {}) {
201201
}
202202

203203
function parseRawHeaders (headers) {
204-
return headers.map(header => header.toString());
204+
return headers.map(header => header.toString())
205205
}
206206

207207
function isBuffer (buffer) {
@@ -263,15 +263,15 @@ function isErrored (body) {
263263
stream.isErrored
264264
? stream.isErrored(body)
265265
: /state: 'errored'/.test(nodeUtil.inspect(body)
266-
)))
266+
)))
267267
}
268268

269269
function isReadable (body) {
270270
return !!(body && (
271271
stream.isReadable
272272
? stream.isReadable(body)
273273
: /state: 'readable'/.test(nodeUtil.inspect(body)
274-
)))
274+
)))
275275
}
276276

277277
function getSocketInfo (socket) {

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

+7-11
Original file line numberDiff line numberDiff line change
@@ -227,22 +227,20 @@ function percentDecode (input) {
227227
// 1. If byte is not 0x25 (%), then append byte to output.
228228
if (byte !== 0x25) {
229229
output.push(byte)
230-
}
231230

232231
// 2. Otherwise, if byte is 0x25 (%) and the next two bytes
233232
// after byte in input are not in the ranges
234233
// 0x30 (0) to 0x39 (9), 0x41 (A) to 0x46 (F),
235234
// and 0x61 (a) to 0x66 (f), all inclusive, append byte
236235
// to output.
237-
else if (
236+
} else if (
238237
byte === 0x25 &&
239238
!/^[0-9A-Fa-f]{2}$/i.test(String.fromCharCode(input[i + 1], input[i + 2]))
240239
) {
241240
output.push(0x25)
242-
}
243241

244242
// 3. Otherwise:
245-
else {
243+
} else {
246244
// 1. Let bytePoint be the two bytes after byte in input,
247245
// decoded, and then interpreted as hexadecimal number.
248246
const nextTwoBytes = String.fromCharCode(input[i + 1], input[i + 2])
@@ -334,7 +332,7 @@ function parseMIMEType (input) {
334332
// whitespace from input given position.
335333
collectASequenceOfCodePoints(
336334
// https://fetch.spec.whatwg.org/#http-whitespace
337-
(char) => /(\u000A|\u000D|\u0009|\u0020)/.test(char),
335+
(char) => /(\u000A|\u000D|\u0009|\u0020)/.test(char), // eslint-disable-line
338336
input,
339337
position
340338
)
@@ -389,10 +387,9 @@ function parseMIMEType (input) {
389387
input,
390388
position
391389
)
392-
}
393390

394391
// 9. Otherwise:
395-
else {
392+
} else {
396393
// 1. Set parameterValue to the result of collecting
397394
// a sequence of code points that are not U+003B (;)
398395
// from input, given position.
@@ -421,7 +418,7 @@ function parseMIMEType (input) {
421418
parameterName.length !== 0 &&
422419
/^[!#$%&'*+-.^_|~A-z0-9]+$/.test(parameterName) &&
423420
// https://mimesniff.spec.whatwg.org/#http-quoted-string-token-code-point
424-
!/^(\u0009|\x{0020}-\x{007E}|\x{0080}-\x{00FF})+$/.test(parameterValue) &&
421+
!/^(\u0009|\x{0020}-\x{007E}|\x{0080}-\x{00FF})+$/.test(parameterValue) && // eslint-disable-line
425422
!mimeType.parameters.has(parameterName)
426423
) {
427424
mimeType.parameters.set(parameterName, parameterValue)
@@ -436,7 +433,7 @@ function parseMIMEType (input) {
436433
/** @param {string} data */
437434
function forgivingBase64 (data) {
438435
// 1. Remove all ASCII whitespace from data.
439-
data = data.replace(/[\u0009\u000A\u000C\u000D\u0020]/g, '')
436+
data = data.replace(/[\u0009\u000A\u000C\u000D\u0020]/g, '') // eslint-disable-line
440437

441438
// 2. If data’s code point length divides by 4 leaving
442439
// no remainder, then:
@@ -529,10 +526,9 @@ function collectAnHTTPQuotedString (input, position, extractValue) {
529526

530527
// 3. Advance position by 1.
531528
position.position++
532-
}
533529

534530
// 6. Otherwise:
535-
else {
531+
} else {
536532
// 1. Assert: quoteOrBackslash is U+0022 (").
537533
assert(quoteOrBackslash === '"')
538534

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

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class File extends Blob {
1313

1414
// 1. Let bytes be the result of processing blob parts given fileBits and
1515
// options.
16+
// TODO
1617

1718
// 2. Let n be the fileName argument to the constructor.
1819
const n = fileName
@@ -42,6 +43,7 @@ class File extends Blob {
4243
// F.name is set to n.
4344
// F.type is set to t.
4445
// F.lastModified is set to d.
46+
// TODO
4547

4648
super(fileBits, { type: t })
4749
this[kState] = {

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ function fetching ({
329329
processResponse,
330330
processResponseEndOfBody,
331331
processResponseConsumeBody,
332-
useParallelQueue = false,
332+
useParallelQueue = false
333333
}) {
334334
// 1. Let taskDestination be null.
335335
let taskDestination = null
@@ -762,16 +762,16 @@ async function schemeFetch (fetchParams) {
762762
switch (scheme) {
763763
case 'about:': {
764764
// If request’s current URL’s path is the string "blank", then return a new response
765-
// whose status message is `OK`, header list is « (`Content-Type`, `text/html;charset=utf-8`) »,
766-
// and body is the empty byte sequence.
765+
// whose status message is `OK`, header list is « (`Content-Type`, `text/html;charset=utf-8`) »,
766+
// and body is the empty byte sequence.
767767
if (path === 'blank') {
768768
const resp = makeResponse({
769769
statusText: 'OK',
770770
headersList: [
771771
'content-type', 'text/html;charset=utf-8'
772772
]
773773
})
774-
774+
775775
resp.urlList = [new URL('about:blank')]
776776
return resp
777777
}
@@ -784,12 +784,12 @@ async function schemeFetch (fetchParams) {
784784

785785
context.on('terminated', onRequestAborted)
786786

787-
// 1. Run these steps, but abort when the ongoing fetch is terminated:
787+
// 1. Run these steps, but abort when the ongoing fetch is terminated:
788788
// 1a. Let blob be request’s current URL’s blob URL entry’s object.
789789
// https://w3c.github.io/FileAPI/#blob-url-entry
790790
// P.S. Thank God this method is available in node.
791791
const currentURL = requestCurrentURL(request)
792-
792+
793793
// https://github.com/web-platform-tests/wpt/blob/7b0ebaccc62b566a1965396e5be7bb2bc06f841f/FileAPI/url/resources/fetch-tests.js#L52-L56
794794
// Buffer.resolveObjectURL does not ignore URL queries.
795795
if (currentURL.search.length !== 0) {
@@ -803,7 +803,7 @@ async function schemeFetch (fetchParams) {
803803
return makeNetworkError('invalid method')
804804
}
805805

806-
// 3a. Let response be a new response whose status message is `OK`.
806+
// 3a. Let response be a new response whose status message is `OK`.
807807
const response = makeResponse({ statusText: 'OK', urlList: [currentURL] })
808808

809809
// 4a. Append (`Content-Length`, blob’s size attribute value) to response’s header list.

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

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const util = require('../core/util')
88
const {
99
isValidHTTPToken,
1010
EnvironmentSettingsObject,
11+
sameOrigin,
1112
toUSVString
1213
} = require('./util')
1314
const {

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,9 @@ function appendRequestOriginHeader (request) {
214214
if (serializedOrigin) {
215215
request.headersList.append('Origin', serializedOrigin)
216216
}
217-
}
218217

219218
// 3. Otherwise, if request’s method is neither `GET` nor `HEAD`, then:
220-
else if (request.method !== 'GET' && request.method !== 'HEAD') {
219+
} else if (request.method !== 'GET' && request.method !== 'HEAD') {
221220
// 1. Switch on request’s referrer policy:
222221
switch (request.referrerPolicy) {
223222
case 'no-referrer':
@@ -307,7 +306,7 @@ function sameOrigin (A, B) {
307306
// 1. If A and B are the same opaque origin, then return true.
308307
// "opaque origin" is an internal value we cannot access, ignore.
309308

310-
// 2. If A and B are both tuple origins and their schemes,
309+
// 2. If A and B are both tuple origins and their schemes,
311310
// hosts, and port are identical, then return true.
312311
if (A.protocol === B.protocol && A.hostname === B.hostname && A.port === B.port) {
313312
return true

deps/undici/src/lib/llhttp/llhttp.wasm

100644100755
File mode changed.

deps/undici/src/lib/llhttp/llhttp.wasm.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deps/undici/src/lib/llhttp/llhttp_simd.wasm

100644100755
File mode changed.

deps/undici/src/lib/llhttp/llhttp_simd.wasm.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deps/undici/src/lib/mock/mock-agent.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,16 @@ const MockPool = require('./mock-pool')
1818
const { matchValue, buildMockOptions } = require('./mock-utils')
1919
const { InvalidArgumentError } = require('../core/errors')
2020
const Dispatcher = require('../dispatcher')
21-
const { WeakRef } = require('../compat/dispatcher-weakref')()
21+
22+
class FakeWeakRef {
23+
constructor (value) {
24+
this.value = value
25+
}
26+
27+
deref () {
28+
return this.value
29+
}
30+
}
2231

2332
class MockAgent extends Dispatcher {
2433
constructor (opts) {
@@ -86,7 +95,7 @@ class MockAgent extends Dispatcher {
8695
}
8796

8897
[kMockAgentSet] (origin, dispatcher) {
89-
this[kClients].set(origin, new WeakRef(dispatcher))
98+
this[kClients].set(origin, new FakeWeakRef(dispatcher))
9099
}
91100

92101
[kFactory] (origin) {

deps/undici/src/lib/mock/mock-interceptor.js

+21-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const {
99
kContentLength,
1010
kMockDispatch
1111
} = require('./mock-symbols')
12-
const { InvalidArgumentError, InvalidReturnValueError } = require('../core/errors')
12+
const { InvalidArgumentError } = require('../core/errors')
1313

1414
/**
1515
* Defines the scope API for a interceptor reply
@@ -66,6 +66,14 @@ class MockInterceptor {
6666
if (typeof opts.method === 'undefined') {
6767
throw new InvalidArgumentError('opts.method must be defined')
6868
}
69+
// See https://github.com/nodejs/undici/issues/1245
70+
// As per RFC 3986, clients are not supposed to send URI
71+
// fragments to servers when they retrieve a document,
72+
if (typeof opts.path === 'string') {
73+
// Matches https://github.com/nodejs/undici/blob/main/lib/fetch/index.js#L1811
74+
const parsedURL = new URL(opts.path, 'data://')
75+
opts.path = parsedURL.pathname + parsedURL.search
76+
}
6977

7078
this[kDispatchKey] = buildKey(opts)
7179
this[kDispatches] = mockDispatches
@@ -74,16 +82,16 @@ class MockInterceptor {
7482
this[kContentLength] = false
7583
}
7684

77-
createMockScopeDispatchData(statusCode, data, responseOptions = {}) {
85+
createMockScopeDispatchData (statusCode, data, responseOptions = {}) {
7886
const responseData = getResponseData(data)
7987
const contentLength = this[kContentLength] ? { 'content-length': responseData.length } : {}
8088
const headers = { ...this[kDefaultHeaders], ...contentLength, ...responseOptions.headers }
8189
const trailers = { ...this[kDefaultTrailers], ...responseOptions.trailers }
8290

83-
return { statusCode, data, headers, trailers };
91+
return { statusCode, data, headers, trailers }
8492
}
8593

86-
validateReplyParameters(statusCode, data, responseOptions) {
94+
validateReplyParameters (statusCode, data, responseOptions) {
8795
if (typeof statusCode === 'undefined') {
8896
throw new InvalidArgumentError('statusCode must be defined')
8997
}
@@ -107,39 +115,38 @@ class MockInterceptor {
107115
// when invoked.
108116
const wrappedDefaultsCallback = (opts) => {
109117
// Our reply options callback contains the parameter for statusCode, data and options.
110-
const resolvedData = replyData(opts);
118+
const resolvedData = replyData(opts)
111119

112120
// Check if it is in the right format
113121
if (typeof resolvedData !== 'object') {
114122
throw new InvalidArgumentError('reply options callback must return an object')
115123
}
116124

117-
const { statusCode, data, responseOptions = {}} = resolvedData;
118-
this.validateReplyParameters(statusCode, data, responseOptions);
125+
const { statusCode, data, responseOptions = {} } = resolvedData
126+
this.validateReplyParameters(statusCode, data, responseOptions)
119127
// Since the values can be obtained immediately we return them
120128
// from this higher order function that will be resolved later.
121-
return {
129+
return {
122130
...this.createMockScopeDispatchData(statusCode, data, responseOptions)
123131
}
124132
}
125133

126134
// Add usual dispatch data, but this time set the data parameter to function that will eventually provide data.
127135
const newMockDispatch = addMockDispatch(this[kDispatches], this[kDispatchKey], wrappedDefaultsCallback)
128-
return new MockScope(newMockDispatch);
136+
return new MockScope(newMockDispatch)
129137
}
130138

131139
// We can have either one or three parameters, if we get here,
132140
// we should have 2-3 parameters. So we spread the arguments of
133141
// this function to obtain the parameters, since replyData will always
134-
// just be the statusCode.
135-
const [statusCode, data, responseOptions = {}] = [...arguments];
136-
this.validateReplyParameters(statusCode, data, responseOptions);
142+
// just be the statusCode.
143+
const [statusCode, data, responseOptions = {}] = [...arguments]
144+
this.validateReplyParameters(statusCode, data, responseOptions)
137145

138146
// Send in-already provided data like usual
139-
const dispatchData = this.createMockScopeDispatchData(statusCode, data, responseOptions);
147+
const dispatchData = this.createMockScopeDispatchData(statusCode, data, responseOptions)
140148
const newMockDispatch = addMockDispatch(this[kDispatches], this[kDispatchKey], dispatchData)
141149
return new MockScope(newMockDispatch)
142-
143150
}
144151

145152
/**

0 commit comments

Comments
 (0)