@@ -85,34 +85,20 @@ function createMultipartStream(entries: readonly MultipartEntry[]): MultipartFor
85
85
} ;
86
86
}
87
87
88
- async function detectStreamSupport ( ) : Promise < boolean > {
89
- try {
90
- const testStream = new ReadableStream ( {
91
- start ( controller ) {
92
- controller . enqueue ( new Uint8Array ( [ 0 ] ) ) ; // Minimal stream chunk
93
- controller . close ( ) ;
94
- } ,
95
- } ) ;
96
-
97
- const request = new Request ( 'data:text/plain;charset=utf-8,42' , {
98
- method : 'POST' ,
99
- body : testStream ,
100
- // Required for streaming request body in some browsers,
101
- // or it will fail and assume it's not supported
102
- // @ts -ignore
103
- duplex : 'half' ,
104
- } ) ;
105
-
106
- // If fails to handle fetch(Request), it's likely not a native implementation of
107
- // Fetch API, so it's not supported.
108
- await fetch ( request . clone ( ) ) ;
109
-
110
- const body = await request . text ( ) ;
111
- // if different from '\x00', it's likely not supported
112
- return body === '\x00' ;
113
- } catch {
114
- return false ;
115
- }
88
+ function detectStreamSupport ( ) {
89
+ let duplexAccessed = false ;
90
+
91
+ const hasContentType = new Request ( 'data:text/plain;charset=utf-8,42' , {
92
+ body : new ReadableStream ( ) ,
93
+ method : 'POST' ,
94
+ // @ts -ignore
95
+ get duplex ( ) {
96
+ duplexAccessed = true ;
97
+ return 'half' ;
98
+ } ,
99
+ } ) . headers . has ( 'Content-Type' ) ;
100
+
101
+ return duplexAccessed && ! hasContentType ;
116
102
}
117
103
118
104
function createFormData ( entries : readonly MultipartEntry [ ] ) : FormData {
@@ -163,7 +149,7 @@ export async function createMultipartRequestInit(
163
149
method : 'POST' | 'PUT' ,
164
150
entries : readonly MultipartEntry [ ] ,
165
151
) : Promise < RequestInit > {
166
- if ( await detectStreamSupport ( ) ) {
152
+ if ( detectStreamSupport ( ) ) {
167
153
const { stream, boundary } = createMultipartStream ( entries ) ;
168
154
169
155
return {
0 commit comments