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