undici 6.14.1 → 6.16.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.
@@ -8,11 +8,11 @@ Receives a header object and returns the parsed value.
8
8
 
9
9
  Arguments:
10
10
 
11
- - **headers** `Record<string, string | string[]> | (Buffer | string | (Buffer | string)[])[]` (required) - Header object.
11
+ - **headers** `(Buffer | string | (Buffer | string)[])[]` (required) - Header object.
12
12
 
13
13
  - **obj** `Record<string, string | string[]>` (optional) - Object to specify a proxy object. The parsed value is assigned to this object. But, if **headers** is an object, it is not used.
14
14
 
15
- Returns: `Record<string, string | string[]>` If **headers** is an object, it is **headers**. Otherwise, if **obj** is specified, it is equivalent to **obj**.
15
+ Returns: `Record<string, string | string[]>` If **obj** is specified, it is equivalent to **obj**.
16
16
 
17
17
  ## `headerNameToString(value)`
18
18
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Connecting through a proxy is possible by:
4
4
 
5
- - Using [AgentProxy](../api/ProxyAgent.md).
5
+ - Using [ProxyAgent](../api/ProxyAgent.md).
6
6
  - Configuring `Client` or `Pool` constructor.
7
7
 
8
8
  The proxy url should be passed to the `Client` or `Pool` constructor, while the upstream server url
package/index-fetch.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ const { getGlobalDispatcher, setGlobalDispatcher } = require('./lib/global')
4
+ const EnvHttpProxyAgent = require('./lib/dispatcher/env-http-proxy-agent')
3
5
  const fetchImpl = require('./lib/web/fetch').fetch
4
6
 
5
7
  module.exports.fetch = function fetch (resource, init = undefined) {
@@ -15,7 +17,16 @@ module.exports.Headers = require('./lib/web/fetch/headers').Headers
15
17
  module.exports.Response = require('./lib/web/fetch/response').Response
16
18
  module.exports.Request = require('./lib/web/fetch/request').Request
17
19
 
20
+ const { CloseEvent, ErrorEvent, MessageEvent, createFastMessageEvent } = require('./lib/web/websocket/events')
18
21
  module.exports.WebSocket = require('./lib/web/websocket/websocket').WebSocket
19
- module.exports.MessageEvent = require('./lib/web/websocket/events').MessageEvent
22
+ module.exports.CloseEvent = CloseEvent
23
+ module.exports.ErrorEvent = ErrorEvent
24
+ module.exports.MessageEvent = MessageEvent
25
+ module.exports.createFastMessageEvent = createFastMessageEvent
20
26
 
21
27
  module.exports.EventSource = require('./lib/web/eventsource/eventsource').EventSource
28
+
29
+ // Expose the fetch implementation to be enabled in Node.js core via a flag
30
+ module.exports.EnvHttpProxyAgent = EnvHttpProxyAgent
31
+ module.exports.getGlobalDispatcher = getGlobalDispatcher
32
+ module.exports.setGlobalDispatcher = setGlobalDispatcher
@@ -2,11 +2,10 @@
2
2
 
3
3
  const assert = require('node:assert')
4
4
  const { Readable } = require('./readable')
5
- const { InvalidArgumentError } = require('../core/errors')
5
+ const { InvalidArgumentError, RequestAbortedError } = require('../core/errors')
6
6
  const util = require('../core/util')
7
7
  const { getResolveErrorBodyCallback } = require('./util')
8
8
  const { AsyncResource } = require('node:async_hooks')
9
- const { addSignal, removeSignal } = require('./abort-signal')
10
9
 
11
10
  class RequestHandler extends AsyncResource {
12
11
  constructor (opts, callback) {
@@ -56,6 +55,9 @@ class RequestHandler extends AsyncResource {
56
55
  this.onInfo = onInfo || null
57
56
  this.throwOnError = throwOnError
58
57
  this.highWaterMark = highWaterMark
58
+ this.signal = signal
59
+ this.reason = null
60
+ this.removeAbortListener = null
59
61
 
60
62
  if (util.isStream(body)) {
61
63
  body.on('error', (err) => {
@@ -63,7 +65,26 @@ class RequestHandler extends AsyncResource {
63
65
  })
64
66
  }
65
67
 
66
- addSignal(this, signal)
68
+ if (this.signal) {
69
+ if (this.signal.aborted) {
70
+ this.reason = this.signal.reason ?? new RequestAbortedError()
71
+ } else {
72
+ this.removeAbortListener = util.addAbortListener(this.signal, () => {
73
+ this.reason = this.signal.reason ?? new RequestAbortedError()
74
+ if (this.res) {
75
+ util.destroy(this.res, this.reason)
76
+ } else if (this.abort) {
77
+ this.abort(this.reason)
78
+ }
79
+
80
+ if (this.removeAbortListener) {
81
+ this.res?.off('close', this.removeAbortListener)
82
+ this.removeAbortListener()
83
+ this.removeAbortListener = null
84
+ }
85
+ })
86
+ }
87
+ }
67
88
  }
68
89
 
69
90
  onConnect (abort, context) {
@@ -93,14 +114,18 @@ class RequestHandler extends AsyncResource {
93
114
  const parsedHeaders = responseHeaders === 'raw' ? util.parseHeaders(rawHeaders) : headers
94
115
  const contentType = parsedHeaders['content-type']
95
116
  const contentLength = parsedHeaders['content-length']
96
- const body = new Readable({ resume, abort, contentType, contentLength, highWaterMark })
117
+ const res = new Readable({ resume, abort, contentType, contentLength, highWaterMark })
118
+
119
+ if (this.removeAbortListener) {
120
+ res.on('close', this.removeAbortListener)
121
+ }
97
122
 
98
123
  this.callback = null
99
- this.res = body
124
+ this.res = res
100
125
  if (callback !== null) {
101
126
  if (this.throwOnError && statusCode >= 400) {
102
127
  this.runInAsyncScope(getResolveErrorBodyCallback, null,
103
- { callback, body, contentType, statusCode, statusMessage, headers }
128
+ { callback, body: res, contentType, statusCode, statusMessage, headers }
104
129
  )
105
130
  } else {
106
131
  this.runInAsyncScope(callback, null, null, {
@@ -108,7 +133,7 @@ class RequestHandler extends AsyncResource {
108
133
  headers,
109
134
  trailers: this.trailers,
110
135
  opaque,
111
- body,
136
+ body: res,
112
137
  context
113
138
  })
114
139
  }
@@ -116,25 +141,17 @@ class RequestHandler extends AsyncResource {
116
141
  }
117
142
 
118
143
  onData (chunk) {
119
- const { res } = this
120
- return res.push(chunk)
144
+ return this.res.push(chunk)
121
145
  }
122
146
 
123
147
  onComplete (trailers) {
124
- const { res } = this
125
-
126
- removeSignal(this)
127
-
128
148
  util.parseHeaders(trailers, this.trailers)
129
-
130
- res.push(null)
149
+ this.res.push(null)
131
150
  }
132
151
 
133
152
  onError (err) {
134
153
  const { res, callback, body, opaque } = this
135
154
 
136
- removeSignal(this)
137
-
138
155
  if (callback) {
139
156
  // TODO: Does this need queueMicrotask?
140
157
  this.callback = null
@@ -155,6 +172,12 @@ class RequestHandler extends AsyncResource {
155
172
  this.body = null
156
173
  util.destroy(body, err)
157
174
  }
175
+
176
+ if (this.removeAbortListener) {
177
+ res?.off('close', this.removeAbortListener)
178
+ this.removeAbortListener()
179
+ this.removeAbortListener = null
180
+ }
158
181
  }
159
182
  }
160
183
 
@@ -63,9 +63,13 @@ class BodyReadable extends Readable {
63
63
  // tick as it is created, then a user who is waiting for a
64
64
  // promise (i.e micro tick) for installing a 'error' listener will
65
65
  // never get a chance and will always encounter an unhandled exception.
66
- setImmediate(() => {
66
+ if (!this[kReading]) {
67
+ setImmediate(() => {
68
+ callback(err)
69
+ })
70
+ } else {
67
71
  callback(err)
68
- })
72
+ }
69
73
  }
70
74
 
71
75
  on (ev, ...args) {
@@ -524,6 +524,7 @@ function writeH2 (client, request) {
524
524
  }
525
525
  } else if (util.isStream(body)) {
526
526
  writeStream({
527
+ abort,
527
528
  body,
528
529
  client,
529
530
  request,
@@ -535,6 +536,7 @@ function writeH2 (client, request) {
535
536
  })
536
537
  } else if (util.isIterable(body)) {
537
538
  writeIterable({
539
+ abort,
538
540
  body,
539
541
  client,
540
542
  request,
@@ -7,9 +7,7 @@ const { isDisturbed, parseHeaders, parseRangeHeader } = require('../core/util')
7
7
 
8
8
  function calculateRetryAfterHeader (retryAfter) {
9
9
  const current = Date.now()
10
- const diff = new Date(retryAfter).getTime() - current
11
-
12
- return diff
10
+ return new Date(retryAfter).getTime() - current
13
11
  }
14
12
 
15
13
  class RetryHandler {
@@ -116,11 +114,7 @@ class RetryHandler {
116
114
  const { counter } = state
117
115
 
118
116
  // Any code that is not a Undici's originated and allowed to retry
119
- if (
120
- code &&
121
- code !== 'UND_ERR_REQ_RETRY' &&
122
- !errorCodes.includes(code)
123
- ) {
117
+ if (code && code !== 'UND_ERR_REQ_RETRY' && !errorCodes.includes(code)) {
124
118
  cb(err)
125
119
  return
126
120
  }
@@ -246,10 +240,7 @@ class RetryHandler {
246
240
  start != null && Number.isFinite(start),
247
241
  'content-range mismatch'
248
242
  )
249
- assert(
250
- end != null && Number.isFinite(end),
251
- 'invalid content-length'
252
- )
243
+ assert(end != null && Number.isFinite(end), 'invalid content-length')
253
244
 
254
245
  this.start = start
255
246
  this.end = end
@@ -270,6 +261,13 @@ class RetryHandler {
270
261
  this.resume = resume
271
262
  this.etag = headers.etag != null ? headers.etag : null
272
263
 
264
+ // Weak etags are not useful for comparison nor cache
265
+ // for instance not safe to assume if the response is byte-per-byte
266
+ // equal
267
+ if (this.etag != null && this.etag.startsWith('W/')) {
268
+ this.etag = null
269
+ }
270
+
273
271
  return this.handler.onHeaders(
274
272
  statusCode,
275
273
  rawHeaders,
@@ -308,7 +306,9 @@ class RetryHandler {
308
306
  // and server error response
309
307
  if (this.retryCount - this.retryCountCheckpoint > 0) {
310
308
  // We count the difference between the last checkpoint and the current retry count
311
- this.retryCount = this.retryCountCheckpoint + (this.retryCount - this.retryCountCheckpoint)
309
+ this.retryCount =
310
+ this.retryCountCheckpoint +
311
+ (this.retryCount - this.retryCountCheckpoint)
312
312
  } else {
313
313
  this.retryCount += 1
314
314
  }
@@ -328,11 +328,18 @@ class RetryHandler {
328
328
  }
329
329
 
330
330
  if (this.start !== 0) {
331
+ const headers = { range: `bytes=${this.start}-${this.end ?? ''}` }
332
+
333
+ // Weak etag check - weak etags will make comparison algorithms never match
334
+ if (this.etag != null) {
335
+ headers['if-match'] = this.etag
336
+ }
337
+
331
338
  this.opts = {
332
339
  ...this.opts,
333
340
  headers: {
334
341
  ...this.opts.headers,
335
- range: `bytes=${this.start}-${this.end ?? ''}`
342
+ ...headers
336
343
  }
337
344
  }
338
345
  }
@@ -42,10 +42,12 @@ class Cache {
42
42
 
43
43
  async match (request, options = {}) {
44
44
  webidl.brandCheck(this, Cache)
45
- webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.match' })
46
45
 
47
- request = webidl.converters.RequestInfo(request)
48
- options = webidl.converters.CacheQueryOptions(options)
46
+ const prefix = 'Cache.match'
47
+ webidl.argumentLengthCheck(arguments, 1, prefix)
48
+
49
+ request = webidl.converters.RequestInfo(request, prefix, 'request')
50
+ options = webidl.converters.CacheQueryOptions(options, prefix, 'options')
49
51
 
50
52
  const p = this.#internalMatchAll(request, options, 1)
51
53
 
@@ -59,17 +61,20 @@ class Cache {
59
61
  async matchAll (request = undefined, options = {}) {
60
62
  webidl.brandCheck(this, Cache)
61
63
 
62
- if (request !== undefined) request = webidl.converters.RequestInfo(request)
63
- options = webidl.converters.CacheQueryOptions(options)
64
+ const prefix = 'Cache.matchAll'
65
+ if (request !== undefined) request = webidl.converters.RequestInfo(request, prefix, 'request')
66
+ options = webidl.converters.CacheQueryOptions(options, prefix, 'options')
64
67
 
65
68
  return this.#internalMatchAll(request, options)
66
69
  }
67
70
 
68
71
  async add (request) {
69
72
  webidl.brandCheck(this, Cache)
70
- webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.add' })
71
73
 
72
- request = webidl.converters.RequestInfo(request)
74
+ const prefix = 'Cache.add'
75
+ webidl.argumentLengthCheck(arguments, 1, prefix)
76
+
77
+ request = webidl.converters.RequestInfo(request, prefix, 'request')
73
78
 
74
79
  // 1.
75
80
  const requests = [request]
@@ -83,7 +88,9 @@ class Cache {
83
88
 
84
89
  async addAll (requests) {
85
90
  webidl.brandCheck(this, Cache)
86
- webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.addAll' })
91
+
92
+ const prefix = 'Cache.addAll'
93
+ webidl.argumentLengthCheck(arguments, 1, prefix)
87
94
 
88
95
  // 1.
89
96
  const responsePromises = []
@@ -95,7 +102,7 @@ class Cache {
95
102
  for (let request of requests) {
96
103
  if (request === undefined) {
97
104
  throw webidl.errors.conversionFailed({
98
- prefix: 'Cache.addAll',
105
+ prefix,
99
106
  argument: 'Argument 1',
100
107
  types: ['undefined is not allowed']
101
108
  })
@@ -113,7 +120,7 @@ class Cache {
113
120
  // 3.2
114
121
  if (!urlIsHttpHttpsScheme(r.url) || r.method !== 'GET') {
115
122
  throw webidl.errors.exception({
116
- header: 'Cache.addAll',
123
+ header: prefix,
117
124
  message: 'Expected http/s scheme when method is not GET.'
118
125
  })
119
126
  }
@@ -131,7 +138,7 @@ class Cache {
131
138
  // 5.2
132
139
  if (!urlIsHttpHttpsScheme(r.url)) {
133
140
  throw webidl.errors.exception({
134
- header: 'Cache.addAll',
141
+ header: prefix,
135
142
  message: 'Expected http/s scheme.'
136
143
  })
137
144
  }
@@ -251,10 +258,12 @@ class Cache {
251
258
 
252
259
  async put (request, response) {
253
260
  webidl.brandCheck(this, Cache)
254
- webidl.argumentLengthCheck(arguments, 2, { header: 'Cache.put' })
255
261
 
256
- request = webidl.converters.RequestInfo(request)
257
- response = webidl.converters.Response(response)
262
+ const prefix = 'Cache.put'
263
+ webidl.argumentLengthCheck(arguments, 2, prefix)
264
+
265
+ request = webidl.converters.RequestInfo(request, prefix, 'request')
266
+ response = webidl.converters.Response(response, prefix, 'response')
258
267
 
259
268
  // 1.
260
269
  let innerRequest = null
@@ -269,7 +278,7 @@ class Cache {
269
278
  // 4.
270
279
  if (!urlIsHttpHttpsScheme(innerRequest.url) || innerRequest.method !== 'GET') {
271
280
  throw webidl.errors.exception({
272
- header: 'Cache.put',
281
+ header: prefix,
273
282
  message: 'Expected an http/s scheme when method is not GET'
274
283
  })
275
284
  }
@@ -280,7 +289,7 @@ class Cache {
280
289
  // 6.
281
290
  if (innerResponse.status === 206) {
282
291
  throw webidl.errors.exception({
283
- header: 'Cache.put',
292
+ header: prefix,
284
293
  message: 'Got 206 status'
285
294
  })
286
295
  }
@@ -295,7 +304,7 @@ class Cache {
295
304
  // 7.2.1
296
305
  if (fieldValue === '*') {
297
306
  throw webidl.errors.exception({
298
- header: 'Cache.put',
307
+ header: prefix,
299
308
  message: 'Got * vary field value'
300
309
  })
301
310
  }
@@ -305,7 +314,7 @@ class Cache {
305
314
  // 8.
306
315
  if (innerResponse.body && (isDisturbed(innerResponse.body.stream) || innerResponse.body.stream.locked)) {
307
316
  throw webidl.errors.exception({
308
- header: 'Cache.put',
317
+ header: prefix,
309
318
  message: 'Response body is locked or disturbed'
310
319
  })
311
320
  }
@@ -380,10 +389,12 @@ class Cache {
380
389
 
381
390
  async delete (request, options = {}) {
382
391
  webidl.brandCheck(this, Cache)
383
- webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.delete' })
384
392
 
385
- request = webidl.converters.RequestInfo(request)
386
- options = webidl.converters.CacheQueryOptions(options)
393
+ const prefix = 'Cache.delete'
394
+ webidl.argumentLengthCheck(arguments, 1, prefix)
395
+
396
+ request = webidl.converters.RequestInfo(request, prefix, 'request')
397
+ options = webidl.converters.CacheQueryOptions(options, prefix, 'options')
387
398
 
388
399
  /**
389
400
  * @type {Request}
@@ -445,8 +456,10 @@ class Cache {
445
456
  async keys (request = undefined, options = {}) {
446
457
  webidl.brandCheck(this, Cache)
447
458
 
448
- if (request !== undefined) request = webidl.converters.RequestInfo(request)
449
- options = webidl.converters.CacheQueryOptions(options)
459
+ const prefix = 'Cache.keys'
460
+
461
+ if (request !== undefined) request = webidl.converters.RequestInfo(request, prefix, 'request')
462
+ options = webidl.converters.CacheQueryOptions(options, prefix, 'options')
450
463
 
451
464
  // 1.
452
465
  let r = null
@@ -810,17 +823,17 @@ const cacheQueryOptionConverters = [
810
823
  {
811
824
  key: 'ignoreSearch',
812
825
  converter: webidl.converters.boolean,
813
- defaultValue: false
826
+ defaultValue: () => false
814
827
  },
815
828
  {
816
829
  key: 'ignoreMethod',
817
830
  converter: webidl.converters.boolean,
818
- defaultValue: false
831
+ defaultValue: () => false
819
832
  },
820
833
  {
821
834
  key: 'ignoreVary',
822
835
  converter: webidl.converters.boolean,
823
- defaultValue: false
836
+ defaultValue: () => false
824
837
  }
825
838
  ]
826
839
 
@@ -20,7 +20,7 @@ class CacheStorage {
20
20
 
21
21
  async match (request, options = {}) {
22
22
  webidl.brandCheck(this, CacheStorage)
23
- webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.match' })
23
+ webidl.argumentLengthCheck(arguments, 1, 'CacheStorage.match')
24
24
 
25
25
  request = webidl.converters.RequestInfo(request)
26
26
  options = webidl.converters.MultiCacheQueryOptions(options)
@@ -57,9 +57,11 @@ class CacheStorage {
57
57
  */
58
58
  async has (cacheName) {
59
59
  webidl.brandCheck(this, CacheStorage)
60
- webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.has' })
61
60
 
62
- cacheName = webidl.converters.DOMString(cacheName)
61
+ const prefix = 'CacheStorage.has'
62
+ webidl.argumentLengthCheck(arguments, 1, prefix)
63
+
64
+ cacheName = webidl.converters.DOMString(cacheName, prefix, 'cacheName')
63
65
 
64
66
  // 2.1.1
65
67
  // 2.2
@@ -73,9 +75,11 @@ class CacheStorage {
73
75
  */
74
76
  async open (cacheName) {
75
77
  webidl.brandCheck(this, CacheStorage)
76
- webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.open' })
77
78
 
78
- cacheName = webidl.converters.DOMString(cacheName)
79
+ const prefix = 'CacheStorage.open'
80
+ webidl.argumentLengthCheck(arguments, 1, prefix)
81
+
82
+ cacheName = webidl.converters.DOMString(cacheName, prefix, 'cacheName')
79
83
 
80
84
  // 2.1
81
85
  if (this.#caches.has(cacheName)) {
@@ -105,9 +109,11 @@ class CacheStorage {
105
109
  */
106
110
  async delete (cacheName) {
107
111
  webidl.brandCheck(this, CacheStorage)
108
- webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.delete' })
109
112
 
110
- cacheName = webidl.converters.DOMString(cacheName)
113
+ const prefix = 'CacheStorage.delete'
114
+ webidl.argumentLengthCheck(arguments, 1, prefix)
115
+
116
+ cacheName = webidl.converters.DOMString(cacheName, prefix, 'cacheName')
111
117
 
112
118
  return this.#caches.delete(cacheName)
113
119
  }
@@ -24,7 +24,7 @@ const { Headers } = require('../fetch/headers')
24
24
  * @returns {Record<string, string>}
25
25
  */
26
26
  function getCookies (headers) {
27
- webidl.argumentLengthCheck(arguments, 1, { header: 'getCookies' })
27
+ webidl.argumentLengthCheck(arguments, 1, 'getCookies')
28
28
 
29
29
  webidl.brandCheck(headers, Headers, { strict: false })
30
30
 
@@ -51,11 +51,12 @@ function getCookies (headers) {
51
51
  * @returns {void}
52
52
  */
53
53
  function deleteCookie (headers, name, attributes) {
54
- webidl.argumentLengthCheck(arguments, 2, { header: 'deleteCookie' })
55
-
56
54
  webidl.brandCheck(headers, Headers, { strict: false })
57
55
 
58
- name = webidl.converters.DOMString(name)
56
+ const prefix = 'deleteCookie'
57
+ webidl.argumentLengthCheck(arguments, 2, prefix)
58
+
59
+ name = webidl.converters.DOMString(name, prefix, 'name')
59
60
  attributes = webidl.converters.DeleteCookieAttributes(attributes)
60
61
 
61
62
  // Matches behavior of
@@ -73,7 +74,7 @@ function deleteCookie (headers, name, attributes) {
73
74
  * @returns {Cookie[]}
74
75
  */
75
76
  function getSetCookies (headers) {
76
- webidl.argumentLengthCheck(arguments, 1, { header: 'getSetCookies' })
77
+ webidl.argumentLengthCheck(arguments, 1, 'getSetCookies')
77
78
 
78
79
  webidl.brandCheck(headers, Headers, { strict: false })
79
80
 
@@ -93,7 +94,7 @@ function getSetCookies (headers) {
93
94
  * @returns {void}
94
95
  */
95
96
  function setCookie (headers, cookie) {
96
- webidl.argumentLengthCheck(arguments, 2, { header: 'setCookie' })
97
+ webidl.argumentLengthCheck(arguments, 2, 'setCookie')
97
98
 
98
99
  webidl.brandCheck(headers, Headers, { strict: false })
99
100
 
@@ -110,12 +111,12 @@ webidl.converters.DeleteCookieAttributes = webidl.dictionaryConverter([
110
111
  {
111
112
  converter: webidl.nullableConverter(webidl.converters.DOMString),
112
113
  key: 'path',
113
- defaultValue: null
114
+ defaultValue: () => null
114
115
  },
115
116
  {
116
117
  converter: webidl.nullableConverter(webidl.converters.DOMString),
117
118
  key: 'domain',
118
- defaultValue: null
119
+ defaultValue: () => null
119
120
  }
120
121
  ])
121
122
 
@@ -137,32 +138,32 @@ webidl.converters.Cookie = webidl.dictionaryConverter([
137
138
  return new Date(value)
138
139
  }),
139
140
  key: 'expires',
140
- defaultValue: null
141
+ defaultValue: () => null
141
142
  },
142
143
  {
143
144
  converter: webidl.nullableConverter(webidl.converters['long long']),
144
145
  key: 'maxAge',
145
- defaultValue: null
146
+ defaultValue: () => null
146
147
  },
147
148
  {
148
149
  converter: webidl.nullableConverter(webidl.converters.DOMString),
149
150
  key: 'domain',
150
- defaultValue: null
151
+ defaultValue: () => null
151
152
  },
152
153
  {
153
154
  converter: webidl.nullableConverter(webidl.converters.DOMString),
154
155
  key: 'path',
155
- defaultValue: null
156
+ defaultValue: () => null
156
157
  },
157
158
  {
158
159
  converter: webidl.nullableConverter(webidl.converters.boolean),
159
160
  key: 'secure',
160
- defaultValue: null
161
+ defaultValue: () => null
161
162
  },
162
163
  {
163
164
  converter: webidl.nullableConverter(webidl.converters.boolean),
164
165
  key: 'httpOnly',
165
- defaultValue: null
166
+ defaultValue: () => null
166
167
  },
167
168
  {
168
169
  converter: webidl.converters.USVString,
@@ -172,7 +173,7 @@ webidl.converters.Cookie = webidl.dictionaryConverter([
172
173
  {
173
174
  converter: webidl.sequenceConverter(webidl.converters.DOMString),
174
175
  key: 'unparsed',
175
- defaultValue: []
176
+ defaultValue: () => new Array(0)
176
177
  }
177
178
  ])
178
179
 
@@ -6,7 +6,7 @@ const { makeRequest } = require('../fetch/request')
6
6
  const { webidl } = require('../fetch/webidl')
7
7
  const { EventSourceStream } = require('./eventsource-stream')
8
8
  const { parseMIMEType } = require('../fetch/data-url')
9
- const { MessageEvent } = require('../websocket/events')
9
+ const { createFastMessageEvent } = require('../websocket/events')
10
10
  const { isNetworkError } = require('../fetch/response')
11
11
  const { delay } = require('./util')
12
12
  const { kEnumerableProperty } = require('../../core/util')
@@ -105,7 +105,8 @@ class EventSource extends EventTarget {
105
105
  // 1. Let ev be a new EventSource object.
106
106
  super()
107
107
 
108
- webidl.argumentLengthCheck(arguments, 1, { header: 'EventSource constructor' })
108
+ const prefix = 'EventSource constructor'
109
+ webidl.argumentLengthCheck(arguments, 1, prefix)
109
110
 
110
111
  if (!experimentalWarned) {
111
112
  experimentalWarned = true
@@ -114,8 +115,8 @@ class EventSource extends EventTarget {
114
115
  })
115
116
  }
116
117
 
117
- url = webidl.converters.USVString(url)
118
- eventSourceInitDict = webidl.converters.EventSourceInitDict(eventSourceInitDict)
118
+ url = webidl.converters.USVString(url, prefix, 'url')
119
+ eventSourceInitDict = webidl.converters.EventSourceInitDict(eventSourceInitDict, prefix, 'eventSourceInitDict')
119
120
 
120
121
  this.#dispatcher = eventSourceInitDict.dispatcher
121
122
  this.#state = {
@@ -290,7 +291,7 @@ class EventSource extends EventTarget {
290
291
  const eventSourceStream = new EventSourceStream({
291
292
  eventSourceSettings: this.#state,
292
293
  push: (event) => {
293
- this.dispatchEvent(new MessageEvent(
294
+ this.dispatchEvent(createFastMessageEvent(
294
295
  event.type,
295
296
  event.options
296
297
  ))
@@ -463,7 +464,7 @@ webidl.converters.EventSourceInitDict = webidl.dictionaryConverter([
463
464
  {
464
465
  key: 'withCredentials',
465
466
  converter: webidl.converters.boolean,
466
- defaultValue: false
467
+ defaultValue: () => false
467
468
  },
468
469
  {
469
470
  key: 'dispatcher', // undici only
@@ -7,13 +7,13 @@ const encoder = new TextEncoder()
7
7
  /**
8
8
  * @see https://mimesniff.spec.whatwg.org/#http-token-code-point
9
9
  */
10
- const HTTP_TOKEN_CODEPOINTS = /^[!#$%&'*+-.^_|~A-Za-z0-9]+$/
10
+ const HTTP_TOKEN_CODEPOINTS = /^[!#$%&'*+\-.^_|~A-Za-z0-9]+$/
11
11
  const HTTP_WHITESPACE_REGEX = /[\u000A\u000D\u0009\u0020]/ // eslint-disable-line
12
12
  const ASCII_WHITESPACE_REPLACE_REGEX = /[\u0009\u000A\u000C\u000D\u0020]/g // eslint-disable-line
13
13
  /**
14
14
  * @see https://mimesniff.spec.whatwg.org/#http-quoted-string-token-code-point
15
15
  */
16
- const HTTP_QUOTED_STRING_TOKENS = /[\u0009\u0020-\u007E\u0080-\u00FF]/ // eslint-disable-line
16
+ const HTTP_QUOTED_STRING_TOKENS = /^[\u0009\u0020-\u007E\u0080-\u00FF]+$/ // eslint-disable-line
17
17
 
18
18
  // https://fetch.spec.whatwg.org/#data-url-processor
19
19
  /** @param {URL} dataURL */