undici 6.14.1 → 6.15.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/index-fetch.js +12 -1
- package/lib/handler/retry-handler.js +21 -14
- package/lib/web/cache/cache.js +39 -26
- package/lib/web/cache/cachestorage.js +13 -7
- package/lib/web/cookies/index.js +16 -15
- package/lib/web/eventsource/eventsource.js +7 -6
- package/lib/web/fetch/dispatcher-weakref.js +3 -2
- package/lib/web/fetch/formdata.js +24 -18
- package/lib/web/fetch/headers.js +49 -20
- package/lib/web/fetch/index.js +3 -3
- package/lib/web/fetch/request.js +65 -33
- package/lib/web/fetch/response.js +14 -14
- package/lib/web/fetch/util.js +1 -1
- package/lib/web/fetch/webidl.js +74 -62
- package/lib/web/fileapi/filereader.js +5 -5
- package/lib/web/fileapi/progressevent.js +7 -7
- package/lib/web/websocket/connection.js +1 -1
- package/lib/web/websocket/events.js +48 -26
- package/lib/web/websocket/util.js +6 -5
- package/lib/web/websocket/websocket.js +15 -15
- package/package.json +2 -2
- package/types/webidl.d.ts +7 -8
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { webidl } = require('../fetch/webidl')
|
|
4
4
|
const { kEnumerableProperty } = require('../../core/util')
|
|
5
|
+
const { kConstruct } = require('../../core/symbols')
|
|
5
6
|
const { MessagePort } = require('node:worker_threads')
|
|
6
7
|
|
|
7
8
|
/**
|
|
@@ -11,10 +12,16 @@ class MessageEvent extends Event {
|
|
|
11
12
|
#eventInit
|
|
12
13
|
|
|
13
14
|
constructor (type, eventInitDict = {}) {
|
|
14
|
-
|
|
15
|
+
if (type === kConstruct) {
|
|
16
|
+
super(arguments[1], arguments[2])
|
|
17
|
+
return
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const prefix = 'MessageEvent constructor'
|
|
21
|
+
webidl.argumentLengthCheck(arguments, 1, prefix)
|
|
15
22
|
|
|
16
|
-
type = webidl.converters.DOMString(type)
|
|
17
|
-
eventInitDict = webidl.converters.MessageEventInit(eventInitDict)
|
|
23
|
+
type = webidl.converters.DOMString(type, prefix, 'type')
|
|
24
|
+
eventInitDict = webidl.converters.MessageEventInit(eventInitDict, prefix, 'eventInitDict')
|
|
18
25
|
|
|
19
26
|
super(type, eventInitDict)
|
|
20
27
|
|
|
@@ -67,14 +74,28 @@ class MessageEvent extends Event {
|
|
|
67
74
|
) {
|
|
68
75
|
webidl.brandCheck(this, MessageEvent)
|
|
69
76
|
|
|
70
|
-
webidl.argumentLengthCheck(arguments, 1,
|
|
77
|
+
webidl.argumentLengthCheck(arguments, 1, 'MessageEvent.initMessageEvent')
|
|
71
78
|
|
|
72
79
|
return new MessageEvent(type, {
|
|
73
80
|
bubbles, cancelable, data, origin, lastEventId, source, ports
|
|
74
81
|
})
|
|
75
82
|
}
|
|
83
|
+
|
|
84
|
+
static createFastMessageEvent (type, init) {
|
|
85
|
+
const messageEvent = new MessageEvent(kConstruct, type, init)
|
|
86
|
+
messageEvent.#eventInit = init
|
|
87
|
+
messageEvent.#eventInit.data ??= null
|
|
88
|
+
messageEvent.#eventInit.origin ??= ''
|
|
89
|
+
messageEvent.#eventInit.lastEventId ??= ''
|
|
90
|
+
messageEvent.#eventInit.source ??= null
|
|
91
|
+
messageEvent.#eventInit.ports ??= []
|
|
92
|
+
return messageEvent
|
|
93
|
+
}
|
|
76
94
|
}
|
|
77
95
|
|
|
96
|
+
const { createFastMessageEvent } = MessageEvent
|
|
97
|
+
delete MessageEvent.createFastMessageEvent
|
|
98
|
+
|
|
78
99
|
/**
|
|
79
100
|
* @see https://websockets.spec.whatwg.org/#the-closeevent-interface
|
|
80
101
|
*/
|
|
@@ -82,9 +103,10 @@ class CloseEvent extends Event {
|
|
|
82
103
|
#eventInit
|
|
83
104
|
|
|
84
105
|
constructor (type, eventInitDict = {}) {
|
|
85
|
-
|
|
106
|
+
const prefix = 'CloseEvent constructor'
|
|
107
|
+
webidl.argumentLengthCheck(arguments, 1, prefix)
|
|
86
108
|
|
|
87
|
-
type = webidl.converters.DOMString(type)
|
|
109
|
+
type = webidl.converters.DOMString(type, prefix, 'type')
|
|
88
110
|
eventInitDict = webidl.converters.CloseEventInit(eventInitDict)
|
|
89
111
|
|
|
90
112
|
super(type, eventInitDict)
|
|
@@ -116,11 +138,12 @@ class ErrorEvent extends Event {
|
|
|
116
138
|
#eventInit
|
|
117
139
|
|
|
118
140
|
constructor (type, eventInitDict) {
|
|
119
|
-
|
|
141
|
+
const prefix = 'ErrorEvent constructor'
|
|
142
|
+
webidl.argumentLengthCheck(arguments, 1, prefix)
|
|
120
143
|
|
|
121
144
|
super(type, eventInitDict)
|
|
122
145
|
|
|
123
|
-
type = webidl.converters.DOMString(type)
|
|
146
|
+
type = webidl.converters.DOMString(type, prefix, 'type')
|
|
124
147
|
eventInitDict = webidl.converters.ErrorEventInit(eventInitDict ?? {})
|
|
125
148
|
|
|
126
149
|
this.#eventInit = eventInitDict
|
|
@@ -202,17 +225,17 @@ const eventInit = [
|
|
|
202
225
|
{
|
|
203
226
|
key: 'bubbles',
|
|
204
227
|
converter: webidl.converters.boolean,
|
|
205
|
-
defaultValue: false
|
|
228
|
+
defaultValue: () => false
|
|
206
229
|
},
|
|
207
230
|
{
|
|
208
231
|
key: 'cancelable',
|
|
209
232
|
converter: webidl.converters.boolean,
|
|
210
|
-
defaultValue: false
|
|
233
|
+
defaultValue: () => false
|
|
211
234
|
},
|
|
212
235
|
{
|
|
213
236
|
key: 'composed',
|
|
214
237
|
converter: webidl.converters.boolean,
|
|
215
|
-
defaultValue: false
|
|
238
|
+
defaultValue: () => false
|
|
216
239
|
}
|
|
217
240
|
]
|
|
218
241
|
|
|
@@ -221,31 +244,29 @@ webidl.converters.MessageEventInit = webidl.dictionaryConverter([
|
|
|
221
244
|
{
|
|
222
245
|
key: 'data',
|
|
223
246
|
converter: webidl.converters.any,
|
|
224
|
-
defaultValue: null
|
|
247
|
+
defaultValue: () => null
|
|
225
248
|
},
|
|
226
249
|
{
|
|
227
250
|
key: 'origin',
|
|
228
251
|
converter: webidl.converters.USVString,
|
|
229
|
-
defaultValue: ''
|
|
252
|
+
defaultValue: () => ''
|
|
230
253
|
},
|
|
231
254
|
{
|
|
232
255
|
key: 'lastEventId',
|
|
233
256
|
converter: webidl.converters.DOMString,
|
|
234
|
-
defaultValue: ''
|
|
257
|
+
defaultValue: () => ''
|
|
235
258
|
},
|
|
236
259
|
{
|
|
237
260
|
key: 'source',
|
|
238
261
|
// Node doesn't implement WindowProxy or ServiceWorker, so the only
|
|
239
262
|
// valid value for source is a MessagePort.
|
|
240
263
|
converter: webidl.nullableConverter(webidl.converters.MessagePort),
|
|
241
|
-
defaultValue: null
|
|
264
|
+
defaultValue: () => null
|
|
242
265
|
},
|
|
243
266
|
{
|
|
244
267
|
key: 'ports',
|
|
245
268
|
converter: webidl.converters['sequence<MessagePort>'],
|
|
246
|
-
|
|
247
|
-
return []
|
|
248
|
-
}
|
|
269
|
+
defaultValue: () => new Array(0)
|
|
249
270
|
}
|
|
250
271
|
])
|
|
251
272
|
|
|
@@ -254,17 +275,17 @@ webidl.converters.CloseEventInit = webidl.dictionaryConverter([
|
|
|
254
275
|
{
|
|
255
276
|
key: 'wasClean',
|
|
256
277
|
converter: webidl.converters.boolean,
|
|
257
|
-
defaultValue: false
|
|
278
|
+
defaultValue: () => false
|
|
258
279
|
},
|
|
259
280
|
{
|
|
260
281
|
key: 'code',
|
|
261
282
|
converter: webidl.converters['unsigned short'],
|
|
262
|
-
defaultValue: 0
|
|
283
|
+
defaultValue: () => 0
|
|
263
284
|
},
|
|
264
285
|
{
|
|
265
286
|
key: 'reason',
|
|
266
287
|
converter: webidl.converters.USVString,
|
|
267
|
-
defaultValue: ''
|
|
288
|
+
defaultValue: () => ''
|
|
268
289
|
}
|
|
269
290
|
])
|
|
270
291
|
|
|
@@ -273,22 +294,22 @@ webidl.converters.ErrorEventInit = webidl.dictionaryConverter([
|
|
|
273
294
|
{
|
|
274
295
|
key: 'message',
|
|
275
296
|
converter: webidl.converters.DOMString,
|
|
276
|
-
defaultValue: ''
|
|
297
|
+
defaultValue: () => ''
|
|
277
298
|
},
|
|
278
299
|
{
|
|
279
300
|
key: 'filename',
|
|
280
301
|
converter: webidl.converters.USVString,
|
|
281
|
-
defaultValue: ''
|
|
302
|
+
defaultValue: () => ''
|
|
282
303
|
},
|
|
283
304
|
{
|
|
284
305
|
key: 'lineno',
|
|
285
306
|
converter: webidl.converters['unsigned long'],
|
|
286
|
-
defaultValue: 0
|
|
307
|
+
defaultValue: () => 0
|
|
287
308
|
},
|
|
288
309
|
{
|
|
289
310
|
key: 'colno',
|
|
290
311
|
converter: webidl.converters['unsigned long'],
|
|
291
|
-
defaultValue: 0
|
|
312
|
+
defaultValue: () => 0
|
|
292
313
|
},
|
|
293
314
|
{
|
|
294
315
|
key: 'error',
|
|
@@ -299,5 +320,6 @@ webidl.converters.ErrorEventInit = webidl.dictionaryConverter([
|
|
|
299
320
|
module.exports = {
|
|
300
321
|
MessageEvent,
|
|
301
322
|
CloseEvent,
|
|
302
|
-
ErrorEvent
|
|
323
|
+
ErrorEvent,
|
|
324
|
+
createFastMessageEvent
|
|
303
325
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const { kReadyState, kController, kResponse, kBinaryType, kWebSocketURL } = require('./symbols')
|
|
4
4
|
const { states, opcodes } = require('./constants')
|
|
5
|
-
const {
|
|
5
|
+
const { ErrorEvent, createFastMessageEvent } = require('./events')
|
|
6
6
|
const { isUtf8 } = require('node:buffer')
|
|
7
7
|
|
|
8
8
|
/* globals Blob */
|
|
@@ -51,15 +51,16 @@ function isClosed (ws) {
|
|
|
51
51
|
* @see https://dom.spec.whatwg.org/#concept-event-fire
|
|
52
52
|
* @param {string} e
|
|
53
53
|
* @param {EventTarget} target
|
|
54
|
+
* @param {(...args: ConstructorParameters<typeof Event>) => Event} eventFactory
|
|
54
55
|
* @param {EventInit | undefined} eventInitDict
|
|
55
56
|
*/
|
|
56
|
-
function fireEvent (e, target,
|
|
57
|
+
function fireEvent (e, target, eventFactory = (type, init) => new Event(type, init), eventInitDict = {}) {
|
|
57
58
|
// 1. If eventConstructor is not given, then let eventConstructor be Event.
|
|
58
59
|
|
|
59
60
|
// 2. Let event be the result of creating an event given eventConstructor,
|
|
60
61
|
// in the relevant realm of target.
|
|
61
62
|
// 3. Initialize event’s type attribute to e.
|
|
62
|
-
const event =
|
|
63
|
+
const event = eventFactory(e, eventInitDict)
|
|
63
64
|
|
|
64
65
|
// 4. Initialize any other IDL attributes of event as described in the
|
|
65
66
|
// invocation of this algorithm.
|
|
@@ -110,7 +111,7 @@ function websocketMessageReceived (ws, type, data) {
|
|
|
110
111
|
// 3. Fire an event named message at the WebSocket object, using MessageEvent,
|
|
111
112
|
// with the origin attribute initialized to the serialization of the WebSocket
|
|
112
113
|
// object’s url's origin, and the data attribute initialized to dataForEvent.
|
|
113
|
-
fireEvent('message', ws,
|
|
114
|
+
fireEvent('message', ws, createFastMessageEvent, {
|
|
114
115
|
origin: ws[kWebSocketURL].origin,
|
|
115
116
|
data: dataForEvent
|
|
116
117
|
})
|
|
@@ -195,7 +196,7 @@ function failWebsocketConnection (ws, reason) {
|
|
|
195
196
|
|
|
196
197
|
if (reason) {
|
|
197
198
|
// TODO: process.nextTick
|
|
198
|
-
fireEvent('error', ws, ErrorEvent, {
|
|
199
|
+
fireEvent('error', ws, (type, init) => new ErrorEvent(type, init), {
|
|
199
200
|
error: new Error(reason)
|
|
200
201
|
})
|
|
201
202
|
}
|
|
@@ -51,7 +51,8 @@ class WebSocket extends EventTarget {
|
|
|
51
51
|
constructor (url, protocols = []) {
|
|
52
52
|
super()
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
const prefix = 'WebSocket constructor'
|
|
55
|
+
webidl.argumentLengthCheck(arguments, 1, prefix)
|
|
55
56
|
|
|
56
57
|
if (!experimentalWarned) {
|
|
57
58
|
experimentalWarned = true
|
|
@@ -60,9 +61,9 @@ class WebSocket extends EventTarget {
|
|
|
60
61
|
})
|
|
61
62
|
}
|
|
62
63
|
|
|
63
|
-
const options = webidl.converters['DOMString or sequence<DOMString> or WebSocketInit'](protocols)
|
|
64
|
+
const options = webidl.converters['DOMString or sequence<DOMString> or WebSocketInit'](protocols, prefix, 'options')
|
|
64
65
|
|
|
65
|
-
url = webidl.converters.USVString(url)
|
|
66
|
+
url = webidl.converters.USVString(url, prefix, 'url')
|
|
66
67
|
protocols = options.protocols
|
|
67
68
|
|
|
68
69
|
// 1. Let baseURL be this's relevant settings object's API base URL.
|
|
@@ -159,12 +160,14 @@ class WebSocket extends EventTarget {
|
|
|
159
160
|
close (code = undefined, reason = undefined) {
|
|
160
161
|
webidl.brandCheck(this, WebSocket)
|
|
161
162
|
|
|
163
|
+
const prefix = 'WebSocket.close'
|
|
164
|
+
|
|
162
165
|
if (code !== undefined) {
|
|
163
|
-
code = webidl.converters['unsigned short'](code, { clamp: true })
|
|
166
|
+
code = webidl.converters['unsigned short'](code, prefix, 'code', { clamp: true })
|
|
164
167
|
}
|
|
165
168
|
|
|
166
169
|
if (reason !== undefined) {
|
|
167
|
-
reason = webidl.converters.USVString(reason)
|
|
170
|
+
reason = webidl.converters.USVString(reason, prefix, 'reason')
|
|
168
171
|
}
|
|
169
172
|
|
|
170
173
|
// 1. If code is present, but is neither an integer equal to 1000 nor an
|
|
@@ -264,9 +267,10 @@ class WebSocket extends EventTarget {
|
|
|
264
267
|
send (data) {
|
|
265
268
|
webidl.brandCheck(this, WebSocket)
|
|
266
269
|
|
|
267
|
-
|
|
270
|
+
const prefix = 'WebSocket.send'
|
|
271
|
+
webidl.argumentLengthCheck(arguments, 1, prefix)
|
|
268
272
|
|
|
269
|
-
data = webidl.converters.WebSocketSendData(data)
|
|
273
|
+
data = webidl.converters.WebSocketSendData(data, prefix, 'data')
|
|
270
274
|
|
|
271
275
|
// 1. If this's ready state is CONNECTING, then throw an
|
|
272
276
|
// "InvalidStateError" DOMException.
|
|
@@ -595,12 +599,12 @@ webidl.converters['sequence<DOMString>'] = webidl.sequenceConverter(
|
|
|
595
599
|
webidl.converters.DOMString
|
|
596
600
|
)
|
|
597
601
|
|
|
598
|
-
webidl.converters['DOMString or sequence<DOMString>'] = function (V) {
|
|
602
|
+
webidl.converters['DOMString or sequence<DOMString>'] = function (V, prefix, argument) {
|
|
599
603
|
if (webidl.util.Type(V) === 'Object' && Symbol.iterator in V) {
|
|
600
604
|
return webidl.converters['sequence<DOMString>'](V)
|
|
601
605
|
}
|
|
602
606
|
|
|
603
|
-
return webidl.converters.DOMString(V)
|
|
607
|
+
return webidl.converters.DOMString(V, prefix, argument)
|
|
604
608
|
}
|
|
605
609
|
|
|
606
610
|
// This implements the propsal made in https://github.com/whatwg/websockets/issues/42
|
|
@@ -608,16 +612,12 @@ webidl.converters.WebSocketInit = webidl.dictionaryConverter([
|
|
|
608
612
|
{
|
|
609
613
|
key: 'protocols',
|
|
610
614
|
converter: webidl.converters['DOMString or sequence<DOMString>'],
|
|
611
|
-
|
|
612
|
-
return []
|
|
613
|
-
}
|
|
615
|
+
defaultValue: () => new Array(0)
|
|
614
616
|
},
|
|
615
617
|
{
|
|
616
618
|
key: 'dispatcher',
|
|
617
619
|
converter: (V) => V,
|
|
618
|
-
|
|
619
|
-
return getGlobalDispatcher()
|
|
620
|
-
}
|
|
620
|
+
defaultValue: () => getGlobalDispatcher()
|
|
621
621
|
},
|
|
622
622
|
{
|
|
623
623
|
key: 'headers',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "undici",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.15.0",
|
|
4
4
|
"description": "An HTTP/1.1 client, written from scratch for Node.js",
|
|
5
5
|
"homepage": "https://undici.nodejs.org",
|
|
6
6
|
"bugs": {
|
|
@@ -100,6 +100,7 @@
|
|
|
100
100
|
"prepare": "husky install && node ./scripts/platform-shell.js"
|
|
101
101
|
},
|
|
102
102
|
"devDependencies": {
|
|
103
|
+
"@fastify/busboy": "2.1.1",
|
|
103
104
|
"@matteo.collina/tspl": "^0.1.1",
|
|
104
105
|
"@sinonjs/fake-timers": "^11.1.0",
|
|
105
106
|
"@types/node": "^18.0.3",
|
|
@@ -118,7 +119,6 @@
|
|
|
118
119
|
"node-forge": "^1.3.1",
|
|
119
120
|
"pre-commit": "^1.2.2",
|
|
120
121
|
"proxy": "^2.1.1",
|
|
121
|
-
"sinon": "^17.0.1",
|
|
122
122
|
"snazzy": "^9.0.0",
|
|
123
123
|
"standard": "^17.0.0",
|
|
124
124
|
"tsd": "^0.31.0",
|
package/types/webidl.d.ts
CHANGED
|
@@ -55,7 +55,9 @@ interface WebidlUtil {
|
|
|
55
55
|
V: unknown,
|
|
56
56
|
bitLength: number,
|
|
57
57
|
signedness: 'signed' | 'unsigned',
|
|
58
|
-
opts?: ConvertToIntOpts
|
|
58
|
+
opts?: ConvertToIntOpts,
|
|
59
|
+
prefix: string,
|
|
60
|
+
argument: string
|
|
59
61
|
): number
|
|
60
62
|
|
|
61
63
|
/**
|
|
@@ -73,14 +75,14 @@ interface WebidlConverters {
|
|
|
73
75
|
/**
|
|
74
76
|
* @see https://webidl.spec.whatwg.org/#es-DOMString
|
|
75
77
|
*/
|
|
76
|
-
DOMString (V: unknown, opts?: {
|
|
78
|
+
DOMString (V: unknown, prefix: string, argument: string, opts?: {
|
|
77
79
|
legacyNullToEmptyString: boolean
|
|
78
80
|
}): string
|
|
79
81
|
|
|
80
82
|
/**
|
|
81
83
|
* @see https://webidl.spec.whatwg.org/#es-ByteString
|
|
82
84
|
*/
|
|
83
|
-
ByteString (V: unknown): string
|
|
85
|
+
ByteString (V: unknown, prefix: string, argument: string): string
|
|
84
86
|
|
|
85
87
|
/**
|
|
86
88
|
* @see https://webidl.spec.whatwg.org/#es-USVString
|
|
@@ -204,7 +206,7 @@ export interface Webidl {
|
|
|
204
206
|
*/
|
|
205
207
|
dictionaryConverter (converters: {
|
|
206
208
|
key: string,
|
|
207
|
-
defaultValue?: unknown,
|
|
209
|
+
defaultValue?: () => unknown,
|
|
208
210
|
required?: boolean,
|
|
209
211
|
converter: (...args: unknown[]) => unknown,
|
|
210
212
|
allowedValues?: unknown[]
|
|
@@ -218,8 +220,5 @@ export interface Webidl {
|
|
|
218
220
|
converter: Converter<T>
|
|
219
221
|
): (V: unknown) => ReturnType<typeof converter> | null
|
|
220
222
|
|
|
221
|
-
argumentLengthCheck (args: { length: number }, min: number, context:
|
|
222
|
-
header: string
|
|
223
|
-
message?: string
|
|
224
|
-
}): void
|
|
223
|
+
argumentLengthCheck (args: { length: number }, min: number, context: string): void
|
|
225
224
|
}
|