Skip to content

Commit

Permalink
deps: update undici to 5.28.2
Browse files Browse the repository at this point in the history
PR-URL: #51024
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Antoine du Hamel <[email protected]>
  • Loading branch information
nodejs-github-bot authored and RafaelGSS committed Dec 15, 2023
1 parent 2b46711 commit 0b61823
Show file tree
Hide file tree
Showing 17 changed files with 231 additions and 284 deletions.
1 change: 1 addition & 0 deletions deps/undici/src/lib/api/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,4 @@ function request (opts, callback) {
}

module.exports = request
module.exports.RequestHandler = RequestHandler
2 changes: 1 addition & 1 deletion deps/undici/src/lib/api/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ module.exports = class BodyReadable extends Readable {
this
.on('close', function () {
signalListenerCleanup()
if (signal?.aborted) {
if (signal && signal.aborted) {
reject(signal.reason || Object.assign(new Error('The operation was aborted'), { name: 'AbortError' }))
} else {
resolve(null)
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/cache/symbols.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict'

module.exports = {
kConstruct: Symbol('constructable')
kConstruct: require('../core/symbols').kConstruct
}
3 changes: 2 additions & 1 deletion deps/undici/src/lib/core/symbols.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ module.exports = {
kHTTP1BuildRequest: Symbol('http1 build request'),
kHTTP2CopyHeaders: Symbol('http2 copy headers'),
kHTTPConnVersion: Symbol('http connection version'),
kRetryHandlerDefaultRetry: Symbol('retry agent default retry')
kRetryHandlerDefaultRetry: Symbol('retry agent default retry'),
kConstruct: Symbol('constructable')
}
13 changes: 5 additions & 8 deletions deps/undici/src/lib/fetch/dataURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,14 @@ function dataURLProcessor (dataURL) {
* @param {boolean} excludeFragment
*/
function URLSerializer (url, excludeFragment = false) {
const href = url.href

if (!excludeFragment) {
return href
return url.href
}

const hash = href.lastIndexOf('#')
if (hash === -1) {
return href
}
return href.slice(0, hash)
const href = url.href
const hashLength = url.hash.length

return hashLength === 0 ? href : href.substring(0, href.length - hashLength)
}

// https://infra.spec.whatwg.org/#collect-a-sequence-of-code-points
Expand Down
5 changes: 4 additions & 1 deletion deps/undici/src/lib/fetch/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

'use strict'

const { kHeadersList } = require('../core/symbols')
const { kHeadersList, kConstruct } = require('../core/symbols')
const { kGuard } = require('./symbols')
const { kEnumerableProperty } = require('../core/util')
const {
Expand Down Expand Up @@ -240,6 +240,9 @@ class HeadersList {
// https://fetch.spec.whatwg.org/#headers-class
class Headers {
constructor (init = undefined) {
if (init === kConstruct) {
return
}
this[kHeadersList] = new HeadersList()

// The new Headers(init) constructor steps are:
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function finalizeAndReportTiming (response, initiatorType = 'other') {
}

// 8. If response’s timing allow passed flag is not set, then:
if (!timingInfo.timingAllowPassed) {
if (!response.timingAllowPassed) {
// 1. Set timingInfo to a the result of creating an opaque timing info for timingInfo.
timingInfo = createOpaqueTimingInfo({
startTime: timingInfo.startTime
Expand Down
13 changes: 6 additions & 7 deletions deps/undici/src/lib/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ const { kHeaders, kSignal, kState, kGuard, kRealm } = require('./symbols')
const { webidl } = require('./webidl')
const { getGlobalOrigin } = require('./global')
const { URLSerializer } = require('./dataURL')
const { kHeadersList } = require('../core/symbols')
const { kHeadersList, kConstruct } = require('../core/symbols')
const assert = require('assert')
const { getMaxListeners, setMaxListeners, getEventListeners, defaultMaxListeners } = require('events')

let TransformStream = globalThis.TransformStream

const kInit = Symbol('init')
const kAbortController = Symbol('abortController')

const requestFinalizer = new FinalizationRegistry(({ signal, abort }) => {
Expand All @@ -45,7 +44,7 @@ const requestFinalizer = new FinalizationRegistry(({ signal, abort }) => {
class Request {
// https://fetch.spec.whatwg.org/#dom-request
constructor (input, init = {}) {
if (input === kInit) {
if (input === kConstruct) {
return
}

Expand Down Expand Up @@ -302,7 +301,7 @@ class Request {
}

// 23. If init["integrity"] exists, then set request’s integrity metadata to it.
if (init.integrity !== undefined && init.integrity != null) {
if (init.integrity != null) {
request.integrity = String(init.integrity)
}

Expand Down Expand Up @@ -398,7 +397,7 @@ class Request {
// 30. Set this’s headers to a new Headers object with this’s relevant
// Realm, whose header list is request’s header list and guard is
// "request".
this[kHeaders] = new Headers()
this[kHeaders] = new Headers(kConstruct)
this[kHeaders][kHeadersList] = request.headersList
this[kHeaders][kGuard] = 'request'
this[kHeaders][kRealm] = this[kRealm]
Expand Down Expand Up @@ -725,10 +724,10 @@ class Request {

// 3. Let clonedRequestObject be the result of creating a Request object,
// given clonedRequest, this’s headers’s guard, and this’s relevant Realm.
const clonedRequestObject = new Request(kInit)
const clonedRequestObject = new Request(kConstruct)
clonedRequestObject[kState] = clonedRequest
clonedRequestObject[kRealm] = this[kRealm]
clonedRequestObject[kHeaders] = new Headers()
clonedRequestObject[kHeaders] = new Headers(kConstruct)
clonedRequestObject[kHeaders][kHeadersList] = clonedRequest.headersList
clonedRequestObject[kHeaders][kGuard] = this[kHeaders][kGuard]
clonedRequestObject[kHeaders][kRealm] = this[kHeaders][kRealm]
Expand Down
10 changes: 3 additions & 7 deletions deps/undici/src/lib/fetch/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const { webidl } = require('./webidl')
const { FormData } = require('./formdata')
const { getGlobalOrigin } = require('./global')
const { URLSerializer } = require('./dataURL')
const { kHeadersList } = require('../core/symbols')
const { kHeadersList, kConstruct } = require('../core/symbols')
const assert = require('assert')
const { types } = require('util')

Expand Down Expand Up @@ -144,7 +144,7 @@ class Response {
// 2. Set this’s headers to a new Headers object with this’s relevant
// Realm, whose header list is this’s response’s header list and guard
// is "response".
this[kHeaders] = new Headers()
this[kHeaders] = new Headers(kConstruct)
this[kHeaders][kGuard] = 'response'
this[kHeaders][kHeadersList] = this[kState].headersList
this[kHeaders][kRealm] = this[kRealm]
Expand Down Expand Up @@ -514,11 +514,7 @@ webidl.converters.XMLHttpRequestBodyInit = function (V) {
return webidl.converters.Blob(V, { strict: false })
}

if (
types.isAnyArrayBuffer(V) ||
types.isTypedArray(V) ||
types.isDataView(V)
) {
if (types.isArrayBuffer(V) || types.isTypedArray(V) || types.isDataView(V)) {
return webidl.converters.BufferSource(V)
}

Expand Down
4 changes: 2 additions & 2 deletions deps/undici/src/lib/handler/RetryHandler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('node:assert')
const assert = require('assert')

const { kRetryHandlerDefaultRetry } = require('../core/symbols')
const { RequestRetryError } = require('../core/errors')
Expand Down Expand Up @@ -95,7 +95,7 @@ class RetryHandler {
}

onBodySent (chunk) {
return this.handler.onBodySent(chunk)
if (this.handler.onBodySent) return this.handler.onBodySent(chunk)
}

static [kRetryHandlerDefaultRetry] (err, { state, opts }, cb) {
Expand Down
10 changes: 6 additions & 4 deletions deps/undici/src/lib/proxy-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,20 @@ class ProxyAgent extends DispatcherBase {
this[kProxyTls] = opts.proxyTls
this[kProxyHeaders] = opts.headers || {}

const resolvedUrl = new URL(opts.uri)
const { origin, port, host, username, password } = resolvedUrl

if (opts.auth && opts.token) {
throw new InvalidArgumentError('opts.auth cannot be used in combination with opts.token')
} else if (opts.auth) {
/* @deprecated in favour of opts.token */
this[kProxyHeaders]['proxy-authorization'] = `Basic ${opts.auth}`
} else if (opts.token) {
this[kProxyHeaders]['proxy-authorization'] = opts.token
} else if (username && password) {
this[kProxyHeaders]['proxy-authorization'] = `Basic ${Buffer.from(`${decodeURIComponent(username)}:${decodeURIComponent(password)}`).toString('base64')}`
}

const resolvedUrl = new URL(opts.uri)
const { origin, port, host } = resolvedUrl

const connect = buildConnector({ ...opts.proxyTls })
this[kConnectEndpoint] = buildConnector({ ...opts.requestTls })
this[kClient] = clientFactory(resolvedUrl, { connect })
Expand All @@ -100,7 +102,7 @@ class ProxyAgent extends DispatcherBase {
})
if (statusCode !== 200) {
socket.on('error', () => {}).destroy()
callback(new RequestAbortedError('Proxy response !== 200 when HTTP Tunneling'))
callback(new RequestAbortedError(`Proxy response (${statusCode}) !== 200 when HTTP Tunneling`))
}
if (opts.protocol !== 'https:') {
callback(null, socket)
Expand Down
Loading

0 comments on commit 0b61823

Please sign in to comment.