Skip to content

Commit

Permalink
Improve detection of streaming request support (#581) (#582)
Browse files Browse the repository at this point in the history
* Fix unsupported BodyInit type (#581)

* Only handle `unsupported BodyInit type` error

* Tweak comment

---------

Co-authored-by: Seth Holladay <me@seth-holladay.com>
  • Loading branch information
edram and sholladay committed Jun 25, 2024
1 parent 36d0bd3 commit b1effd9
Showing 1 changed file with 18 additions and 9 deletions.
27 changes: 18 additions & 9 deletions source/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,24 @@ export const supportsRequestStreams = (() => {
const supportsRequest = typeof globalThis.Request === 'function';

if (supportsReadableStream && supportsRequest) {
hasContentType = new globalThis.Request('https://empty.invalid', {
body: new globalThis.ReadableStream(),
method: 'POST',
// @ts-expect-error - Types are outdated.
get duplex() {
duplexAccessed = true;
return 'half';
},
}).headers.has('Content-Type');
try {
hasContentType = new globalThis.Request('https://empty.invalid', {
body: new globalThis.ReadableStream(),
method: 'POST',
// @ts-expect-error - Types are outdated.
get duplex() {
duplexAccessed = true;
return 'half';
},
}).headers.has('Content-Type');
} catch (error) {
// QQBrowser on iOS throws "unsupported BodyInit type" error (see issue #581)
if (error instanceof Error && error.message === 'unsupported BodyInit type') {
return false;
}

throw error;
}
}

return duplexAccessed && !hasContentType;
Expand Down

0 comments on commit b1effd9

Please sign in to comment.