@@ -85,32 +85,33 @@ function createMultipartStream(entries: readonly MultipartEntry[]): MultipartFor
85
85
} ;
86
86
}
87
87
88
- async function detectStreamSupport ( ) : Promise < boolean > {
88
+ async function detectStreamSupport ( ) {
89
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' , {
90
+ let duplexAccessed = false ;
91
+ const hasContentType = new Request ( 'https://' , {
92
+ body : new ReadableStream ( ) ,
98
93
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
94
// @ts -ignore
103
- duplex : 'half' ,
104
- } ) ;
95
+ get duplex ( ) {
96
+ duplexAccessed = true ;
97
+ return 'half' ;
98
+ } ,
99
+ } ) . headers . has ( 'Content-Type' ) ;
105
100
106
101
// If fails to handle fetch(Request), it's likely not a native implementation of
107
102
// 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 {
103
+ const res = await fetch (
104
+ new Request ( 'data:text/plain;charset=utf-8,42' , {
105
+ method : 'POST' ,
106
+ body : new ReadableStream ( ) ,
107
+ // @ts -ignore
108
+ duplex : 'half' ,
109
+ } ) ,
110
+ ) ;
111
+ const body = await res . text ( ) ;
112
+
113
+ return duplexAccessed && ! hasContentType && body === '\x00' ;
114
+ } catch ( error ) {
114
115
return false ;
115
116
}
116
117
}
0 commit comments