Skip to content

Commit

Permalink
deps: update undici to 6.19.0
Browse files Browse the repository at this point in the history
PR-URL: #53468
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
nodejs-github-bot authored and marco-ippolito committed Jul 19, 2024
1 parent 76882d3 commit fde1249
Show file tree
Hide file tree
Showing 16 changed files with 455 additions and 415 deletions.
2 changes: 1 addition & 1 deletion deps/undici/src/docs/docs/api/Client.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Returns: `Client`

> ⚠️ Warning: The `H2` support is experimental.
* **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.
* **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.
* **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.
* **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.
* **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.
Expand Down
4 changes: 2 additions & 2 deletions deps/undici/src/lib/core/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ if (global.FinalizationRegistry && !(process.env.NODE_V8_COVERAGE || process.env
}
}

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

const sessionKey = servername || hostname
const session = sessionCache.get(sessionKey) || null
const session = customSession || sessionCache.get(sessionKey) || null

assert(sessionKey)

Expand Down
7 changes: 4 additions & 3 deletions deps/undici/src/lib/core/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const {
isBlobLike,
buildURL,
validateHandler,
getServerName
getServerName,
normalizedMethodRecords
} = require('./util')
const { channels } = require('./diagnostics.js')
const { headerNameLowerCasedRecord } = require('./constants')
Expand Down Expand Up @@ -51,13 +52,13 @@ class Request {
method !== 'CONNECT'
) {
throw new InvalidArgumentError('path must be an absolute URL or start with a slash')
} else if (invalidPathRegex.exec(path) !== null) {
} else if (invalidPathRegex.test(path)) {
throw new InvalidArgumentError('invalid request path')
}

if (typeof method !== 'string') {
throw new InvalidArgumentError('method must be a string')
} else if (!isValidHTTPToken(method)) {
} else if (normalizedMethodRecords[method] === undefined && !isValidHTTPToken(method)) {
throw new InvalidArgumentError('invalid request method')
}

Expand Down
27 changes: 27 additions & 0 deletions deps/undici/src/lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,31 @@ function errorRequest (client, request, err) {
const kEnumerableProperty = Object.create(null)
kEnumerableProperty.enumerable = true

const normalizedMethodRecordsBase = {
delete: 'DELETE',
DELETE: 'DELETE',
get: 'GET',
GET: 'GET',
head: 'HEAD',
HEAD: 'HEAD',
options: 'OPTIONS',
OPTIONS: 'OPTIONS',
post: 'POST',
POST: 'POST',
put: 'PUT',
PUT: 'PUT'
}

const normalizedMethodRecords = {
...normalizedMethodRecordsBase,
patch: 'patch',
PATCH: 'PATCH'
}

// Note: object prototypes should not be able to be referenced. e.g. `Object#hasOwnProperty`.
Object.setPrototypeOf(normalizedMethodRecordsBase, null)
Object.setPrototypeOf(normalizedMethodRecords, null)

module.exports = {
kEnumerableProperty,
nop,
Expand Down Expand Up @@ -683,6 +708,8 @@ module.exports = {
isValidHeaderValue,
isTokenCharCode,
parseRangeHeader,
normalizedMethodRecordsBase,
normalizedMethodRecords,
isValidPort,
isHttpOrHttpsPrefixed,
nodeMajor,
Expand Down
20 changes: 10 additions & 10 deletions deps/undici/src/lib/dispatcher/client-h1.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,27 +978,27 @@ function writeH1 (client, request) {

/* istanbul ignore else: assertion */
if (!body || bodyLength === 0) {
writeBuffer({ abort, body: null, client, request, socket, contentLength, header, expectsPayload })
writeBuffer(abort, null, client, request, socket, contentLength, header, expectsPayload)
} else if (util.isBuffer(body)) {
writeBuffer({ abort, body, client, request, socket, contentLength, header, expectsPayload })
writeBuffer(abort, body, client, request, socket, contentLength, header, expectsPayload)
} else if (util.isBlobLike(body)) {
if (typeof body.stream === 'function') {
writeIterable({ abort, body: body.stream(), client, request, socket, contentLength, header, expectsPayload })
writeIterable(abort, body.stream(), client, request, socket, contentLength, header, expectsPayload)
} else {
writeBlob({ abort, body, client, request, socket, contentLength, header, expectsPayload })
writeBlob(abort, body, client, request, socket, contentLength, header, expectsPayload)
}
} else if (util.isStream(body)) {
writeStream({ abort, body, client, request, socket, contentLength, header, expectsPayload })
writeStream(abort, body, client, request, socket, contentLength, header, expectsPayload)
} else if (util.isIterable(body)) {
writeIterable({ abort, body, client, request, socket, contentLength, header, expectsPayload })
writeIterable(abort, body, client, request, socket, contentLength, header, expectsPayload)
} else {
assert(false)
}

return true
}

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

let finished = false
Expand Down Expand Up @@ -1101,7 +1101,7 @@ function writeStream ({ abort, body, client, request, socket, contentLength, hea
}
}

function writeBuffer ({ abort, body, client, request, socket, contentLength, header, expectsPayload }) {
function writeBuffer (abort, body, client, request, socket, contentLength, header, expectsPayload) {
try {
if (!body) {
if (contentLength === 0) {
Expand Down Expand Up @@ -1131,7 +1131,7 @@ function writeBuffer ({ abort, body, client, request, socket, contentLength, hea
}
}

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

try {
Expand Down Expand Up @@ -1159,7 +1159,7 @@ async function writeBlob ({ abort, body, client, request, socket, contentLength,
}
}

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

let callback = null
Expand Down
78 changes: 38 additions & 40 deletions deps/undici/src/lib/dispatcher/client-h2.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,82 +477,80 @@ function writeH2 (client, request) {
function writeBodyH2 () {
/* istanbul ignore else: assertion */
if (!body || contentLength === 0) {
writeBuffer({
writeBuffer(
abort,
stream,
null,
client,
request,
client[kSocket],
contentLength,
expectsPayload,
h2stream: stream,
body: null,
socket: client[kSocket]
})
expectsPayload
)
} else if (util.isBuffer(body)) {
writeBuffer({
writeBuffer(
abort,
stream,
body,
client,
request,
client[kSocket],
contentLength,
body,
expectsPayload,
h2stream: stream,
socket: client[kSocket]
})
expectsPayload
)
} else if (util.isBlobLike(body)) {
if (typeof body.stream === 'function') {
writeIterable({
writeIterable(
abort,
stream,
body.stream(),
client,
request,
client[kSocket],
contentLength,
expectsPayload,
h2stream: stream,
body: body.stream(),
socket: client[kSocket]
})
expectsPayload
)
} else {
writeBlob({
writeBlob(
abort,
stream,
body,
client,
request,
client[kSocket],
contentLength,
expectsPayload,
h2stream: stream,
socket: client[kSocket]
})
expectsPayload
)
}
} else if (util.isStream(body)) {
writeStream({
writeStream(
abort,
client[kSocket],
expectsPayload,
stream,
body,
client,
request,
contentLength,
expectsPayload,
socket: client[kSocket],
h2stream: stream,
header: ''
})
contentLength
)
} else if (util.isIterable(body)) {
writeIterable({
writeIterable(
abort,
stream,
body,
client,
request,
client[kSocket],
contentLength,
expectsPayload,
header: '',
h2stream: stream,
socket: client[kSocket]
})
expectsPayload
)
} else {
assert(false)
}
}
}

function writeBuffer ({ abort, h2stream, body, client, request, socket, contentLength, expectsPayload }) {
function writeBuffer (abort, h2stream, body, client, request, socket, contentLength, expectsPayload) {
try {
if (body != null && util.isBuffer(body)) {
assert(contentLength === body.byteLength, 'buffer body must have content length')
Expand All @@ -575,7 +573,7 @@ function writeBuffer ({ abort, h2stream, body, client, request, socket, contentL
}
}

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

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

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

try {
Expand Down Expand Up @@ -634,7 +632,7 @@ async function writeBlob ({ abort, h2stream, body, client, request, socket, cont
}
}

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

let callback = null
Expand Down
4 changes: 2 additions & 2 deletions deps/undici/src/lib/handler/retry-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class RetryHandler {
this.abort(
new RequestRetryError('Content-Range mismatch', statusCode, {
headers,
count: this.retryCount
data: { count: this.retryCount }
})
)
return false
Expand All @@ -213,7 +213,7 @@ class RetryHandler {
this.abort(
new RequestRetryError('ETag mismatch', statusCode, {
headers,
count: this.retryCount
data: { count: this.retryCount }
})
)
return false
Expand Down
16 changes: 9 additions & 7 deletions deps/undici/src/lib/web/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const nodeUtil = require('node:util')
const {
isValidHTTPToken,
sameOrigin,
normalizeMethod,
environmentSettingsObject,
normalizeMethodRecord
environmentSettingsObject
} = require('./util')
const {
forbiddenMethodsSet,
Expand All @@ -24,7 +22,7 @@ const {
requestCache,
requestDuplex
} = require('./constants')
const { kEnumerableProperty } = util
const { kEnumerableProperty, normalizedMethodRecordsBase, normalizedMethodRecords } = util
const { kHeaders, kSignal, kState, kDispatcher } = require('./symbols')
const { webidl } = require('./webidl')
const { URLSerializer } = require('./data-url')
Expand Down Expand Up @@ -349,7 +347,7 @@ class Request {
// 1. Let method be init["method"].
let method = init.method

const mayBeNormalized = normalizeMethodRecord[method]
const mayBeNormalized = normalizedMethodRecords[method]

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

if (forbiddenMethodsSet.has(method.toUpperCase())) {
const upperCase = method.toUpperCase()

if (forbiddenMethodsSet.has(upperCase)) {
throw new TypeError(`'${method}' HTTP method is unsupported.`)
}

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

// 4. Set request’s method to method.
request.method = method
Expand Down
Loading

0 comments on commit fde1249

Please sign in to comment.