@@ -20,6 +20,12 @@ const fetchProgressDecorator = (total, fn) => {
20
20
const isFetchSupported = typeof fetch !== 'undefined' ;
21
21
const isReadableStreamSupported = isFetchSupported && typeof ReadableStream !== 'undefined' ;
22
22
23
+ // used only inside the fetch adapter
24
+ const encodeText = isFetchSupported && ( typeof TextEncoder !== 'undefined' ?
25
+ ( ( encoder ) => ( str ) => encoder . encode ( str ) ) ( new TextEncoder ( ) ) :
26
+ async ( str ) => new Uint8Array ( await new Response ( str ) . arrayBuffer ( ) )
27
+ ) ;
28
+
23
29
const supportsRequestStream = isReadableStreamSupported && ( ( ) => {
24
30
let duplexAccessed = false ;
25
31
@@ -80,7 +86,7 @@ const getBodyLength = async (body) => {
80
86
}
81
87
82
88
if ( utils . isString ( body ) ) {
83
- return ( await new TextEncoder ( ) . encode ( body ) ) . byteLength ;
89
+ return ( await encodeText ( body ) ) . byteLength ;
84
90
}
85
91
}
86
92
@@ -144,7 +150,7 @@ export default isFetchSupported && (async (config) => {
144
150
data = trackStream ( _request . body , DEFAULT_CHUNK_SIZE , fetchProgressDecorator (
145
151
requestContentLength ,
146
152
progressEventReducer ( onUploadProgress )
147
- ) ) ;
153
+ ) , null , encodeText ) ;
148
154
}
149
155
}
150
156
@@ -179,7 +185,7 @@ export default isFetchSupported && (async (config) => {
179
185
trackStream ( response . body , DEFAULT_CHUNK_SIZE , onDownloadProgress && fetchProgressDecorator (
180
186
responseContentLength ,
181
187
progressEventReducer ( onDownloadProgress , true )
182
- ) , isStreamResponse && onFinish ) ,
188
+ ) , isStreamResponse && onFinish , encodeText ) ,
183
189
options
184
190
) ;
185
191
}
0 commit comments