undici 6.6.0 → 6.6.1
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/fetch/formdata.js +24 -9
- package/lib/fetch/headers.js +10 -25
- package/lib/fetch/index.js +9 -3
- package/lib/fetch/util.js +62 -60
- package/package.json +2 -2
package/lib/fetch/formdata.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const { isBlobLike, toUSVString, makeIterator } = require('./util')
|
|
4
4
|
const { kState } = require('./symbols')
|
|
5
|
+
const { kEnumerableProperty } = require('../core/util')
|
|
5
6
|
const { File: UndiciFile, FileLike, isFileLike } = require('./file')
|
|
6
7
|
const { webidl } = require('./webidl')
|
|
7
|
-
const {
|
|
8
|
+
const { File: NativeFile } = require('node:buffer')
|
|
8
9
|
|
|
9
10
|
/** @type {globalThis['File']} */
|
|
10
11
|
const File = NativeFile ?? UndiciFile
|
|
@@ -158,9 +159,10 @@ class FormData {
|
|
|
158
159
|
webidl.brandCheck(this, FormData)
|
|
159
160
|
|
|
160
161
|
return makeIterator(
|
|
161
|
-
() => this[kState]
|
|
162
|
+
() => this[kState],
|
|
162
163
|
'FormData',
|
|
163
|
-
'key+value'
|
|
164
|
+
'key+value',
|
|
165
|
+
'name', 'value'
|
|
164
166
|
)
|
|
165
167
|
}
|
|
166
168
|
|
|
@@ -168,9 +170,10 @@ class FormData {
|
|
|
168
170
|
webidl.brandCheck(this, FormData)
|
|
169
171
|
|
|
170
172
|
return makeIterator(
|
|
171
|
-
() => this[kState]
|
|
173
|
+
() => this[kState],
|
|
172
174
|
'FormData',
|
|
173
|
-
'key'
|
|
175
|
+
'key',
|
|
176
|
+
'name', 'value'
|
|
174
177
|
)
|
|
175
178
|
}
|
|
176
179
|
|
|
@@ -178,9 +181,10 @@ class FormData {
|
|
|
178
181
|
webidl.brandCheck(this, FormData)
|
|
179
182
|
|
|
180
183
|
return makeIterator(
|
|
181
|
-
() => this[kState]
|
|
184
|
+
() => this[kState],
|
|
182
185
|
'FormData',
|
|
183
|
-
'value'
|
|
186
|
+
'value',
|
|
187
|
+
'name', 'value'
|
|
184
188
|
)
|
|
185
189
|
}
|
|
186
190
|
|
|
@@ -200,7 +204,7 @@ class FormData {
|
|
|
200
204
|
}
|
|
201
205
|
|
|
202
206
|
for (const [key, value] of this) {
|
|
203
|
-
callbackFn.
|
|
207
|
+
callbackFn.call(thisArg, value, key, this)
|
|
204
208
|
}
|
|
205
209
|
}
|
|
206
210
|
}
|
|
@@ -208,6 +212,17 @@ class FormData {
|
|
|
208
212
|
FormData.prototype[Symbol.iterator] = FormData.prototype.entries
|
|
209
213
|
|
|
210
214
|
Object.defineProperties(FormData.prototype, {
|
|
215
|
+
append: kEnumerableProperty,
|
|
216
|
+
delete: kEnumerableProperty,
|
|
217
|
+
get: kEnumerableProperty,
|
|
218
|
+
getAll: kEnumerableProperty,
|
|
219
|
+
has: kEnumerableProperty,
|
|
220
|
+
set: kEnumerableProperty,
|
|
221
|
+
entries: kEnumerableProperty,
|
|
222
|
+
keys: kEnumerableProperty,
|
|
223
|
+
values: kEnumerableProperty,
|
|
224
|
+
forEach: kEnumerableProperty,
|
|
225
|
+
[Symbol.iterator]: { enumerable: false },
|
|
211
226
|
[Symbol.toStringTag]: {
|
|
212
227
|
value: 'FormData',
|
|
213
228
|
configurable: true
|
|
@@ -225,7 +240,7 @@ function makeEntry (name, value, filename) {
|
|
|
225
240
|
// 1. Set name to the result of converting name into a scalar value string.
|
|
226
241
|
// "To convert a string into a scalar value string, replace any surrogates
|
|
227
242
|
// with U+FFFD."
|
|
228
|
-
// see: https://nodejs.org/dist/latest-
|
|
243
|
+
// see: https://nodejs.org/dist/latest-v20.x/docs/api/buffer.html#buftostringencoding-start-end
|
|
229
244
|
name = Buffer.from(name).toString('utf8')
|
|
230
245
|
|
|
231
246
|
// 2. If value is a string, then set value to the result of converting
|
package/lib/fetch/headers.js
CHANGED
|
@@ -492,48 +492,33 @@ class Headers {
|
|
|
492
492
|
keys () {
|
|
493
493
|
webidl.brandCheck(this, Headers)
|
|
494
494
|
|
|
495
|
-
if (this[kGuard] === 'immutable') {
|
|
496
|
-
const value = this[kHeadersSortedMap]
|
|
497
|
-
return makeIterator(() => value, 'Headers',
|
|
498
|
-
'key')
|
|
499
|
-
}
|
|
500
|
-
|
|
501
495
|
return makeIterator(
|
|
502
|
-
() =>
|
|
496
|
+
() => this[kHeadersSortedMap],
|
|
503
497
|
'Headers',
|
|
504
|
-
'key'
|
|
498
|
+
'key',
|
|
499
|
+
0, 1
|
|
505
500
|
)
|
|
506
501
|
}
|
|
507
502
|
|
|
508
503
|
values () {
|
|
509
504
|
webidl.brandCheck(this, Headers)
|
|
510
505
|
|
|
511
|
-
if (this[kGuard] === 'immutable') {
|
|
512
|
-
const value = this[kHeadersSortedMap]
|
|
513
|
-
return makeIterator(() => value, 'Headers',
|
|
514
|
-
'value')
|
|
515
|
-
}
|
|
516
|
-
|
|
517
506
|
return makeIterator(
|
|
518
|
-
() =>
|
|
507
|
+
() => this[kHeadersSortedMap],
|
|
519
508
|
'Headers',
|
|
520
|
-
'value'
|
|
509
|
+
'value',
|
|
510
|
+
0, 1
|
|
521
511
|
)
|
|
522
512
|
}
|
|
523
513
|
|
|
524
514
|
entries () {
|
|
525
515
|
webidl.brandCheck(this, Headers)
|
|
526
516
|
|
|
527
|
-
if (this[kGuard] === 'immutable') {
|
|
528
|
-
const value = this[kHeadersSortedMap]
|
|
529
|
-
return makeIterator(() => value, 'Headers',
|
|
530
|
-
'key+value')
|
|
531
|
-
}
|
|
532
|
-
|
|
533
517
|
return makeIterator(
|
|
534
|
-
() =>
|
|
518
|
+
() => this[kHeadersSortedMap],
|
|
535
519
|
'Headers',
|
|
536
|
-
'key+value'
|
|
520
|
+
'key+value',
|
|
521
|
+
0, 1
|
|
537
522
|
)
|
|
538
523
|
}
|
|
539
524
|
|
|
@@ -553,7 +538,7 @@ class Headers {
|
|
|
553
538
|
}
|
|
554
539
|
|
|
555
540
|
for (const [key, value] of this) {
|
|
556
|
-
callbackFn.
|
|
541
|
+
callbackFn.call(thisArg, value, key, this)
|
|
557
542
|
}
|
|
558
543
|
}
|
|
559
544
|
|
package/lib/fetch/index.js
CHANGED
|
@@ -1099,10 +1099,10 @@ function fetchFinale (fetchParams, response) {
|
|
|
1099
1099
|
|
|
1100
1100
|
const byteStream = new ReadableStream({
|
|
1101
1101
|
readableStream: transformStream.readable,
|
|
1102
|
-
async
|
|
1102
|
+
async pull (controller) {
|
|
1103
1103
|
const reader = this.readableStream.getReader()
|
|
1104
1104
|
|
|
1105
|
-
while (
|
|
1105
|
+
while (controller.desiredSize >= 0) {
|
|
1106
1106
|
const { done, value } = await reader.read()
|
|
1107
1107
|
|
|
1108
1108
|
if (done) {
|
|
@@ -1113,6 +1113,7 @@ function fetchFinale (fetchParams, response) {
|
|
|
1113
1113
|
controller.enqueue(value)
|
|
1114
1114
|
}
|
|
1115
1115
|
},
|
|
1116
|
+
queuingStrategy: new ByteLengthQueuingStrategy({ highWaterMark: 16384 }),
|
|
1116
1117
|
type: 'bytes'
|
|
1117
1118
|
})
|
|
1118
1119
|
|
|
@@ -1326,6 +1327,9 @@ function httpRedirectFetch (fetchParams, response) {
|
|
|
1326
1327
|
// https://fetch.spec.whatwg.org/#cors-non-wildcard-request-header-name
|
|
1327
1328
|
request.headersList.delete('authorization', true)
|
|
1328
1329
|
|
|
1330
|
+
// https://fetch.spec.whatwg.org/#authentication-entries
|
|
1331
|
+
request.headersList.delete('proxy-authorization', true)
|
|
1332
|
+
|
|
1329
1333
|
// "Cookie" and "Host" are forbidden request-headers, which undici doesn't implement.
|
|
1330
1334
|
request.headersList.delete('cookie', true)
|
|
1331
1335
|
request.headersList.delete('host', true)
|
|
@@ -1924,6 +1928,7 @@ async function httpNetworkFetch (
|
|
|
1924
1928
|
// cancelAlgorithm set to cancelAlgorithm.
|
|
1925
1929
|
const stream = new ReadableStream(
|
|
1926
1930
|
{
|
|
1931
|
+
highWaterMark: 16384,
|
|
1927
1932
|
async start (controller) {
|
|
1928
1933
|
fetchParams.controller.controller = controller
|
|
1929
1934
|
},
|
|
@@ -1933,7 +1938,8 @@ async function httpNetworkFetch (
|
|
|
1933
1938
|
async cancel (reason) {
|
|
1934
1939
|
await cancelAlgorithm(reason)
|
|
1935
1940
|
},
|
|
1936
|
-
type: 'bytes'
|
|
1941
|
+
type: 'bytes',
|
|
1942
|
+
queuingStrategy: new ByteLengthQueuingStrategy({ highWaterMark: 16384 })
|
|
1937
1943
|
}
|
|
1938
1944
|
)
|
|
1939
1945
|
|
package/lib/fetch/util.js
CHANGED
|
@@ -739,19 +739,23 @@ const esIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf([][Symbo
|
|
|
739
739
|
|
|
740
740
|
/**
|
|
741
741
|
* @see https://webidl.spec.whatwg.org/#dfn-iterator-prototype-object
|
|
742
|
-
* @param {() => unknown
|
|
742
|
+
* @param {() => unknown} iterator
|
|
743
743
|
* @param {string} name name of the instance
|
|
744
744
|
* @param {'key'|'value'|'key+value'} kind
|
|
745
|
+
* @param {string | number} [keyIndex]
|
|
746
|
+
* @param {string | number} [valueIndex]
|
|
745
747
|
*/
|
|
746
|
-
function makeIterator (iterator, name, kind) {
|
|
748
|
+
function makeIterator (iterator, name, kind, keyIndex = 0, valueIndex = 1) {
|
|
747
749
|
const object = {
|
|
748
750
|
index: 0,
|
|
749
751
|
kind,
|
|
750
752
|
target: iterator
|
|
751
753
|
}
|
|
754
|
+
// The [[Prototype]] internal slot of an iterator prototype object must be %IteratorPrototype%.
|
|
755
|
+
const iteratorObject = Object.create(esIteratorPrototype)
|
|
752
756
|
|
|
753
|
-
|
|
754
|
-
next () {
|
|
757
|
+
Object.defineProperty(iteratorObject, 'next', {
|
|
758
|
+
value: function next () {
|
|
755
759
|
// 1. Let interface be the interface for which the iterator prototype object exists.
|
|
756
760
|
|
|
757
761
|
// 2. Let thisValue be the this value.
|
|
@@ -763,7 +767,7 @@ function makeIterator (iterator, name, kind) {
|
|
|
763
767
|
|
|
764
768
|
// 5. If object is not a default iterator object for interface,
|
|
765
769
|
// then throw a TypeError.
|
|
766
|
-
if (Object.getPrototypeOf(this) !==
|
|
770
|
+
if (Object.getPrototypeOf(this) !== iteratorObject) {
|
|
767
771
|
throw new TypeError(
|
|
768
772
|
`'next' called on an object that does not implement interface ${name} Iterator.`
|
|
769
773
|
)
|
|
@@ -783,68 +787,66 @@ function makeIterator (iterator, name, kind) {
|
|
|
783
787
|
if (index >= len) {
|
|
784
788
|
return { value: undefined, done: true }
|
|
785
789
|
}
|
|
786
|
-
|
|
787
790
|
// 11. Let pair be the entry in values at index index.
|
|
788
|
-
const
|
|
789
|
-
|
|
791
|
+
const { [keyIndex]: key, [valueIndex]: value } = values[index]
|
|
790
792
|
// 12. Set object’s index to index + 1.
|
|
791
793
|
object.index = index + 1
|
|
792
|
-
|
|
793
794
|
// 13. Return the iterator result for pair and kind.
|
|
794
|
-
|
|
795
|
+
// https://webidl.spec.whatwg.org/#iterator-result
|
|
796
|
+
// 1. Let result be a value determined by the value of kind:
|
|
797
|
+
let result
|
|
798
|
+
switch (kind) {
|
|
799
|
+
case 'key':
|
|
800
|
+
// 1. Let idlKey be pair’s key.
|
|
801
|
+
// 2. Let key be the result of converting idlKey to an
|
|
802
|
+
// ECMAScript value.
|
|
803
|
+
// 3. result is key.
|
|
804
|
+
result = key
|
|
805
|
+
break
|
|
806
|
+
case 'value':
|
|
807
|
+
// 1. Let idlValue be pair’s value.
|
|
808
|
+
// 2. Let value be the result of converting idlValue to
|
|
809
|
+
// an ECMAScript value.
|
|
810
|
+
// 3. result is value.
|
|
811
|
+
result = value
|
|
812
|
+
break
|
|
813
|
+
case 'key+value':
|
|
814
|
+
// 1. Let idlKey be pair’s key.
|
|
815
|
+
// 2. Let idlValue be pair’s value.
|
|
816
|
+
// 3. Let key be the result of converting idlKey to an
|
|
817
|
+
// ECMAScript value.
|
|
818
|
+
// 4. Let value be the result of converting idlValue to
|
|
819
|
+
// an ECMAScript value.
|
|
820
|
+
// 5. Let array be ! ArrayCreate(2).
|
|
821
|
+
// 6. Call ! CreateDataProperty(array, "0", key).
|
|
822
|
+
// 7. Call ! CreateDataProperty(array, "1", value).
|
|
823
|
+
// 8. result is array.
|
|
824
|
+
result = [key, value]
|
|
825
|
+
break
|
|
826
|
+
}
|
|
827
|
+
// 2. Return CreateIterResultObject(result, false).
|
|
828
|
+
return {
|
|
829
|
+
value: result,
|
|
830
|
+
done: false
|
|
831
|
+
}
|
|
795
832
|
},
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
// The [[Prototype]] internal slot of an iterator prototype object must be %IteratorPrototype%.
|
|
802
|
-
Object.setPrototypeOf(i, esIteratorPrototype)
|
|
803
|
-
// esIteratorPrototype needs to be the prototype of i
|
|
804
|
-
// which is the prototype of an empty object. Yes, it's confusing.
|
|
805
|
-
return Object.setPrototypeOf({}, i)
|
|
806
|
-
}
|
|
833
|
+
writable: true,
|
|
834
|
+
enumerable: true,
|
|
835
|
+
configurable: true
|
|
836
|
+
})
|
|
807
837
|
|
|
808
|
-
//
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
// 2. Let key be the result of converting idlKey to an
|
|
817
|
-
// ECMAScript value.
|
|
818
|
-
// 3. result is key.
|
|
819
|
-
result = pair[0]
|
|
820
|
-
break
|
|
821
|
-
}
|
|
822
|
-
case 'value': {
|
|
823
|
-
// 1. Let idlValue be pair’s value.
|
|
824
|
-
// 2. Let value be the result of converting idlValue to
|
|
825
|
-
// an ECMAScript value.
|
|
826
|
-
// 3. result is value.
|
|
827
|
-
result = pair[1]
|
|
828
|
-
break
|
|
829
|
-
}
|
|
830
|
-
case 'key+value': {
|
|
831
|
-
// 1. Let idlKey be pair’s key.
|
|
832
|
-
// 2. Let idlValue be pair’s value.
|
|
833
|
-
// 3. Let key be the result of converting idlKey to an
|
|
834
|
-
// ECMAScript value.
|
|
835
|
-
// 4. Let value be the result of converting idlValue to
|
|
836
|
-
// an ECMAScript value.
|
|
837
|
-
// 5. Let array be ! ArrayCreate(2).
|
|
838
|
-
// 6. Call ! CreateDataProperty(array, "0", key).
|
|
839
|
-
// 7. Call ! CreateDataProperty(array, "1", value).
|
|
840
|
-
// 8. result is array.
|
|
841
|
-
result = pair
|
|
842
|
-
break
|
|
843
|
-
}
|
|
844
|
-
}
|
|
838
|
+
// The class string of an iterator prototype object for a given interface is the
|
|
839
|
+
// result of concatenating the identifier of the interface and the string " Iterator".
|
|
840
|
+
Object.defineProperty(iteratorObject, Symbol.toStringTag, {
|
|
841
|
+
value: `${name} Iterator`,
|
|
842
|
+
writable: false,
|
|
843
|
+
enumerable: false,
|
|
844
|
+
configurable: true
|
|
845
|
+
})
|
|
845
846
|
|
|
846
|
-
//
|
|
847
|
-
|
|
847
|
+
// esIteratorPrototype needs to be the prototype of iteratorObject
|
|
848
|
+
// which is the prototype of an empty object. Yes, it's confusing.
|
|
849
|
+
return Object.create(iteratorObject)
|
|
848
850
|
}
|
|
849
851
|
|
|
850
852
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "undici",
|
|
3
|
-
"version": "6.6.
|
|
3
|
+
"version": "6.6.1",
|
|
4
4
|
"description": "An HTTP/1.1 client, written from scratch for Node.js",
|
|
5
5
|
"homepage": "https://undici.nodejs.org",
|
|
6
6
|
"bugs": {
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"jest": "^29.0.2",
|
|
122
122
|
"jsdom": "^24.0.0",
|
|
123
123
|
"jsfuzz": "^1.0.15",
|
|
124
|
-
"mitata": "^0.1.
|
|
124
|
+
"mitata": "^0.1.8",
|
|
125
125
|
"mocha": "^10.0.0",
|
|
126
126
|
"p-timeout": "^3.2.0",
|
|
127
127
|
"pre-commit": "^1.2.2",
|