Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: update undici to 6.6.0 #51630

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions deps/undici/src/docs/best-practices/client-certificate.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ The server option `rejectUnauthorized: false` allows us to handle any invalid ce
### Client Certificate Authentication

```js
const { readFileSync } = require('fs')
const { join } = require('path')
const { createServer } = require('https')
const { readFileSync } = require('node:fs')
const { join } = require('node:path')
const { createServer } = require('node:https')
const { Client } = require('undici')

const serverOptions = {
Expand Down
12 changes: 5 additions & 7 deletions deps/undici/src/lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Agent extends DispatcherBase {
connect = { ...connect }
}

this[kInterceptors] = options.interceptors && options.interceptors.Agent && Array.isArray(options.interceptors.Agent)
this[kInterceptors] = options.interceptors?.Agent && Array.isArray(options.interceptors.Agent)
? options.interceptors.Agent
: [createRedirectInterceptor({ maxRedirections })]

Expand All @@ -54,22 +54,20 @@ class Agent extends DispatcherBase {
this[kFactory] = factory
this[kClients] = new Map()

const agent = this

this[kOnDrain] = (origin, targets) => {
agent.emit('drain', origin, [agent, ...targets])
this.emit('drain', origin, [this, ...targets])
}

this[kOnConnect] = (origin, targets) => {
agent.emit('connect', origin, [agent, ...targets])
this.emit('connect', origin, [this, ...targets])
}

this[kOnDisconnect] = (origin, targets, err) => {
agent.emit('disconnect', origin, [agent, ...targets], err)
this.emit('disconnect', origin, [this, ...targets], err)
}

this[kOnConnectionError] = (origin, targets, err) => {
agent.emit('connectionError', origin, [agent, ...targets], err)
this.emit('connectionError', origin, [this, ...targets], err)
}
}

Expand Down
4 changes: 2 additions & 2 deletions deps/undici/src/lib/api/api-connect.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const { AsyncResource } = require('async_hooks')
const { AsyncResource } = require('node:async_hooks')
const { InvalidArgumentError, RequestAbortedError, SocketError } = require('../core/errors')
const util = require('../core/util')
const { addSignal, removeSignal } = require('./abort-signal')
Expand Down Expand Up @@ -96,7 +96,7 @@ function connect (opts, callback) {
if (typeof callback !== 'function') {
throw err
}
const opaque = opts && opts.opaque
const opaque = opts?.opaque
queueMicrotask(() => callback(err, { opaque }))
}
}
Expand Down
8 changes: 4 additions & 4 deletions deps/undici/src/lib/api/api-pipeline.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ const {
Readable,
Duplex,
PassThrough
} = require('stream')
} = require('node:stream')
const {
InvalidArgumentError,
InvalidReturnValueError,
RequestAbortedError
} = require('../core/errors')
const util = require('../core/util')
const { AsyncResource } = require('async_hooks')
const { AsyncResource } = require('node:async_hooks')
const { addSignal, removeSignal } = require('./abort-signal')
const assert = require('assert')
const assert = require('node:assert')

const kResume = Symbol('resume')

Expand Down Expand Up @@ -100,7 +100,7 @@ class PipelineHandler extends AsyncResource {
read: () => {
const { body } = this

if (body && body.resume) {
if (body?.resume) {
body.resume()
}
},
Expand Down
4 changes: 2 additions & 2 deletions deps/undici/src/lib/api/api-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const {
} = require('../core/errors')
const util = require('../core/util')
const { getResolveErrorBodyCallback } = require('./util')
const { AsyncResource } = require('async_hooks')
const { AsyncResource } = require('node:async_hooks')
const { addSignal, removeSignal } = require('./abort-signal')

class RequestHandler extends AsyncResource {
Expand Down Expand Up @@ -171,7 +171,7 @@ function request (opts, callback) {
if (typeof callback !== 'function') {
throw err
}
const opaque = opts && opts.opaque
const opaque = opts?.opaque
queueMicrotask(() => callback(err, { opaque }))
}
}
Expand Down
8 changes: 4 additions & 4 deletions deps/undici/src/lib/api/api-stream.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict'

const { finished, PassThrough } = require('stream')
const { finished, PassThrough } = require('node:stream')
const {
InvalidArgumentError,
InvalidReturnValueError,
RequestAbortedError
} = require('../core/errors')
const util = require('../core/util')
const { getResolveErrorBodyCallback } = require('./util')
const { AsyncResource } = require('async_hooks')
const { AsyncResource } = require('node:async_hooks')
const { addSignal, removeSignal } = require('./abort-signal')

class StreamHandler extends AsyncResource {
Expand Down Expand Up @@ -148,7 +148,7 @@ class StreamHandler extends AsyncResource {

const needDrain = res.writableNeedDrain !== undefined
? res.writableNeedDrain
: res._writableState && res._writableState.needDrain
: res._writableState?.needDrain

return needDrain !== true
}
Expand Down Expand Up @@ -212,7 +212,7 @@ function stream (opts, factory, callback) {
if (typeof callback !== 'function') {
throw err
}
const opaque = opts && opts.opaque
const opaque = opts?.opaque
queueMicrotask(() => callback(err, { opaque }))
}
}
Expand Down
6 changes: 3 additions & 3 deletions deps/undici/src/lib/api/api-upgrade.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'

const { InvalidArgumentError, RequestAbortedError, SocketError } = require('../core/errors')
const { AsyncResource } = require('async_hooks')
const { AsyncResource } = require('node:async_hooks')
const util = require('../core/util')
const { addSignal, removeSignal } = require('./abort-signal')
const assert = require('assert')
const assert = require('node:assert')

class UpgradeHandler extends AsyncResource {
constructor (opts, callback) {
Expand Down Expand Up @@ -97,7 +97,7 @@ function upgrade (opts, callback) {
if (typeof callback !== 'function') {
throw err
}
const opaque = opts && opts.opaque
const opaque = opts?.opaque
queueMicrotask(() => callback(err, { opaque }))
}
}
Expand Down
4 changes: 2 additions & 2 deletions deps/undici/src/lib/api/readable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

'use strict'

const assert = require('assert')
const { Readable } = require('stream')
const assert = require('node:assert')
const { Readable } = require('node:stream')
const { RequestAbortedError, NotSupportedError, InvalidArgumentError, AbortError } = require('../core/errors')
const util = require('../core/util')
const { ReadableStreamFrom } = require('../core/util')
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/api/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const assert = require('assert')
const assert = require('node:assert')
const {
ResponseStatusCodeError
} = require('../core/errors')
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 @@ -53,7 +53,7 @@ class BalancedPool extends PoolBase {
throw new InvalidArgumentError('factory must be a function.')
}

this[kInterceptors] = opts.interceptors && opts.interceptors.BalancedPool && Array.isArray(opts.interceptors.BalancedPool)
this[kInterceptors] = opts.interceptors?.BalancedPool && Array.isArray(opts.interceptors.BalancedPool)
? opts.interceptors.BalancedPool
: []
this[kFactory] = factory
Expand Down
14 changes: 4 additions & 10 deletions deps/undici/src/lib/cache/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
const { kConstruct } = require('./symbols')
const { urlEquals, fieldValues: getFieldValues } = require('./util')
const { kEnumerableProperty, isDisturbed } = require('../core/util')
const { kHeadersList } = require('../core/symbols')
const { webidl } = require('../fetch/webidl')
const { Response, cloneResponse } = require('../fetch/response')
const { Response, cloneResponse, fromInnerResponse } = require('../fetch/response')
const { Request, fromInnerRequest } = require('../fetch/request')
const { Headers } = require('../fetch/headers')
const { kState, kHeaders, kGuard } = require('../fetch/symbols')
const { kState } = require('../fetch/symbols')
const { fetching } = require('../fetch/index')
const { urlIsHttpHttpsScheme, createDeferredPromise, readAllBytes } = require('../fetch/util')
const assert = require('assert')
const assert = require('node:assert')
const { getGlobalDispatcher } = require('../global')

/**
Expand Down Expand Up @@ -783,11 +781,7 @@ class Cache {
// 5.5.2
for (const response of responses) {
// 5.5.2.1
const responseObject = new Response(kConstruct)
responseObject[kState] = response
responseObject[kHeaders] = new Headers(kConstruct)
responseObject[kHeaders][kHeadersList] = response.headersList
responseObject[kHeaders][kGuard] = 'immutable'
const responseObject = fromInnerResponse(response, 'immutable', { settingsObject: {} })

responseList.push(responseObject.clone())

Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/cache/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const assert = require('assert')
const assert = require('node:assert')
const { URLSerializer } = require('../fetch/dataURL')
const { isValidHeaderName } = require('../fetch/util')

Expand Down
28 changes: 14 additions & 14 deletions deps/undici/src/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

/* global WebAssembly */

const assert = require('assert')
const net = require('net')
const http = require('http')
const { pipeline } = require('stream')
const assert = require('node:assert')
const net = require('node:net')
const http = require('node:http')
const { pipeline } = require('node:stream')
const util = require('./core/util')
const { channels } = require('./core/diagnostics')
const timers = require('./timers')
Expand Down Expand Up @@ -84,7 +84,7 @@ const {
/** @type {import('http2')} */
let http2
try {
http2 = require('http2')
http2 = require('node:http2')
} catch {
// @ts-ignore
http2 = { constants: {} }
Expand Down Expand Up @@ -250,7 +250,7 @@ class Client extends DispatcherBase {
})
}

this[kInterceptors] = interceptors && interceptors.Client && Array.isArray(interceptors.Client)
this[kInterceptors] = interceptors?.Client && Array.isArray(interceptors.Client)
? interceptors.Client
: [createRedirectInterceptor({ maxRedirections })]
this[kUrl] = util.parseOrigin(url)
Expand Down Expand Up @@ -370,10 +370,10 @@ class Client extends DispatcherBase {
// TODO: for H2 we need to gracefully flush the remaining enqueued
// request and close each stream.
return new Promise((resolve) => {
if (!this[kSize]) {
resolve(null)
} else {
if (this[kSize]) {
this[kClosedResolve] = resolve
} else {
resolve(null)
}
})
}
Expand Down Expand Up @@ -401,10 +401,10 @@ class Client extends DispatcherBase {
this[kHTTP2SessionState] = null
}

if (!this[kSocket]) {
queueMicrotask(callback)
} else {
if (this[kSocket]) {
util.destroy(this[kSocket].on('close', callback), err)
} else {
queueMicrotask(callback)
}

resume(this)
Expand Down Expand Up @@ -479,15 +479,15 @@ async function lazyllhttp () {

let mod
try {
mod = await WebAssembly.compile(Buffer.from(require('./llhttp/llhttp_simd-wasm.js'), 'base64'))
mod = await WebAssembly.compile(require('./llhttp/llhttp_simd-wasm.js'))
} catch (e) {
/* istanbul ignore next */

// We could check if the error was caused by the simd option not
// being enabled, but the occurring of this other error
// * https://github.com/emscripten-core/emscripten/issues/11495
// got me to remove that check to avoid breaking Node 12.
mod = await WebAssembly.compile(Buffer.from(llhttpWasmData || require('./llhttp/llhttp-wasm.js'), 'base64'))
mod = await WebAssembly.compile(llhttpWasmData || require('./llhttp/llhttp-wasm.js'))
}

return await WebAssembly.instantiate(mod, {
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/cookies/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const { maxNameValuePairSize, maxAttributeValueSize } = require('./constants')
const { isCTLExcludingHtab } = require('./util')
const { collectASequenceOfCodePointsFast } = require('../fetch/dataURL')
const assert = require('assert')
const assert = require('node:assert')

/**
* @description Parses the field-value attributes of a set-cookie header string.
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/cookies/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const assert = require('assert')
const assert = require('node:assert')
const { kHeadersList } = require('../core/symbols')

function isCTLExcludingHtab (value) {
Expand Down
6 changes: 3 additions & 3 deletions deps/undici/src/lib/core/connect.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const net = require('net')
const assert = require('assert')
const net = require('node:net')
const assert = require('node:assert')
const util = require('./util')
const { InvalidArgumentError, ConnectTimeoutError } = require('./errors')

Expand Down Expand Up @@ -86,7 +86,7 @@ function buildConnector ({ allowH2, maxCachedSessions, socketPath, timeout, ...o
let socket
if (protocol === 'https:') {
if (!tls) {
tls = require('tls')
tls = require('node:tls')
}
servername = servername || options.servername || util.getServerName(host) || null

Expand Down
4 changes: 2 additions & 2 deletions deps/undici/src/lib/core/diagnostics.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'
const diagnosticsChannel = require('diagnostics_channel')
const util = require('util')
const diagnosticsChannel = require('node:diagnostics_channel')
const util = require('node:util')

const undiciDebugLog = util.debuglog('undici')
const fetchDebuglog = util.debuglog('fetch')
Expand Down
Loading
Loading