diff --git a/source/core/Ky.ts b/source/core/Ky.ts index 8165fa18..d2ef777e 100644 --- a/source/core/Ky.ts +++ b/source/core/Ky.ts @@ -35,8 +35,8 @@ export class Ky { // Delay the fetch so that body method shortcuts can set the Accept header await Promise.resolve(); - // Before using ky.request, _fetch clones a new Request for retries preparation. - // If retry is not needed, close the original Request ReadableStream for memory safety. + // Before using ky.request, _fetch clones it and saves the clone for future retries to use. + // If retry is not needed, close the cloned request's ReadableStream for memory safety. let response = await ky._fetch(); for (const hook of ky._options.hooks.afterResponse) { @@ -65,10 +65,9 @@ export class Ky { throw error; } - // Now, it can be determined that a retry is not needed, - // close the ReadableStream of the ky.request. + // Now that we know a retry is not needed, close the ReadableStream of the cloned request. if (!ky.request.bodyUsed) { - await ky.request.arrayBuffer(); + await ky.request.body?.cancel(); } // If `onDownloadProgress` is passed, it uses the stream API internally