Skip to content

Commit

Permalink
deps: update undici to 5.16.0
Browse files Browse the repository at this point in the history
PR-URL: #46213
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
nodejs-github-bot authored and juanarbol committed Feb 15, 2023
1 parent 90994e6 commit b4e49fb
Show file tree
Hide file tree
Showing 11 changed files with 2,560 additions and 5,531 deletions.
10 changes: 9 additions & 1 deletion deps/undici/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ const nodeVersion = process.versions.node.split('.')
const nodeMajor = Number(nodeVersion[0])
const nodeMinor = Number(nodeVersion[1])

let hasCrypto
try {
require('crypto')
hasCrypto = true
} catch {
hasCrypto = false
}

Object.assign(Dispatcher.prototype, api)

module.exports.Dispatcher = Dispatcher
Expand Down Expand Up @@ -128,7 +136,7 @@ if (nodeMajor >= 16) {
module.exports.setCookie = setCookie
}

if (nodeMajor >= 18) {
if (nodeMajor >= 18 && hasCrypto) {
const { WebSocket } = require('./lib/websocket/websocket')

module.exports.WebSocket = WebSocket
Expand Down
11 changes: 5 additions & 6 deletions deps/undici/src/lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,7 @@ async function lazyllhttp () {

let llhttpInstance = null
let llhttpPromise = lazyllhttp()
.catch(() => {
})
llhttpPromise.catch()

let currentParser = null
let currentBufferRef = null
Expand Down Expand Up @@ -1074,8 +1073,6 @@ async function connect (client) {

assert(socket)

client[kSocket] = socket

socket[kNoRef] = false
socket[kWriting] = false
socket[kReset] = false
Expand All @@ -1091,6 +1088,8 @@ async function connect (client) {
.on('end', onSocketEnd)
.on('close', onSocketClose)

client[kSocket] = socket

if (channels.connected.hasSubscribers) {
channels.connected.publish({
connectParams: {
Expand Down Expand Up @@ -1176,7 +1175,7 @@ function _resume (client, sync) {

const socket = client[kSocket]

if (socket) {
if (socket && !socket.destroyed) {
if (client[kSize] === 0) {
if (!socket[kNoRef] && socket.unref) {
socket.unref()
Expand Down Expand Up @@ -1243,7 +1242,7 @@ function _resume (client, sync) {

if (!socket) {
connect(client)
continue
return
}

if (socket.destroyed || socket[kWriting] || socket[kReset] || socket[kBlocking]) {
Expand Down
17 changes: 16 additions & 1 deletion deps/undici/src/lib/core/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,23 @@ function ReadableStreamFrom (iterable) {
)
}

// The chunk should be a FormData instance and contains
// all the required methods.
function isFormDataLike (chunk) {
return chunk && chunk.constructor && chunk.constructor.name === 'FormData'
return (chunk &&
chunk.constructor && chunk.constructor.name === 'FormData' &&
typeof chunk === 'object' &&
(typeof chunk.append === 'function' &&
typeof chunk.delete === 'function' &&
typeof chunk.get === 'function' &&
typeof chunk.getAll === 'function' &&
typeof chunk.has === 'function' &&
typeof chunk.set === 'function' &&
typeof chunk.entries === 'function' &&
typeof chunk.keys === 'function' &&
typeof chunk.values === 'function' &&
typeof chunk.forEach === 'function')
)
}

const kEnumerableProperty = Object.create(null)
Expand Down
21 changes: 12 additions & 9 deletions deps/undici/src/lib/fetch/dataURL.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ const { isValidHTTPToken, isomorphicDecode } = require('./util')

const encoder = new TextEncoder()

// Regex
const HTTP_TOKEN_CODEPOINTS = /^[!#$%&'*+-.^_|~A-z0-9]+$/
const HTTP_WHITESPACE_REGEX = /(\u000A|\u000D|\u0009|\u0020)/ // eslint-disable-line
// https://mimesniff.spec.whatwg.org/#http-quoted-string-token-code-point
const HTTP_QUOTED_STRING_TOKENS = /^(\u0009|\x{0020}-\x{007E}|\x{0080}-\x{00FF})+$/ // eslint-disable-line

// https://fetch.spec.whatwg.org/#data-url-processor
/** @param {URL} dataURL */
function dataURLProcessor (dataURL) {
Expand Down Expand Up @@ -217,7 +223,7 @@ function parseMIMEType (input) {
// 4. If type is the empty string or does not solely
// contain HTTP token code points, then return failure.
// https://mimesniff.spec.whatwg.org/#http-token-code-point
if (type.length === 0 || !/^[!#$%&'*+-.^_|~A-z0-9]+$/.test(type)) {
if (type.length === 0 || !HTTP_TOKEN_CODEPOINTS.test(type)) {
return 'failure'
}

Expand All @@ -244,7 +250,7 @@ function parseMIMEType (input) {

// 9. If subtype is the empty string or does not solely
// contain HTTP token code points, then return failure.
if (subtype.length === 0 || !/^[!#$%&'*+-.^_|~A-z0-9]+$/.test(subtype)) {
if (subtype.length === 0 || !HTTP_TOKEN_CODEPOINTS.test(subtype)) {
return 'failure'
}

Expand All @@ -258,9 +264,7 @@ function parseMIMEType (input) {
/** @type {Map<string, string>} */
parameters: new Map(),
// https://mimesniff.spec.whatwg.org/#mime-type-essence
get essence () {
return `${this.type}/${this.subtype}`
}
essence: `${type}/${subtype}`
}

// 11. While position is not past the end of input:
Expand All @@ -272,7 +276,7 @@ function parseMIMEType (input) {
// whitespace from input given position.
collectASequenceOfCodePoints(
// https://fetch.spec.whatwg.org/#http-whitespace
(char) => /(\u000A|\u000D|\u0009|\u0020)/.test(char), // eslint-disable-line
char => HTTP_WHITESPACE_REGEX.test(char),
input,
position
)
Expand Down Expand Up @@ -355,9 +359,8 @@ function parseMIMEType (input) {
// then set mimeType’s parameters[parameterName] to parameterValue.
if (
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) && // eslint-disable-line
HTTP_TOKEN_CODEPOINTS.test(parameterName) &&
!HTTP_QUOTED_STRING_TOKENS.test(parameterValue) &&
!mimeType.parameters.has(parameterName)
) {
mimeType.parameters.set(parameterName, parameterValue)
Expand Down
4 changes: 1 addition & 3 deletions deps/undici/src/lib/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const { Readable, pipeline } = require('stream')
const { isErrored, isReadable } = require('../core/util')
const { dataURLProcessor, serializeAMimeType } = require('./dataURL')
const { TransformStream } = require('stream/web')
const { getGlobalDispatcher } = require('../../index')
const { getGlobalDispatcher } = require('../global')
const { webidl } = require('./webidl')
const { STATUS_CODES } = require('http')

Expand Down Expand Up @@ -1951,8 +1951,6 @@ async function httpNetworkFetch (
body: fetchParams.controller.dispatcher.isMockActive ? request.body && request.body.source : body,
headers: request.headersList[kHeadersCaseInsensitive],
maxRedirections: 0,
bodyTimeout: 300_000,
headersTimeout: 300_000,
upgrade: request.mode === 'websocket' ? 'websocket' : undefined
},
{
Expand Down
2 changes: 1 addition & 1 deletion deps/undici/src/lib/proxy-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ProxyAgent extends DispatcherBase {

this[kRequestTls] = opts.requestTls
this[kProxyTls] = opts.proxyTls
this[kProxyHeaders] = {}
this[kProxyHeaders] = opts.headers || {}

if (opts.auth && opts.token) {
throw new InvalidArgumentError('opts.auth cannot be used in combination with opts.token')
Expand Down
1 change: 0 additions & 1 deletion deps/undici/src/lib/websocket/connection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

// TODO: crypto isn't available in all environments
const { randomBytes, createHash } = require('crypto')
const diagnosticsChannel = require('diagnostics_channel')
const { uid, states } = require('./constants')
Expand Down
3 changes: 2 additions & 1 deletion deps/undici/src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "undici",
"version": "5.15.1",
"version": "5.16.0",
"description": "An HTTP/1.1 client, written from scratch for Node.js",
"homepage": "https://undici.nodejs.org",
"bugs": {
Expand Down Expand Up @@ -79,6 +79,7 @@
"cronometro": "^1.0.5",
"delay": "^5.0.0",
"docsify-cli": "^4.4.3",
"form-data": "^4.0.0",
"formdata-node": "^4.3.1",
"https-pem": "^3.0.0",
"husky": "^8.0.1",
Expand Down
3 changes: 3 additions & 0 deletions deps/undici/src/types/proxy-agent.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { IncomingHttpHeaders } from 'http'

import Agent from './agent'
import buildConnector from './connector';
import Dispatcher from './dispatcher'
Expand All @@ -19,6 +21,7 @@ declare namespace ProxyAgent {
*/
auth?: string;
token?: string;
headers?: IncomingHttpHeaders;
requestTls?: buildConnector.BuildOptions;
proxyTls?: buildConnector.BuildOptions;
}
Expand Down
Loading

0 comments on commit b4e49fb

Please sign in to comment.