From bcdc6da78c86782a9fe0c33fae9c2e56bedeb3d1 Mon Sep 17 00:00:00 2001 From: Joshua Sosso Date: Fri, 24 May 2024 10:55:12 -0500 Subject: [PATCH 1/6] add _bodyInit check for react native --- src/fetch.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/fetch.ts b/src/fetch.ts index 61d858a..b3d47df 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -185,7 +185,11 @@ export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch { } const hasBody = - context.response.body && + (context.response.body || + // React Native whatwg-fetch check. Can be removed when the following occurs + // 1) https://github.com/JakeChampion/fetch/issues/1454 is fixed + // 2) React Native upgrades to the whatwg-fetch version that has this fix + (context.response as any)._bodyInit) && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD"; if (hasBody) { From e11a6a0ca98196c239bd3f65c92be847abdc6898 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 8 Oct 2024 17:19:25 +0200 Subject: [PATCH 2/6] Update fetch.ts --- src/fetch.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/fetch.ts b/src/fetch.ts index 5a3b043..ec1141d 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -195,9 +195,7 @@ export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch { const hasBody = (context.response.body || - // React Native whatwg-fetch check. Can be removed when the following occurs - // 1) https://github.com/JakeChampion/fetch/issues/1454 is fixed - // 2) React Native upgrades to the whatwg-fetch version that has this fix + // https://github.com/JakeChampion/fetch/issues/1454 (context.response as any)._bodyInit) && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD"; From 5ab0b9423e579e603db0f6d1bd5cf66650afd94d Mon Sep 17 00:00:00 2001 From: Joshua Sosso Date: Tue, 8 Oct 2024 10:34:47 -0500 Subject: [PATCH 3/6] check for _bodyInit in "stream" responseType case --- src/fetch.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/fetch.ts b/src/fetch.ts index ec1141d..d81b0d5 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -215,7 +215,10 @@ export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch { break; } case "stream": { - context.response._data = context.response.body; + context.response._data = + context.response.body || + // https://github.com/JakeChampion/fetch/issues/1454 + (context.response as any)._bodyInit; break; } default: { From 8ae29736eeda83e302e0dd03a6cb5125aa5498f9 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 8 Oct 2024 17:41:06 +0200 Subject: [PATCH 4/6] add ref to #294 --- src/fetch.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/fetch.ts b/src/fetch.ts index d81b0d5..9a5da85 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -196,6 +196,7 @@ export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch { const hasBody = (context.response.body || // https://github.com/JakeChampion/fetch/issues/1454 + // https://github.com/unjs/ofetch/issues/294 (context.response as any)._bodyInit) && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD"; @@ -218,6 +219,7 @@ export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch { context.response._data = context.response.body || // https://github.com/JakeChampion/fetch/issues/1454 + // https://github.com/unjs/ofetch/issues/294 (context.response as any)._bodyInit; break; } From df30e5d8b635f43f8307495de7d9d1eaf0c2ae64 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Tue, 8 Oct 2024 17:42:30 +0200 Subject: [PATCH 5/6] Update fetch.ts --- src/fetch.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/fetch.ts b/src/fetch.ts index 9a5da85..9db8de8 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -195,8 +195,9 @@ export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch { const hasBody = (context.response.body || - // https://github.com/JakeChampion/fetch/issues/1454 + // https://github.com/unjs/ofetch/issues/324 // https://github.com/unjs/ofetch/issues/294 + // https://github.com/JakeChampion/fetch/issues/1454 (context.response as any)._bodyInit) && !nullBodyResponses.has(context.response.status) && context.options.method !== "HEAD"; @@ -217,10 +218,8 @@ export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch { } case "stream": { context.response._data = - context.response.body || - // https://github.com/JakeChampion/fetch/issues/1454 - // https://github.com/unjs/ofetch/issues/294 - (context.response as any)._bodyInit; + context.response.body || + (context.response as any)._bodyInit; // (see refs above) break; } default: { From 6c5317b1a4ca8a3bd91d49f752f22e2ebae420b9 Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:43:00 +0000 Subject: [PATCH 6/6] chore: apply automated updates --- src/fetch.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/fetch.ts b/src/fetch.ts index 9db8de8..9bd3c96 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -218,8 +218,7 @@ export function createFetch(globalOptions: CreateFetchOptions = {}): $Fetch { } case "stream": { context.response._data = - context.response.body || - (context.response as any)._bodyInit; // (see refs above) + context.response.body || (context.response as any)._bodyInit; // (see refs above) break; } default: {