undici 6.21.0 → 7.0.0-alpha.10

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.
Files changed (156) hide show
  1. package/README.md +27 -46
  2. package/docs/docs/api/Agent.md +14 -17
  3. package/docs/docs/api/BalancedPool.md +16 -16
  4. package/docs/docs/api/CacheStore.md +131 -0
  5. package/docs/docs/api/Client.md +12 -14
  6. package/docs/docs/api/Debug.md +1 -1
  7. package/docs/docs/api/Dispatcher.md +98 -194
  8. package/docs/docs/api/EnvHttpProxyAgent.md +12 -13
  9. package/docs/docs/api/MockAgent.md +5 -3
  10. package/docs/docs/api/MockClient.md +5 -5
  11. package/docs/docs/api/MockPool.md +4 -3
  12. package/docs/docs/api/Pool.md +15 -16
  13. package/docs/docs/api/PoolStats.md +1 -1
  14. package/docs/docs/api/ProxyAgent.md +3 -3
  15. package/docs/docs/api/RedirectHandler.md +1 -1
  16. package/docs/docs/api/RetryAgent.md +1 -1
  17. package/docs/docs/api/RetryHandler.md +4 -4
  18. package/docs/docs/api/WebSocket.md +46 -4
  19. package/docs/docs/api/api-lifecycle.md +11 -11
  20. package/docs/docs/best-practices/mocking-request.md +2 -2
  21. package/docs/docs/best-practices/proxy.md +1 -1
  22. package/index.d.ts +1 -1
  23. package/index.js +23 -7
  24. package/lib/api/abort-signal.js +2 -0
  25. package/lib/api/api-connect.js +3 -1
  26. package/lib/api/api-pipeline.js +7 -6
  27. package/lib/api/api-request.js +33 -48
  28. package/lib/api/api-stream.js +39 -50
  29. package/lib/api/api-upgrade.js +5 -3
  30. package/lib/api/readable.js +235 -62
  31. package/lib/api/util.js +2 -0
  32. package/lib/cache/memory-cache-store.js +177 -0
  33. package/lib/cache/sqlite-cache-store.js +446 -0
  34. package/lib/core/constants.js +35 -10
  35. package/lib/core/diagnostics.js +122 -128
  36. package/lib/core/errors.js +6 -6
  37. package/lib/core/request.js +13 -11
  38. package/lib/core/symbols.js +2 -1
  39. package/lib/core/tree.js +9 -1
  40. package/lib/core/util.js +237 -49
  41. package/lib/dispatcher/agent.js +3 -17
  42. package/lib/dispatcher/balanced-pool.js +5 -8
  43. package/lib/dispatcher/client-h1.js +379 -134
  44. package/lib/dispatcher/client-h2.js +173 -107
  45. package/lib/dispatcher/client.js +19 -32
  46. package/lib/dispatcher/dispatcher-base.js +6 -35
  47. package/lib/dispatcher/dispatcher.js +7 -24
  48. package/lib/dispatcher/fixed-queue.js +91 -49
  49. package/lib/dispatcher/pool-stats.js +2 -0
  50. package/lib/dispatcher/pool.js +3 -6
  51. package/lib/dispatcher/proxy-agent.js +3 -6
  52. package/lib/handler/cache-handler.js +393 -0
  53. package/lib/handler/cache-revalidation-handler.js +124 -0
  54. package/lib/handler/decorator-handler.js +27 -0
  55. package/lib/handler/redirect-handler.js +54 -59
  56. package/lib/handler/retry-handler.js +77 -109
  57. package/lib/handler/unwrap-handler.js +96 -0
  58. package/lib/handler/wrap-handler.js +98 -0
  59. package/lib/interceptor/cache.js +350 -0
  60. package/lib/interceptor/dns.js +375 -0
  61. package/lib/interceptor/dump.js +2 -2
  62. package/lib/interceptor/redirect.js +11 -14
  63. package/lib/interceptor/response-error.js +18 -7
  64. package/lib/llhttp/constants.d.ts +97 -0
  65. package/lib/llhttp/constants.js +412 -192
  66. package/lib/llhttp/constants.js.map +1 -0
  67. package/lib/llhttp/llhttp-wasm.js +11 -1
  68. package/lib/llhttp/llhttp_simd-wasm.js +11 -1
  69. package/lib/llhttp/utils.d.ts +2 -0
  70. package/lib/llhttp/utils.js +9 -9
  71. package/lib/llhttp/utils.js.map +1 -0
  72. package/lib/mock/mock-agent.js +5 -8
  73. package/lib/mock/mock-client.js +9 -4
  74. package/lib/mock/mock-errors.js +3 -1
  75. package/lib/mock/mock-interceptor.js +8 -6
  76. package/lib/mock/mock-pool.js +9 -4
  77. package/lib/mock/mock-symbols.js +3 -1
  78. package/lib/mock/mock-utils.js +29 -5
  79. package/lib/util/cache.js +360 -0
  80. package/lib/web/cache/cache.js +24 -21
  81. package/lib/web/cache/cachestorage.js +1 -1
  82. package/lib/web/cookies/index.js +29 -14
  83. package/lib/web/cookies/parse.js +8 -3
  84. package/lib/web/eventsource/eventsource-stream.js +9 -8
  85. package/lib/web/eventsource/eventsource.js +10 -6
  86. package/lib/web/fetch/body.js +43 -41
  87. package/lib/web/fetch/constants.js +12 -5
  88. package/lib/web/fetch/data-url.js +3 -3
  89. package/lib/web/fetch/formdata-parser.js +72 -45
  90. package/lib/web/fetch/formdata.js +65 -54
  91. package/lib/web/fetch/headers.js +118 -86
  92. package/lib/web/fetch/index.js +58 -67
  93. package/lib/web/fetch/request.js +136 -77
  94. package/lib/web/fetch/response.js +87 -56
  95. package/lib/web/fetch/util.js +259 -109
  96. package/lib/web/fetch/webidl.js +113 -68
  97. package/lib/web/websocket/connection.js +76 -147
  98. package/lib/web/websocket/constants.js +70 -10
  99. package/lib/web/websocket/events.js +4 -2
  100. package/lib/web/websocket/frame.js +45 -3
  101. package/lib/web/websocket/receiver.js +29 -33
  102. package/lib/web/websocket/sender.js +18 -13
  103. package/lib/web/websocket/stream/websocketerror.js +83 -0
  104. package/lib/web/websocket/stream/websocketstream.js +485 -0
  105. package/lib/web/websocket/util.js +128 -77
  106. package/lib/web/websocket/websocket.js +234 -135
  107. package/package.json +24 -36
  108. package/scripts/strip-comments.js +3 -1
  109. package/types/agent.d.ts +7 -7
  110. package/types/api.d.ts +24 -24
  111. package/types/balanced-pool.d.ts +11 -11
  112. package/types/cache-interceptor.d.ts +172 -0
  113. package/types/client.d.ts +11 -12
  114. package/types/cookies.d.ts +2 -0
  115. package/types/diagnostics-channel.d.ts +10 -10
  116. package/types/dispatcher.d.ts +113 -90
  117. package/types/env-http-proxy-agent.d.ts +2 -2
  118. package/types/errors.d.ts +53 -47
  119. package/types/fetch.d.ts +17 -16
  120. package/types/formdata.d.ts +7 -7
  121. package/types/global-dispatcher.d.ts +4 -4
  122. package/types/global-origin.d.ts +5 -5
  123. package/types/handlers.d.ts +7 -7
  124. package/types/header.d.ts +157 -1
  125. package/types/index.d.ts +44 -46
  126. package/types/interceptors.d.ts +25 -8
  127. package/types/mock-agent.d.ts +21 -18
  128. package/types/mock-client.d.ts +4 -4
  129. package/types/mock-errors.d.ts +3 -3
  130. package/types/mock-interceptor.d.ts +19 -19
  131. package/types/mock-pool.d.ts +4 -4
  132. package/types/patch.d.ts +0 -4
  133. package/types/pool-stats.d.ts +8 -8
  134. package/types/pool.d.ts +12 -12
  135. package/types/proxy-agent.d.ts +4 -4
  136. package/types/readable.d.ts +18 -15
  137. package/types/retry-agent.d.ts +1 -1
  138. package/types/retry-handler.d.ts +10 -10
  139. package/types/util.d.ts +3 -3
  140. package/types/utility.d.ts +7 -0
  141. package/types/webidl.d.ts +44 -6
  142. package/types/websocket.d.ts +34 -1
  143. package/docs/docs/api/DispatchInterceptor.md +0 -60
  144. package/lib/interceptor/redirect-interceptor.js +0 -21
  145. package/lib/mock/pluralizer.js +0 -29
  146. package/lib/web/cache/symbols.js +0 -5
  147. package/lib/web/fetch/file.js +0 -126
  148. package/lib/web/fetch/symbols.js +0 -9
  149. package/lib/web/fileapi/encoding.js +0 -290
  150. package/lib/web/fileapi/filereader.js +0 -344
  151. package/lib/web/fileapi/progressevent.js +0 -78
  152. package/lib/web/fileapi/symbols.js +0 -10
  153. package/lib/web/fileapi/util.js +0 -391
  154. package/lib/web/websocket/symbols.js +0 -12
  155. package/types/file.d.ts +0 -39
  156. package/types/filereader.d.ts +0 -54
@@ -23,12 +23,11 @@ const {
23
23
  requestDuplex
24
24
  } = require('./constants')
25
25
  const { kEnumerableProperty, normalizedMethodRecordsBase, normalizedMethodRecords } = util
26
- const { kHeaders, kSignal, kState, kDispatcher } = require('./symbols')
27
26
  const { webidl } = require('./webidl')
28
27
  const { URLSerializer } = require('./data-url')
29
28
  const { kConstruct } = require('../../core/symbols')
30
29
  const assert = require('node:assert')
31
- const { getMaxListeners, setMaxListeners, getEventListeners, defaultMaxListeners } = require('node:events')
30
+ const { getMaxListeners, setMaxListeners, defaultMaxListeners } = require('node:events')
32
31
 
33
32
  const kAbortController = Symbol('abortController')
34
33
 
@@ -80,9 +79,21 @@ let patchMethodWarning = false
80
79
 
81
80
  // https://fetch.spec.whatwg.org/#request-class
82
81
  class Request {
82
+ /** @type {AbortSignal} */
83
+ #signal
84
+
85
+ /** @type {import('../../dispatcher/dispatcher')} */
86
+ #dispatcher
87
+
88
+ /** @type {Headers} */
89
+ #headers
90
+
91
+ #state
92
+
83
93
  // https://fetch.spec.whatwg.org/#dom-request
84
- constructor (input, init = {}) {
94
+ constructor (input, init = undefined) {
85
95
  webidl.util.markAsUncloneable(this)
96
+
86
97
  if (input === kConstruct) {
87
98
  return
88
99
  }
@@ -107,7 +118,7 @@ class Request {
107
118
 
108
119
  // 5. If input is a string, then:
109
120
  if (typeof input === 'string') {
110
- this[kDispatcher] = init.dispatcher
121
+ this.#dispatcher = init.dispatcher
111
122
 
112
123
  // 1. Let parsedURL be the result of parsing input with baseURL.
113
124
  // 2. If parsedURL is failure, then throw a TypeError.
@@ -132,18 +143,18 @@ class Request {
132
143
  // 5. Set fallbackMode to "cors".
133
144
  fallbackMode = 'cors'
134
145
  } else {
135
- this[kDispatcher] = init.dispatcher || input[kDispatcher]
136
-
137
146
  // 6. Otherwise:
138
147
 
139
148
  // 7. Assert: input is a Request object.
140
- assert(input instanceof Request)
149
+ assert(webidl.is.Request(input))
141
150
 
142
151
  // 8. Set request to input’s request.
143
- request = input[kState]
152
+ request = input.#state
144
153
 
145
154
  // 9. Set signal to input’s signal.
146
- signal = input[kSignal]
155
+ signal = input.#signal
156
+
157
+ this.#dispatcher = init.dispatcher || input.#dispatcher
147
158
  }
148
159
 
149
160
  // 7. Let origin be this’s relevant settings object’s origin.
@@ -390,27 +401,17 @@ class Request {
390
401
  }
391
402
 
392
403
  // 27. Set this’s request to request.
393
- this[kState] = request
404
+ this.#state = request
394
405
 
395
406
  // 28. Set this’s signal to a new AbortSignal object with this’s relevant
396
407
  // Realm.
397
408
  // TODO: could this be simplified with AbortSignal.any
398
409
  // (https://dom.spec.whatwg.org/#dom-abortsignal-any)
399
410
  const ac = new AbortController()
400
- this[kSignal] = ac.signal
411
+ this.#signal = ac.signal
401
412
 
402
413
  // 29. If signal is not null, then make this’s signal follow signal.
403
414
  if (signal != null) {
404
- if (
405
- !signal ||
406
- typeof signal.aborted !== 'boolean' ||
407
- typeof signal.addEventListener !== 'function'
408
- ) {
409
- throw new TypeError(
410
- "Failed to construct 'Request': member signal is not of type AbortSignal."
411
- )
412
- }
413
-
414
415
  if (signal.aborted) {
415
416
  ac.abort(signal.reason)
416
417
  } else {
@@ -430,8 +431,6 @@ class Request {
430
431
  // This is only available in node >= v19.9.0
431
432
  if (typeof getMaxListeners === 'function' && getMaxListeners(signal) === defaultMaxListeners) {
432
433
  setMaxListeners(1500, signal)
433
- } else if (getEventListeners(signal, 'abort').length >= defaultMaxListeners) {
434
- setMaxListeners(1500, signal)
435
434
  }
436
435
  } catch {}
437
436
 
@@ -447,9 +446,9 @@ class Request {
447
446
  // 30. Set this’s headers to a new Headers object with this’s relevant
448
447
  // Realm, whose header list is request’s header list and guard is
449
448
  // "request".
450
- this[kHeaders] = new Headers(kConstruct)
451
- setHeadersList(this[kHeaders], request.headersList)
452
- setHeadersGuard(this[kHeaders], 'request')
449
+ this.#headers = new Headers(kConstruct)
450
+ setHeadersList(this.#headers, request.headersList)
451
+ setHeadersGuard(this.#headers, 'request')
453
452
 
454
453
  // 31. If this’s request’s mode is "no-cors", then:
455
454
  if (mode === 'no-cors') {
@@ -462,13 +461,13 @@ class Request {
462
461
  }
463
462
 
464
463
  // 2. Set this’s headers’s guard to "request-no-cors".
465
- setHeadersGuard(this[kHeaders], 'request-no-cors')
464
+ setHeadersGuard(this.#headers, 'request-no-cors')
466
465
  }
467
466
 
468
467
  // 32. If init is not empty, then:
469
468
  if (initHasKey) {
470
469
  /** @type {HeadersList} */
471
- const headersList = getHeadersList(this[kHeaders])
470
+ const headersList = getHeadersList(this.#headers)
472
471
  // 1. Let headers be a copy of this’s headers and its associated header
473
472
  // list.
474
473
  // 2. If init["headers"] exists, then set headers to init["headers"].
@@ -487,13 +486,13 @@ class Request {
487
486
  headersList.cookies = headers.cookies
488
487
  } else {
489
488
  // 5. Otherwise, fill this’s headers with headers.
490
- fillHeaders(this[kHeaders], headers)
489
+ fillHeaders(this.#headers, headers)
491
490
  }
492
491
  }
493
492
 
494
493
  // 33. Let inputBody be input’s request’s body if input is a Request
495
494
  // object; otherwise null.
496
- const inputBody = input instanceof Request ? input[kState].body : null
495
+ const inputBody = webidl.is.Request(input) ? input.#state.body : null
497
496
 
498
497
  // 34. If either init["body"] exists and is non-null or inputBody is
499
498
  // non-null, and request’s method is `GET` or `HEAD`, then throw a
@@ -522,8 +521,8 @@ class Request {
522
521
  // 3, If Content-Type is non-null and this’s headers’s header list does
523
522
  // not contain `Content-Type`, then append `Content-Type`/Content-Type to
524
523
  // this’s headers.
525
- if (contentType && !getHeadersList(this[kHeaders]).contains('content-type', true)) {
526
- this[kHeaders].append('content-type', contentType)
524
+ if (contentType && !getHeadersList(this.#headers).contains('content-type', true)) {
525
+ this.#headers.append('content-type', contentType, true)
527
526
  }
528
527
  }
529
528
 
@@ -558,7 +557,7 @@ class Request {
558
557
  // 40. If initBody is null and inputBody is non-null, then:
559
558
  if (initBody == null && inputBody != null) {
560
559
  // 1. If input is unusable, then throw a TypeError.
561
- if (bodyUnusable(input)) {
560
+ if (bodyUnusable(input.#state)) {
562
561
  throw new TypeError(
563
562
  'Cannot construct a Request with a Request object that has already been used.'
564
563
  )
@@ -576,7 +575,7 @@ class Request {
576
575
  }
577
576
 
578
577
  // 41. Set this’s request’s body to finalBody.
579
- this[kState].body = finalBody
578
+ this.#state.body = finalBody
580
579
  }
581
580
 
582
581
  // Returns request’s HTTP method, which is "GET" by default.
@@ -584,7 +583,7 @@ class Request {
584
583
  webidl.brandCheck(this, Request)
585
584
 
586
585
  // The method getter steps are to return this’s request’s method.
587
- return this[kState].method
586
+ return this.#state.method
588
587
  }
589
588
 
590
589
  // Returns the URL of request as a string.
@@ -592,7 +591,7 @@ class Request {
592
591
  webidl.brandCheck(this, Request)
593
592
 
594
593
  // The url getter steps are to return this’s request’s URL, serialized.
595
- return URLSerializer(this[kState].url)
594
+ return URLSerializer(this.#state.url)
596
595
  }
597
596
 
598
597
  // Returns a Headers object consisting of the headers associated with request.
@@ -602,7 +601,7 @@ class Request {
602
601
  webidl.brandCheck(this, Request)
603
602
 
604
603
  // The headers getter steps are to return this’s headers.
605
- return this[kHeaders]
604
+ return this.#headers
606
605
  }
607
606
 
608
607
  // Returns the kind of resource requested by request, e.g., "document"
@@ -611,7 +610,7 @@ class Request {
611
610
  webidl.brandCheck(this, Request)
612
611
 
613
612
  // The destination getter are to return this’s request’s destination.
614
- return this[kState].destination
613
+ return this.#state.destination
615
614
  }
616
615
 
617
616
  // Returns the referrer of request. Its value can be a same-origin URL if
@@ -624,18 +623,18 @@ class Request {
624
623
 
625
624
  // 1. If this’s request’s referrer is "no-referrer", then return the
626
625
  // empty string.
627
- if (this[kState].referrer === 'no-referrer') {
626
+ if (this.#state.referrer === 'no-referrer') {
628
627
  return ''
629
628
  }
630
629
 
631
630
  // 2. If this’s request’s referrer is "client", then return
632
631
  // "about:client".
633
- if (this[kState].referrer === 'client') {
632
+ if (this.#state.referrer === 'client') {
634
633
  return 'about:client'
635
634
  }
636
635
 
637
636
  // Return this’s request’s referrer, serialized.
638
- return this[kState].referrer.toString()
637
+ return this.#state.referrer.toString()
639
638
  }
640
639
 
641
640
  // Returns the referrer policy associated with request.
@@ -645,7 +644,7 @@ class Request {
645
644
  webidl.brandCheck(this, Request)
646
645
 
647
646
  // The referrerPolicy getter steps are to return this’s request’s referrer policy.
648
- return this[kState].referrerPolicy
647
+ return this.#state.referrerPolicy
649
648
  }
650
649
 
651
650
  // Returns the mode associated with request, which is a string indicating
@@ -655,15 +654,17 @@ class Request {
655
654
  webidl.brandCheck(this, Request)
656
655
 
657
656
  // The mode getter steps are to return this’s request’s mode.
658
- return this[kState].mode
657
+ return this.#state.mode
659
658
  }
660
659
 
661
660
  // Returns the credentials mode associated with request,
662
661
  // which is a string indicating whether credentials will be sent with the
663
662
  // request always, never, or only when sent to a same-origin URL.
664
663
  get credentials () {
664
+ webidl.brandCheck(this, Request)
665
+
665
666
  // The credentials getter steps are to return this’s request’s credentials mode.
666
- return this[kState].credentials
667
+ return this.#state.credentials
667
668
  }
668
669
 
669
670
  // Returns the cache mode associated with request,
@@ -673,7 +674,7 @@ class Request {
673
674
  webidl.brandCheck(this, Request)
674
675
 
675
676
  // The cache getter steps are to return this’s request’s cache mode.
676
- return this[kState].cache
677
+ return this.#state.cache
677
678
  }
678
679
 
679
680
  // Returns the redirect mode associated with request,
@@ -684,7 +685,7 @@ class Request {
684
685
  webidl.brandCheck(this, Request)
685
686
 
686
687
  // The redirect getter steps are to return this’s request’s redirect mode.
687
- return this[kState].redirect
688
+ return this.#state.redirect
688
689
  }
689
690
 
690
691
  // Returns request’s subresource integrity metadata, which is a
@@ -695,7 +696,7 @@ class Request {
695
696
 
696
697
  // The integrity getter steps are to return this’s request’s integrity
697
698
  // metadata.
698
- return this[kState].integrity
699
+ return this.#state.integrity
699
700
  }
700
701
 
701
702
  // Returns a boolean indicating whether or not request can outlive the
@@ -704,7 +705,7 @@ class Request {
704
705
  webidl.brandCheck(this, Request)
705
706
 
706
707
  // The keepalive getter steps are to return this’s request’s keepalive.
707
- return this[kState].keepalive
708
+ return this.#state.keepalive
708
709
  }
709
710
 
710
711
  // Returns a boolean indicating whether or not request is for a reload
@@ -714,7 +715,7 @@ class Request {
714
715
 
715
716
  // The isReloadNavigation getter steps are to return true if this’s
716
717
  // request’s reload-navigation flag is set; otherwise false.
717
- return this[kState].reloadNavigation
718
+ return this.#state.reloadNavigation
718
719
  }
719
720
 
720
721
  // Returns a boolean indicating whether or not request is for a history
@@ -724,7 +725,7 @@ class Request {
724
725
 
725
726
  // The isHistoryNavigation getter steps are to return true if this’s request’s
726
727
  // history-navigation flag is set; otherwise false.
727
- return this[kState].historyNavigation
728
+ return this.#state.historyNavigation
728
729
  }
729
730
 
730
731
  // Returns the signal associated with request, which is an AbortSignal
@@ -734,19 +735,19 @@ class Request {
734
735
  webidl.brandCheck(this, Request)
735
736
 
736
737
  // The signal getter steps are to return this’s signal.
737
- return this[kSignal]
738
+ return this.#signal
738
739
  }
739
740
 
740
741
  get body () {
741
742
  webidl.brandCheck(this, Request)
742
743
 
743
- return this[kState].body ? this[kState].body.stream : null
744
+ return this.#state.body ? this.#state.body.stream : null
744
745
  }
745
746
 
746
747
  get bodyUsed () {
747
748
  webidl.brandCheck(this, Request)
748
749
 
749
- return !!this[kState].body && util.isDisturbed(this[kState].body.stream)
750
+ return !!this.#state.body && util.isDisturbed(this.#state.body.stream)
750
751
  }
751
752
 
752
753
  get duplex () {
@@ -760,12 +761,12 @@ class Request {
760
761
  webidl.brandCheck(this, Request)
761
762
 
762
763
  // 1. If this is unusable, then throw a TypeError.
763
- if (bodyUnusable(this)) {
764
+ if (bodyUnusable(this.#state)) {
764
765
  throw new TypeError('unusable')
765
766
  }
766
767
 
767
768
  // 2. Let clonedRequest be the result of cloning this’s request.
768
- const clonedRequest = cloneRequest(this[kState])
769
+ const clonedRequest = cloneRequest(this.#state)
769
770
 
770
771
  // 3. Let clonedRequestObject be the result of creating a Request object,
771
772
  // given clonedRequest, this’s headers’s guard, and this’s relevant Realm.
@@ -788,7 +789,7 @@ class Request {
788
789
  }
789
790
 
790
791
  // 4. Return clonedRequestObject.
791
- return fromInnerRequest(clonedRequest, ac.signal, getHeadersGuard(this[kHeaders]))
792
+ return fromInnerRequest(clonedRequest, this.#dispatcher, ac.signal, getHeadersGuard(this.#headers))
792
793
  }
793
794
 
794
795
  [nodeUtil.inspect.custom] (depth, options) {
@@ -818,9 +819,64 @@ class Request {
818
819
 
819
820
  return `Request ${nodeUtil.formatWithOptions(options, properties)}`
820
821
  }
822
+
823
+ /**
824
+ * @param {Request} request
825
+ * @param {AbortSignal} newSignal
826
+ */
827
+ static setRequestSignal (request, newSignal) {
828
+ request.#signal = newSignal
829
+ return request
830
+ }
831
+
832
+ /**
833
+ * @param {Request} request
834
+ */
835
+ static getRequestDispatcher (request) {
836
+ return request.#dispatcher
837
+ }
838
+
839
+ /**
840
+ * @param {Request} request
841
+ * @param {import('../../dispatcher/dispatcher')} newDispatcher
842
+ */
843
+ static setRequestDispatcher (request, newDispatcher) {
844
+ request.#dispatcher = newDispatcher
845
+ }
846
+
847
+ /**
848
+ * @param {Request} request
849
+ * @param {Headers} newHeaders
850
+ */
851
+ static setRequestHeaders (request, newHeaders) {
852
+ request.#headers = newHeaders
853
+ }
854
+
855
+ /**
856
+ * @param {Request} request
857
+ */
858
+ static getRequestState (request) {
859
+ return request.#state
860
+ }
861
+
862
+ /**
863
+ * @param {Request} request
864
+ * @param {any} newState
865
+ */
866
+ static setRequestState (request, newState) {
867
+ request.#state = newState
868
+ }
821
869
  }
822
870
 
823
- mixinBody(Request)
871
+ const { setRequestSignal, getRequestDispatcher, setRequestDispatcher, setRequestHeaders, getRequestState, setRequestState } = Request
872
+ Reflect.deleteProperty(Request, 'setRequestSignal')
873
+ Reflect.deleteProperty(Request, 'getRequestDispatcher')
874
+ Reflect.deleteProperty(Request, 'setRequestDispatcher')
875
+ Reflect.deleteProperty(Request, 'setRequestHeaders')
876
+ Reflect.deleteProperty(Request, 'getRequestState')
877
+ Reflect.deleteProperty(Request, 'setRequestState')
878
+
879
+ mixinBody(Request, getRequestState)
824
880
 
825
881
  // https://fetch.spec.whatwg.org/#requests
826
882
  function makeRequest (init) {
@@ -888,17 +944,20 @@ function cloneRequest (request) {
888
944
  /**
889
945
  * @see https://fetch.spec.whatwg.org/#request-create
890
946
  * @param {any} innerRequest
947
+ * @param {import('../../dispatcher/agent')} dispatcher
891
948
  * @param {AbortSignal} signal
892
949
  * @param {'request' | 'immutable' | 'request-no-cors' | 'response' | 'none'} guard
893
950
  * @returns {Request}
894
951
  */
895
- function fromInnerRequest (innerRequest, signal, guard) {
952
+ function fromInnerRequest (innerRequest, dispatcher, signal, guard) {
896
953
  const request = new Request(kConstruct)
897
- request[kState] = innerRequest
898
- request[kSignal] = signal
899
- request[kHeaders] = new Headers(kConstruct)
900
- setHeadersList(request[kHeaders], innerRequest.headersList)
901
- setHeadersGuard(request[kHeaders], guard)
954
+ setRequestState(request, innerRequest)
955
+ setRequestDispatcher(request, dispatcher)
956
+ setRequestSignal(request, signal)
957
+ const headers = new Headers(kConstruct)
958
+ setRequestHeaders(request, headers)
959
+ setHeadersList(headers, innerRequest.headersList)
960
+ setHeadersGuard(headers, guard)
902
961
  return request
903
962
  }
904
963
 
@@ -929,27 +988,21 @@ Object.defineProperties(Request.prototype, {
929
988
  }
930
989
  })
931
990
 
932
- webidl.converters.Request = webidl.interfaceConverter(
933
- Request
934
- )
991
+ webidl.is.Request = webidl.util.MakeTypeAssertion(Request)
935
992
 
936
993
  // https://fetch.spec.whatwg.org/#requestinfo
937
994
  webidl.converters.RequestInfo = function (V, prefix, argument) {
938
995
  if (typeof V === 'string') {
939
- return webidl.converters.USVString(V, prefix, argument)
996
+ return webidl.converters.USVString(V)
940
997
  }
941
998
 
942
- if (V instanceof Request) {
943
- return webidl.converters.Request(V, prefix, argument)
999
+ if (webidl.is.Request(V)) {
1000
+ return V
944
1001
  }
945
1002
 
946
- return webidl.converters.USVString(V, prefix, argument)
1003
+ return webidl.converters.USVString(V)
947
1004
  }
948
1005
 
949
- webidl.converters.AbortSignal = webidl.interfaceConverter(
950
- AbortSignal
951
- )
952
-
953
1006
  // https://fetch.spec.whatwg.org/#requestinit
954
1007
  webidl.converters.RequestInit = webidl.dictionaryConverter([
955
1008
  {
@@ -1014,8 +1067,7 @@ webidl.converters.RequestInit = webidl.dictionaryConverter([
1014
1067
  (signal) => webidl.converters.AbortSignal(
1015
1068
  signal,
1016
1069
  'RequestInit',
1017
- 'signal',
1018
- { strict: false }
1070
+ 'signal'
1019
1071
  )
1020
1072
  )
1021
1073
  },
@@ -1034,4 +1086,11 @@ webidl.converters.RequestInit = webidl.dictionaryConverter([
1034
1086
  }
1035
1087
  ])
1036
1088
 
1037
- module.exports = { Request, makeRequest, fromInnerRequest, cloneRequest }
1089
+ module.exports = {
1090
+ Request,
1091
+ makeRequest,
1092
+ fromInnerRequest,
1093
+ cloneRequest,
1094
+ getRequestDispatcher,
1095
+ getRequestState
1096
+ }