From 06ca9ca8f352091c64e4ab77dc5aadfeea4ee686 Mon Sep 17 00:00:00 2001 From: edram Date: Thu, 25 Apr 2024 16:47:14 +0800 Subject: [PATCH 1/3] Fix unsupported BodyInit type (#581) --- source/core/constants.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/source/core/constants.ts b/source/core/constants.ts index 27309629..207ac613 100644 --- a/source/core/constants.ts +++ b/source/core/constants.ts @@ -9,15 +9,19 @@ 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 { + // IOS QQBrowser throw "unsupported BodyInit type" Error (see issue #581) + } } return duplexAccessed && !hasContentType; From f2f9236f65e71a47f43b4b474ceb11705edbc816 Mon Sep 17 00:00:00 2001 From: edram Date: Sun, 23 Jun 2024 17:51:04 +0800 Subject: [PATCH 2/3] Only handle `unsupported BodyInit type` error --- source/core/constants.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/core/constants.ts b/source/core/constants.ts index 207ac613..a02ac17d 100644 --- a/source/core/constants.ts +++ b/source/core/constants.ts @@ -19,8 +19,13 @@ export const supportsRequestStreams = (() => { return 'half'; }, }).headers.has('Content-Type'); - } catch { + } catch (error) { // IOS QQBrowser throw "unsupported BodyInit type" Error (see issue #581) + if (error instanceof Error && error.message === 'unsupported BodyInit type') { + return false; + } + + throw error; } } From 8e0cf213307d8ac972bc7ed51c12bf378717c6df Mon Sep 17 00:00:00 2001 From: Seth Holladay Date: Tue, 25 Jun 2024 07:08:53 -0400 Subject: [PATCH 3/3] Tweak comment --- source/core/constants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/core/constants.ts b/source/core/constants.ts index a02ac17d..f05ae175 100644 --- a/source/core/constants.ts +++ b/source/core/constants.ts @@ -20,7 +20,7 @@ export const supportsRequestStreams = (() => { }, }).headers.has('Content-Type'); } catch (error) { - // IOS QQBrowser throw "unsupported BodyInit type" Error (see issue #581) + // QQBrowser on iOS throws "unsupported BodyInit type" error (see issue #581) if (error instanceof Error && error.message === 'unsupported BodyInit type') { return false; }