undici 5.25.1 → 5.25.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/lib/compat/dispatcher-weakref.js +8 -0
- package/lib/core/util.js +19 -19
- package/lib/fetch/body.js +4 -6
- package/lib/fetch/global.js +0 -8
- package/lib/websocket/connection.js +10 -3
- package/lib/websocket/frame.js +9 -2
- package/package.json +2 -2
- package/types/package.json +2 -2
package/README.md
CHANGED
|
@@ -436,6 +436,7 @@ and `undici.Agent`) which will enable the family autoselection algorithm when es
|
|
|
436
436
|
* [__Ethan Arrowood__](https://github.com/ethan-arrowood), <https://www.npmjs.com/~ethan_arrowood>
|
|
437
437
|
* [__Matteo Collina__](https://github.com/mcollina), <https://www.npmjs.com/~matteo.collina>
|
|
438
438
|
* [__Robert Nagy__](https://github.com/ronag), <https://www.npmjs.com/~ronag>
|
|
439
|
+
* [__Matthew Aitken__](https://github.com/KhafraDev), <https://www.npmjs.com/~khaf>
|
|
439
440
|
|
|
440
441
|
## License
|
|
441
442
|
|
|
@@ -31,6 +31,14 @@ class CompatFinalizer {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
module.exports = function () {
|
|
34
|
+
// FIXME: remove workaround when the Node bug is fixed
|
|
35
|
+
// https://github.com/nodejs/node/issues/49344#issuecomment-1741776308
|
|
36
|
+
if (process.env.NODE_V8_COVERAGE) {
|
|
37
|
+
return {
|
|
38
|
+
WeakRef: CompatWeakRef,
|
|
39
|
+
FinalizationRegistry: CompatFinalizer
|
|
40
|
+
}
|
|
41
|
+
}
|
|
34
42
|
return {
|
|
35
43
|
WeakRef: global.WeakRef || CompatWeakRef,
|
|
36
44
|
FinalizationRegistry: global.FinalizationRegistry || CompatFinalizer
|
package/lib/core/util.js
CHANGED
|
@@ -58,31 +58,31 @@ function parseURL (url) {
|
|
|
58
58
|
throw new InvalidArgumentError('Invalid URL: The URL argument must be a non-null object.')
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
if (url.
|
|
62
|
-
throw new InvalidArgumentError('Invalid URL:
|
|
61
|
+
if (!/^https?:/.test(url.origin || url.protocol)) {
|
|
62
|
+
throw new InvalidArgumentError('Invalid URL protocol: the URL must start with `http:` or `https:`.')
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
if (url
|
|
66
|
-
|
|
67
|
-
|
|
65
|
+
if (!(url instanceof URL)) {
|
|
66
|
+
if (url.port != null && url.port !== '' && !Number.isFinite(parseInt(url.port))) {
|
|
67
|
+
throw new InvalidArgumentError('Invalid URL: port must be a valid integer or a string representation of an integer.')
|
|
68
|
+
}
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
if (url.path != null && typeof url.path !== 'string') {
|
|
71
|
+
throw new InvalidArgumentError('Invalid URL path: the path must be a string or null/undefined.')
|
|
72
|
+
}
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
if (url.pathname != null && typeof url.pathname !== 'string') {
|
|
75
|
+
throw new InvalidArgumentError('Invalid URL pathname: the pathname must be a string or null/undefined.')
|
|
76
|
+
}
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
if (url.hostname != null && typeof url.hostname !== 'string') {
|
|
79
|
+
throw new InvalidArgumentError('Invalid URL hostname: the hostname must be a string or null/undefined.')
|
|
80
|
+
}
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
if (url.origin != null && typeof url.origin !== 'string') {
|
|
83
|
+
throw new InvalidArgumentError('Invalid URL origin: the origin must be a string or null/undefined.')
|
|
84
|
+
}
|
|
84
85
|
|
|
85
|
-
if (!(url instanceof URL)) {
|
|
86
86
|
const port = url.port != null
|
|
87
87
|
? url.port
|
|
88
88
|
: (url.protocol === 'https:' ? 443 : 80)
|
|
@@ -168,7 +168,7 @@ function bodyLength (body) {
|
|
|
168
168
|
return 0
|
|
169
169
|
} else if (isStream(body)) {
|
|
170
170
|
const state = body._readableState
|
|
171
|
-
return state && state.ended === true && Number.isFinite(state.length)
|
|
171
|
+
return state && state.objectMode === false && state.ended === true && Number.isFinite(state.length)
|
|
172
172
|
? state.length
|
|
173
173
|
: null
|
|
174
174
|
} else if (isBlobLike(body)) {
|
package/lib/fetch/body.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const Busboy = require('busboy')
|
|
3
|
+
const Busboy = require('@fastify/busboy')
|
|
4
4
|
const util = require('../core/util')
|
|
5
5
|
const {
|
|
6
6
|
ReadableStreamFrom,
|
|
@@ -385,10 +385,9 @@ function bodyMixinMethods (instance) {
|
|
|
385
385
|
let busboy
|
|
386
386
|
|
|
387
387
|
try {
|
|
388
|
-
busboy = Busboy({
|
|
388
|
+
busboy = new Busboy({
|
|
389
389
|
headers,
|
|
390
|
-
preservePath: true
|
|
391
|
-
defParamCharset: 'utf8'
|
|
390
|
+
preservePath: true
|
|
392
391
|
})
|
|
393
392
|
} catch (err) {
|
|
394
393
|
throw new DOMException(`${err}`, 'AbortError')
|
|
@@ -397,8 +396,7 @@ function bodyMixinMethods (instance) {
|
|
|
397
396
|
busboy.on('field', (name, value) => {
|
|
398
397
|
responseFormData.append(name, value)
|
|
399
398
|
})
|
|
400
|
-
busboy.on('file', (name, value,
|
|
401
|
-
const { filename, encoding, mimeType } = info
|
|
399
|
+
busboy.on('file', (name, value, filename, encoding, mimeType) => {
|
|
402
400
|
const chunks = []
|
|
403
401
|
|
|
404
402
|
if (encoding === 'base64' || encoding.toLowerCase() === 'base64') {
|
package/lib/fetch/global.js
CHANGED
|
@@ -9,14 +9,6 @@ function getGlobalOrigin () {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
function setGlobalOrigin (newOrigin) {
|
|
12
|
-
if (
|
|
13
|
-
newOrigin !== undefined &&
|
|
14
|
-
typeof newOrigin !== 'string' &&
|
|
15
|
-
!(newOrigin instanceof URL)
|
|
16
|
-
) {
|
|
17
|
-
throw new Error('Invalid base url')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
12
|
if (newOrigin === undefined) {
|
|
21
13
|
Object.defineProperty(globalThis, globalOrigin, {
|
|
22
14
|
value: undefined,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { randomBytes, createHash } = require('crypto')
|
|
4
3
|
const diagnosticsChannel = require('diagnostics_channel')
|
|
5
4
|
const { uid, states } = require('./constants')
|
|
6
5
|
const {
|
|
@@ -22,6 +21,14 @@ channels.open = diagnosticsChannel.channel('undici:websocket:open')
|
|
|
22
21
|
channels.close = diagnosticsChannel.channel('undici:websocket:close')
|
|
23
22
|
channels.socketError = diagnosticsChannel.channel('undici:websocket:socket_error')
|
|
24
23
|
|
|
24
|
+
/** @type {import('crypto')} */
|
|
25
|
+
let crypto
|
|
26
|
+
try {
|
|
27
|
+
crypto = require('crypto')
|
|
28
|
+
} catch {
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
25
32
|
/**
|
|
26
33
|
* @see https://websockets.spec.whatwg.org/#concept-websocket-establish
|
|
27
34
|
* @param {URL} url
|
|
@@ -66,7 +73,7 @@ function establishWebSocketConnection (url, protocols, ws, onEstablish, options)
|
|
|
66
73
|
// 5. Let keyValue be a nonce consisting of a randomly selected
|
|
67
74
|
// 16-byte value that has been forgiving-base64-encoded and
|
|
68
75
|
// isomorphic encoded.
|
|
69
|
-
const keyValue = randomBytes(16).toString('base64')
|
|
76
|
+
const keyValue = crypto.randomBytes(16).toString('base64')
|
|
70
77
|
|
|
71
78
|
// 6. Append (`Sec-WebSocket-Key`, keyValue) to request’s
|
|
72
79
|
// header list.
|
|
@@ -148,7 +155,7 @@ function establishWebSocketConnection (url, protocols, ws, onEstablish, options)
|
|
|
148
155
|
// trailing whitespace, the client MUST _Fail the WebSocket
|
|
149
156
|
// Connection_.
|
|
150
157
|
const secWSAccept = response.headersList.get('Sec-WebSocket-Accept')
|
|
151
|
-
const digest = createHash('sha1').update(keyValue + uid).digest('base64')
|
|
158
|
+
const digest = crypto.createHash('sha1').update(keyValue + uid).digest('base64')
|
|
152
159
|
if (secWSAccept !== digest) {
|
|
153
160
|
failWebsocketConnection(ws, 'Incorrect hash received in Sec-WebSocket-Accept header.')
|
|
154
161
|
return
|
package/lib/websocket/frame.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const { randomBytes } = require('crypto')
|
|
4
3
|
const { maxUnsigned16Bit } = require('./constants')
|
|
5
4
|
|
|
5
|
+
/** @type {import('crypto')} */
|
|
6
|
+
let crypto
|
|
7
|
+
try {
|
|
8
|
+
crypto = require('crypto')
|
|
9
|
+
} catch {
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
|
|
6
13
|
class WebsocketFrameSend {
|
|
7
14
|
/**
|
|
8
15
|
* @param {Buffer|undefined} data
|
|
9
16
|
*/
|
|
10
17
|
constructor (data) {
|
|
11
18
|
this.frameData = data
|
|
12
|
-
this.maskKey = randomBytes(4)
|
|
19
|
+
this.maskKey = crypto.randomBytes(4)
|
|
13
20
|
}
|
|
14
21
|
|
|
15
22
|
createFrame (opcode) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "undici",
|
|
3
|
-
"version": "5.25.
|
|
3
|
+
"version": "5.25.3",
|
|
4
4
|
"description": "An HTTP/1.1 client, written from scratch for Node.js",
|
|
5
5
|
"homepage": "https://undici.nodejs.org",
|
|
6
6
|
"bugs": {
|
|
@@ -161,6 +161,6 @@
|
|
|
161
161
|
]
|
|
162
162
|
},
|
|
163
163
|
"dependencies": {
|
|
164
|
-
"busboy": "^
|
|
164
|
+
"@fastify/busboy": "^2.0.0"
|
|
165
165
|
}
|
|
166
166
|
}
|
package/types/package.json
CHANGED