Skip to content

Commit

Permalink
deps: update undici to 4.16.0
Browse files Browse the repository at this point in the history
PR-URL: nodejs#42414
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
nodejs-github-bot authored and xtx1130 committed Apr 25, 2022
1 parent 89a9b97 commit fd1cd7d
Show file tree
Hide file tree
Showing 23 changed files with 124 additions and 77 deletions.
2 changes: 2 additions & 0 deletions deps/undici/src/docs/api/Dispatcher.md
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,8 @@ The `RequestOptions.method` property should not be value `'CONNECT'`.
- `body`
- `bodyUsed`

`body` can not be consumed twice. For example, calling `text()` after `json()` throws `TypeError`.

`body` contains the following additional extensions:

- `dump({ limit: Integer })`, dump the response by reading up to `limit` bytes without killing the socket (optional) - Default: 262144.
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/balanced-pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const kFactory = Symbol('factory')
const kOptions = Symbol('options')

function defaultFactory (origin, opts) {
return new Pool(origin, opts);
return new Pool(origin, opts)
}

class BalancedPool extends PoolBase {
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ class Parser {
return -1
}

/* istanbul ignore if: this can only happen if server is misbehaving */
/* this can only happen if server is misbehaving */
if (upgrade && !request.upgrade) {
util.destroy(socket, new SocketError('bad upgrade', util.getSocketInfo(socket)))
return -1
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/core/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function buildConnector ({ maxCachedSessions, socketPath, timeout, ...opts }) {
let socket
if (protocol === 'https:') {
if (!tls) {
tls = require('tls')
tls = require('tls')
}
servername = servername || options.servername || util.getServerName(host) || null

Expand Down
6 changes: 3 additions & 3 deletions deps/undici/src/lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ function parseHeaders (headers, obj = {}) {
}

function parseRawHeaders (headers) {
return headers.map(header => header.toString());
return headers.map(header => header.toString())
}

function isBuffer (buffer) {
Expand Down Expand Up @@ -263,15 +263,15 @@ function isErrored (body) {
stream.isErrored
? stream.isErrored(body)
: /state: 'errored'/.test(nodeUtil.inspect(body)
)))
)))
}

function isReadable (body) {
return !!(body && (
stream.isReadable
? stream.isReadable(body)
: /state: 'readable'/.test(nodeUtil.inspect(body)
)))
)))
}

function getSocketInfo (socket) {
Expand Down
18 changes: 7 additions & 11 deletions deps/undici/src/lib/fetch/dataURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,22 +227,20 @@ function percentDecode (input) {
// 1. If byte is not 0x25 (%), then append byte to output.
if (byte !== 0x25) {
output.push(byte)
}

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

// 3. Otherwise:
else {
} else {
// 1. Let bytePoint be the two bytes after byte in input,
// decoded, and then interpreted as hexadecimal number.
const nextTwoBytes = String.fromCharCode(input[i + 1], input[i + 2])
Expand Down Expand Up @@ -334,7 +332,7 @@ function parseMIMEType (input) {
// whitespace from input given position.
collectASequenceOfCodePoints(
// https://fetch.spec.whatwg.org/#http-whitespace
(char) => /(\u000A|\u000D|\u0009|\u0020)/.test(char),
(char) => /(\u000A|\u000D|\u0009|\u0020)/.test(char), // eslint-disable-line
input,
position
)
Expand Down Expand Up @@ -389,10 +387,9 @@ function parseMIMEType (input) {
input,
position
)
}

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

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

// 3. Advance position by 1.
position.position++
}

// 6. Otherwise:
else {
} else {
// 1. Assert: quoteOrBackslash is U+0022 (").
assert(quoteOrBackslash === '"')

Expand Down
2 changes: 2 additions & 0 deletions deps/undici/src/lib/fetch/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class File extends Blob {

// 1. Let bytes be the result of processing blob parts given fileBits and
// options.
// TODO

// 2. Let n be the fileName argument to the constructor.
const n = fileName
Expand Down Expand Up @@ -42,6 +43,7 @@ class File extends Blob {
// F.name is set to n.
// F.type is set to t.
// F.lastModified is set to d.
// TODO

super(fileBits, { type: t })
this[kState] = {
Expand Down
14 changes: 7 additions & 7 deletions deps/undici/src/lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ function fetching ({
processResponse,
processResponseEndOfBody,
processResponseConsumeBody,
useParallelQueue = false,
useParallelQueue = false
}) {
// 1. Let taskDestination be null.
let taskDestination = null
Expand Down Expand Up @@ -762,16 +762,16 @@ async function schemeFetch (fetchParams) {
switch (scheme) {
case 'about:': {
// If request’s current URL’s path is the string "blank", then return a new response
// whose status message is `OK`, header list is « (`Content-Type`, `text/html;charset=utf-8`) »,
// and body is the empty byte sequence.
// whose status message is `OK`, header list is « (`Content-Type`, `text/html;charset=utf-8`) »,
// and body is the empty byte sequence.
if (path === 'blank') {
const resp = makeResponse({
statusText: 'OK',
headersList: [
'content-type', 'text/html;charset=utf-8'
]
})

resp.urlList = [new URL('about:blank')]
return resp
}
Expand All @@ -784,12 +784,12 @@ async function schemeFetch (fetchParams) {

context.on('terminated', onRequestAborted)

// 1. Run these steps, but abort when the ongoing fetch is terminated:
// 1. Run these steps, but abort when the ongoing fetch is terminated:
// 1a. Let blob be request’s current URL’s blob URL entry’s object.
// https://w3c.github.io/FileAPI/#blob-url-entry
// P.S. Thank God this method is available in node.
const currentURL = requestCurrentURL(request)

// https://github.com/web-platform-tests/wpt/blob/7b0ebaccc62b566a1965396e5be7bb2bc06f841f/FileAPI/url/resources/fetch-tests.js#L52-L56
// Buffer.resolveObjectURL does not ignore URL queries.
if (currentURL.search.length !== 0) {
Expand All @@ -803,7 +803,7 @@ async function schemeFetch (fetchParams) {
return makeNetworkError('invalid method')
}

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

// 4a. Append (`Content-Length`, blob’s size attribute value) to response’s header list.
Expand Down
1 change: 1 addition & 0 deletions deps/undici/src/lib/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const util = require('../core/util')
const {
isValidHTTPToken,
EnvironmentSettingsObject,
sameOrigin,
toUSVString
} = require('./util')
const {
Expand Down
5 changes: 2 additions & 3 deletions deps/undici/src/lib/fetch/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,9 @@ function appendRequestOriginHeader (request) {
if (serializedOrigin) {
request.headersList.append('Origin', serializedOrigin)
}
}

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

// 2. If A and B are both tuple origins and their schemes,
// 2. If A and B are both tuple origins and their schemes,
// hosts, and port are identical, then return true.
if (A.protocol === B.protocol && A.hostname === B.hostname && A.port === B.port) {
return true
Expand Down
Empty file modified deps/undici/src/lib/llhttp/llhttp.wasm
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion deps/undici/src/lib/llhttp/llhttp.wasm.js

Large diffs are not rendered by default.

Empty file modified deps/undici/src/lib/llhttp/llhttp_simd.wasm
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion deps/undici/src/lib/llhttp/llhttp_simd.wasm.js

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions deps/undici/src/lib/mock/mock-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ const MockPool = require('./mock-pool')
const { matchValue, buildMockOptions } = require('./mock-utils')
const { InvalidArgumentError } = require('../core/errors')
const Dispatcher = require('../dispatcher')
const { WeakRef } = require('../compat/dispatcher-weakref')()

class FakeWeakRef {
constructor (value) {
this.value = value
}

deref () {
return this.value
}
}

class MockAgent extends Dispatcher {
constructor (opts) {
Expand Down Expand Up @@ -86,7 +95,7 @@ class MockAgent extends Dispatcher {
}

[kMockAgentSet] (origin, dispatcher) {
this[kClients].set(origin, new WeakRef(dispatcher))
this[kClients].set(origin, new FakeWeakRef(dispatcher))
}

[kFactory] (origin) {
Expand Down
35 changes: 21 additions & 14 deletions deps/undici/src/lib/mock/mock-interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
kContentLength,
kMockDispatch
} = require('./mock-symbols')
const { InvalidArgumentError, InvalidReturnValueError } = require('../core/errors')
const { InvalidArgumentError } = require('../core/errors')

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

this[kDispatchKey] = buildKey(opts)
this[kDispatches] = mockDispatches
Expand All @@ -74,16 +82,16 @@ class MockInterceptor {
this[kContentLength] = false
}

createMockScopeDispatchData(statusCode, data, responseOptions = {}) {
createMockScopeDispatchData (statusCode, data, responseOptions = {}) {
const responseData = getResponseData(data)
const contentLength = this[kContentLength] ? { 'content-length': responseData.length } : {}
const headers = { ...this[kDefaultHeaders], ...contentLength, ...responseOptions.headers }
const trailers = { ...this[kDefaultTrailers], ...responseOptions.trailers }

return { statusCode, data, headers, trailers };
return { statusCode, data, headers, trailers }
}

validateReplyParameters(statusCode, data, responseOptions) {
validateReplyParameters (statusCode, data, responseOptions) {
if (typeof statusCode === 'undefined') {
throw new InvalidArgumentError('statusCode must be defined')
}
Expand All @@ -107,39 +115,38 @@ class MockInterceptor {
// when invoked.
const wrappedDefaultsCallback = (opts) => {
// Our reply options callback contains the parameter for statusCode, data and options.
const resolvedData = replyData(opts);
const resolvedData = replyData(opts)

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

const { statusCode, data, responseOptions = {}} = resolvedData;
this.validateReplyParameters(statusCode, data, responseOptions);
const { statusCode, data, responseOptions = {} } = resolvedData
this.validateReplyParameters(statusCode, data, responseOptions)
// Since the values can be obtained immediately we return them
// from this higher order function that will be resolved later.
return {
return {
...this.createMockScopeDispatchData(statusCode, data, responseOptions)
}
}

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

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

// Send in-already provided data like usual
const dispatchData = this.createMockScopeDispatchData(statusCode, data, responseOptions);
const dispatchData = this.createMockScopeDispatchData(statusCode, data, responseOptions)
const newMockDispatch = addMockDispatch(this[kDispatches], this[kDispatchKey], dispatchData)
return new MockScope(newMockDispatch)

}

/**
Expand Down
Loading

0 comments on commit fd1cd7d

Please sign in to comment.