Skip to content

Commit b4e49fb

Browse files
nodejs-github-botjuanarbol
authored andcommittedFeb 15, 2023
deps: update undici to 5.16.0
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>
1 parent 90994e6 commit b4e49fb

File tree

11 files changed

+2560
-5531
lines changed

11 files changed

+2560
-5531
lines changed
 

‎deps/undici/src/index.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ const nodeVersion = process.versions.node.split('.')
2424
const nodeMajor = Number(nodeVersion[0])
2525
const nodeMinor = Number(nodeVersion[1])
2626

27+
let hasCrypto
28+
try {
29+
require('crypto')
30+
hasCrypto = true
31+
} catch {
32+
hasCrypto = false
33+
}
34+
2735
Object.assign(Dispatcher.prototype, api)
2836

2937
module.exports.Dispatcher = Dispatcher
@@ -128,7 +136,7 @@ if (nodeMajor >= 16) {
128136
module.exports.setCookie = setCookie
129137
}
130138

131-
if (nodeMajor >= 18) {
139+
if (nodeMajor >= 18 && hasCrypto) {
132140
const { WebSocket } = require('./lib/websocket/websocket')
133141

134142
module.exports.WebSocket = WebSocket

‎deps/undici/src/lib/client.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,7 @@ async function lazyllhttp () {
404404

405405
let llhttpInstance = null
406406
let llhttpPromise = lazyllhttp()
407-
.catch(() => {
408-
})
407+
llhttpPromise.catch()
409408

410409
let currentParser = null
411410
let currentBufferRef = null
@@ -1074,8 +1073,6 @@ async function connect (client) {
10741073

10751074
assert(socket)
10761075

1077-
client[kSocket] = socket
1078-
10791076
socket[kNoRef] = false
10801077
socket[kWriting] = false
10811078
socket[kReset] = false
@@ -1091,6 +1088,8 @@ async function connect (client) {
10911088
.on('end', onSocketEnd)
10921089
.on('close', onSocketClose)
10931090

1091+
client[kSocket] = socket
1092+
10941093
if (channels.connected.hasSubscribers) {
10951094
channels.connected.publish({
10961095
connectParams: {
@@ -1176,7 +1175,7 @@ function _resume (client, sync) {
11761175

11771176
const socket = client[kSocket]
11781177

1179-
if (socket) {
1178+
if (socket && !socket.destroyed) {
11801179
if (client[kSize] === 0) {
11811180
if (!socket[kNoRef] && socket.unref) {
11821181
socket.unref()
@@ -1243,7 +1242,7 @@ function _resume (client, sync) {
12431242

12441243
if (!socket) {
12451244
connect(client)
1246-
continue
1245+
return
12471246
}
12481247

12491248
if (socket.destroyed || socket[kWriting] || socket[kReset] || socket[kBlocking]) {

‎deps/undici/src/lib/core/util.js

+16-1
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,23 @@ function ReadableStreamFrom (iterable) {
354354
)
355355
}
356356

357+
// The chunk should be a FormData instance and contains
358+
// all the required methods.
357359
function isFormDataLike (chunk) {
358-
return chunk && chunk.constructor && chunk.constructor.name === 'FormData'
360+
return (chunk &&
361+
chunk.constructor && chunk.constructor.name === 'FormData' &&
362+
typeof chunk === 'object' &&
363+
(typeof chunk.append === 'function' &&
364+
typeof chunk.delete === 'function' &&
365+
typeof chunk.get === 'function' &&
366+
typeof chunk.getAll === 'function' &&
367+
typeof chunk.has === 'function' &&
368+
typeof chunk.set === 'function' &&
369+
typeof chunk.entries === 'function' &&
370+
typeof chunk.keys === 'function' &&
371+
typeof chunk.values === 'function' &&
372+
typeof chunk.forEach === 'function')
373+
)
359374
}
360375

361376
const kEnumerableProperty = Object.create(null)

‎deps/undici/src/lib/fetch/dataURL.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ const { isValidHTTPToken, isomorphicDecode } = require('./util')
55

66
const encoder = new TextEncoder()
77

8+
// Regex
9+
const HTTP_TOKEN_CODEPOINTS = /^[!#$%&'*+-.^_|~A-z0-9]+$/
10+
const HTTP_WHITESPACE_REGEX = /(\u000A|\u000D|\u0009|\u0020)/ // eslint-disable-line
11+
// https://mimesniff.spec.whatwg.org/#http-quoted-string-token-code-point
12+
const HTTP_QUOTED_STRING_TOKENS = /^(\u0009|\x{0020}-\x{007E}|\x{0080}-\x{00FF})+$/ // eslint-disable-line
13+
814
// https://fetch.spec.whatwg.org/#data-url-processor
915
/** @param {URL} dataURL */
1016
function dataURLProcessor (dataURL) {
@@ -217,7 +223,7 @@ function parseMIMEType (input) {
217223
// 4. If type is the empty string or does not solely
218224
// contain HTTP token code points, then return failure.
219225
// https://mimesniff.spec.whatwg.org/#http-token-code-point
220-
if (type.length === 0 || !/^[!#$%&'*+-.^_|~A-z0-9]+$/.test(type)) {
226+
if (type.length === 0 || !HTTP_TOKEN_CODEPOINTS.test(type)) {
221227
return 'failure'
222228
}
223229

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

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

@@ -258,9 +264,7 @@ function parseMIMEType (input) {
258264
/** @type {Map<string, string>} */
259265
parameters: new Map(),
260266
// https://mimesniff.spec.whatwg.org/#mime-type-essence
261-
get essence () {
262-
return `${this.type}/${this.subtype}`
263-
}
267+
essence: `${type}/${subtype}`
264268
}
265269

266270
// 11. While position is not past the end of input:
@@ -272,7 +276,7 @@ function parseMIMEType (input) {
272276
// whitespace from input given position.
273277
collectASequenceOfCodePoints(
274278
// https://fetch.spec.whatwg.org/#http-whitespace
275-
(char) => /(\u000A|\u000D|\u0009|\u0020)/.test(char), // eslint-disable-line
279+
char => HTTP_WHITESPACE_REGEX.test(char),
276280
input,
277281
position
278282
)
@@ -355,9 +359,8 @@ function parseMIMEType (input) {
355359
// then set mimeType’s parameters[parameterName] to parameterValue.
356360
if (
357361
parameterName.length !== 0 &&
358-
/^[!#$%&'*+-.^_|~A-z0-9]+$/.test(parameterName) &&
359-
// https://mimesniff.spec.whatwg.org/#http-quoted-string-token-code-point
360-
!/^(\u0009|\x{0020}-\x{007E}|\x{0080}-\x{00FF})+$/.test(parameterValue) && // eslint-disable-line
362+
HTTP_TOKEN_CODEPOINTS.test(parameterName) &&
363+
!HTTP_QUOTED_STRING_TOKENS.test(parameterValue) &&
361364
!mimeType.parameters.has(parameterName)
362365
) {
363366
mimeType.parameters.set(parameterName, parameterValue)

‎deps/undici/src/lib/fetch/index.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const { Readable, pipeline } = require('stream')
5656
const { isErrored, isReadable } = require('../core/util')
5757
const { dataURLProcessor, serializeAMimeType } = require('./dataURL')
5858
const { TransformStream } = require('stream/web')
59-
const { getGlobalDispatcher } = require('../../index')
59+
const { getGlobalDispatcher } = require('../global')
6060
const { webidl } = require('./webidl')
6161
const { STATUS_CODES } = require('http')
6262

@@ -1951,8 +1951,6 @@ async function httpNetworkFetch (
19511951
body: fetchParams.controller.dispatcher.isMockActive ? request.body && request.body.source : body,
19521952
headers: request.headersList[kHeadersCaseInsensitive],
19531953
maxRedirections: 0,
1954-
bodyTimeout: 300_000,
1955-
headersTimeout: 300_000,
19561954
upgrade: request.mode === 'websocket' ? 'websocket' : undefined
19571955
},
19581956
{

‎deps/undici/src/lib/proxy-agent.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ProxyAgent extends DispatcherBase {
5353

5454
this[kRequestTls] = opts.requestTls
5555
this[kProxyTls] = opts.proxyTls
56-
this[kProxyHeaders] = {}
56+
this[kProxyHeaders] = opts.headers || {}
5757

5858
if (opts.auth && opts.token) {
5959
throw new InvalidArgumentError('opts.auth cannot be used in combination with opts.token')

‎deps/undici/src/lib/websocket/connection.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict'
22

3-
// TODO: crypto isn't available in all environments
43
const { randomBytes, createHash } = require('crypto')
54
const diagnosticsChannel = require('diagnostics_channel')
65
const { uid, states } = require('./constants')

‎deps/undici/src/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "undici",
3-
"version": "5.15.1",
3+
"version": "5.16.0",
44
"description": "An HTTP/1.1 client, written from scratch for Node.js",
55
"homepage": "https://undici.nodejs.org",
66
"bugs": {
@@ -79,6 +79,7 @@
7979
"cronometro": "^1.0.5",
8080
"delay": "^5.0.0",
8181
"docsify-cli": "^4.4.3",
82+
"form-data": "^4.0.0",
8283
"formdata-node": "^4.3.1",
8384
"https-pem": "^3.0.0",
8485
"husky": "^8.0.1",

‎deps/undici/src/types/proxy-agent.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { IncomingHttpHeaders } from 'http'
2+
13
import Agent from './agent'
24
import buildConnector from './connector';
35
import Dispatcher from './dispatcher'
@@ -19,6 +21,7 @@ declare namespace ProxyAgent {
1921
*/
2022
auth?: string;
2123
token?: string;
24+
headers?: IncomingHttpHeaders;
2225
requestTls?: buildConnector.BuildOptions;
2326
proxyTls?: buildConnector.BuildOptions;
2427
}

0 commit comments

Comments
 (0)
Please sign in to comment.