feat: fetch stream compatibility enhance (#1551)

This commit is contained in:
Ricky 2023-11-20 15:30:32 +08:00 • committed by GitHub
commit 657334a5fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 2 deletions

21
web/utils/stream.ts Normal file
View file

@ -0,0 +1,21 @@
// https://developer.chrome.com/articles/fetch-streaming-requests/#feature-detection
export const isSupportNativeFetchStream = () => {
const supportsRequestStreams = (() => {
let duplexAccessed = false
const params = {
body: new ReadableStream(),
method: 'POST',
get duplex() {
duplexAccessed = true
return 'half'
},
}
const hasContentType = new Request('', params).headers.has('Content-Type')
return duplexAccessed && !hasContentType
})()
return supportsRequestStreams
}