undici 5.28.4 → 5.29.0
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/lib/cookies/index.js +3 -4
- package/lib/cookies/util.js +9 -26
- package/lib/fetch/body.js +9 -1
- package/lib/fetch/headers.js +4 -0
- package/lib/pool.js +14 -0
- package/package.json +1 -1
package/lib/cookies/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { parseSetCookie } = require('./parse')
|
|
4
|
-
const { stringify
|
|
4
|
+
const { stringify } = require('./util')
|
|
5
5
|
const { webidl } = require('../fetch/webidl')
|
|
6
6
|
const { Headers } = require('../fetch/headers')
|
|
7
7
|
|
|
@@ -77,14 +77,13 @@ function getSetCookies (headers) {
|
|
|
77
77
|
|
|
78
78
|
webidl.brandCheck(headers, Headers, { strict: false })
|
|
79
79
|
|
|
80
|
-
const cookies =
|
|
80
|
+
const cookies = headers.getSetCookie()
|
|
81
81
|
|
|
82
82
|
if (!cookies) {
|
|
83
83
|
return []
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
|
|
87
|
-
return cookies.map((pair) => parseSetCookie(Array.isArray(pair) ? pair[1] : pair))
|
|
86
|
+
return cookies.map((pair) => parseSetCookie(pair))
|
|
88
87
|
}
|
|
89
88
|
|
|
90
89
|
/**
|
package/lib/cookies/util.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
/**
|
|
4
|
+
* @param {string} value
|
|
5
|
+
* @returns {boolean}
|
|
6
|
+
*/
|
|
6
7
|
function isCTLExcludingHtab (value) {
|
|
7
8
|
if (value.length === 0) {
|
|
8
9
|
return false
|
|
@@ -263,29 +264,11 @@ function stringify (cookie) {
|
|
|
263
264
|
return out.join('; ')
|
|
264
265
|
}
|
|
265
266
|
|
|
266
|
-
let kHeadersListNode
|
|
267
|
-
|
|
268
|
-
function getHeadersList (headers) {
|
|
269
|
-
if (headers[kHeadersList]) {
|
|
270
|
-
return headers[kHeadersList]
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
if (!kHeadersListNode) {
|
|
274
|
-
kHeadersListNode = Object.getOwnPropertySymbols(headers).find(
|
|
275
|
-
(symbol) => symbol.description === 'headers list'
|
|
276
|
-
)
|
|
277
|
-
|
|
278
|
-
assert(kHeadersListNode, 'Headers cannot be parsed')
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
const headersList = headers[kHeadersListNode]
|
|
282
|
-
assert(headersList)
|
|
283
|
-
|
|
284
|
-
return headersList
|
|
285
|
-
}
|
|
286
|
-
|
|
287
267
|
module.exports = {
|
|
288
268
|
isCTLExcludingHtab,
|
|
289
|
-
|
|
290
|
-
|
|
269
|
+
validateCookieName,
|
|
270
|
+
validateCookiePath,
|
|
271
|
+
validateCookieValue,
|
|
272
|
+
toIMFDate,
|
|
273
|
+
stringify
|
|
291
274
|
}
|
package/lib/fetch/body.js
CHANGED
|
@@ -22,6 +22,14 @@ const { isUint8Array, isArrayBuffer } = require('util/types')
|
|
|
22
22
|
const { File: UndiciFile } = require('./file')
|
|
23
23
|
const { parseMIMEType, serializeAMimeType } = require('./dataURL')
|
|
24
24
|
|
|
25
|
+
let random
|
|
26
|
+
try {
|
|
27
|
+
const crypto = require('node:crypto')
|
|
28
|
+
random = (max) => crypto.randomInt(0, max)
|
|
29
|
+
} catch {
|
|
30
|
+
random = (max) => Math.floor(Math.random(max))
|
|
31
|
+
}
|
|
32
|
+
|
|
25
33
|
let ReadableStream = globalThis.ReadableStream
|
|
26
34
|
|
|
27
35
|
/** @type {globalThis['File']} */
|
|
@@ -107,7 +115,7 @@ function extractBody (object, keepalive = false) {
|
|
|
107
115
|
// Set source to a copy of the bytes held by object.
|
|
108
116
|
source = new Uint8Array(object.buffer.slice(object.byteOffset, object.byteOffset + object.byteLength))
|
|
109
117
|
} else if (util.isFormDataLike(object)) {
|
|
110
|
-
const boundary = `----formdata-undici-0${`${
|
|
118
|
+
const boundary = `----formdata-undici-0${`${random(1e11)}`.padStart(11, '0')}`
|
|
111
119
|
const prefix = `--${boundary}\r\nContent-Disposition: form-data`
|
|
112
120
|
|
|
113
121
|
/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
|
package/lib/fetch/headers.js
CHANGED
|
@@ -10,6 +10,7 @@ const {
|
|
|
10
10
|
isValidHeaderName,
|
|
11
11
|
isValidHeaderValue
|
|
12
12
|
} = require('./util')
|
|
13
|
+
const util = require('util')
|
|
13
14
|
const { webidl } = require('./webidl')
|
|
14
15
|
const assert = require('assert')
|
|
15
16
|
|
|
@@ -563,6 +564,9 @@ Object.defineProperties(Headers.prototype, {
|
|
|
563
564
|
[Symbol.toStringTag]: {
|
|
564
565
|
value: 'Headers',
|
|
565
566
|
configurable: true
|
|
567
|
+
},
|
|
568
|
+
[util.inspect.custom]: {
|
|
569
|
+
enumerable: false
|
|
566
570
|
}
|
|
567
571
|
})
|
|
568
572
|
|
package/lib/pool.js
CHANGED
|
@@ -73,6 +73,20 @@ class Pool extends PoolBase {
|
|
|
73
73
|
? { ...options.interceptors }
|
|
74
74
|
: undefined
|
|
75
75
|
this[kFactory] = factory
|
|
76
|
+
|
|
77
|
+
this.on('connectionError', (origin, targets, error) => {
|
|
78
|
+
// If a connection error occurs, we remove the client from the pool,
|
|
79
|
+
// and emit a connectionError event. They will not be re-used.
|
|
80
|
+
// Fixes https://github.com/nodejs/undici/issues/3895
|
|
81
|
+
for (const target of targets) {
|
|
82
|
+
// Do not use kRemoveClient here, as it will close the client,
|
|
83
|
+
// but the client cannot be closed in this state.
|
|
84
|
+
const idx = this[kClients].indexOf(target)
|
|
85
|
+
if (idx !== -1) {
|
|
86
|
+
this[kClients].splice(idx, 1)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
})
|
|
76
90
|
}
|
|
77
91
|
|
|
78
92
|
[kGetDispatcher] () {
|