@@ -19,6 +19,16 @@ export const keepAliveSupport = {
19
19
supported : Boolean ( typeof Request !== "undefined" && "keepalive" in new Request ( "https://[::1]" ) ) ,
20
20
} ;
21
21
22
+ /**
23
+ * @internal
24
+ */
25
+ type AdditionalRequestParameters = {
26
+ // This is required in Node.js when Request has a body, and does nothing in the browser.
27
+ // Duplex: half means the request is fully transmitted before attempting to process the response.
28
+ // As of writing this is the only accepted value in https://fetch.spec.whatwg.org/.
29
+ duplex ?: "half" ;
30
+ } ;
31
+
22
32
/**
23
33
* @public
24
34
*
@@ -91,16 +101,23 @@ export class FetchHttpHandler implements HttpHandler<FetchHttpHandlerConfig> {
91
101
// Request constructor doesn't allow GET/HEAD request with body
92
102
// ref: https://github.com/whatwg/fetch/issues/551
93
103
const body = method === "GET" || method === "HEAD" ? undefined : request . body ;
94
- const requestOptions : RequestInit = { body, headers : new Headers ( request . headers ) , method : method } ;
104
+ const requestOptions : RequestInit & AdditionalRequestParameters = {
105
+ body,
106
+ headers : new Headers ( request . headers ) ,
107
+ method : method ,
108
+ } ;
109
+ if ( body ) {
110
+ requestOptions . duplex = "half" ;
111
+ }
95
112
96
113
// some browsers support abort signal
97
114
if ( typeof AbortController !== "undefined" ) {
98
- ( requestOptions as any ) [ " signal" ] = abortSignal ;
115
+ requestOptions . signal = abortSignal as AbortSignal ;
99
116
}
100
117
101
118
// some browsers support keepalive
102
119
if ( keepAliveSupport . supported ) {
103
- ( requestOptions as any ) [ " keepalive" ] = keepAlive ;
120
+ requestOptions . keepalive = keepAlive ;
104
121
}
105
122
106
123
const fetchRequest = new Request ( url , requestOptions ) ;
0 commit comments