From c977df5197ad013f3f4977f5edfaa4c11293afed Mon Sep 17 00:00:00 2001 From: Mert Can Altin Date: Sat, 13 Apr 2024 20:28:40 +0300 Subject: [PATCH] fetch: limit web streams usage in body mixin methods --- lib/web/fetch/response.js | 2 +- lib/web/fetch/util.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/web/fetch/response.js b/lib/web/fetch/response.js index 182e3dc0199..acd063915cf 100644 --- a/lib/web/fetch/response.js +++ b/lib/web/fetch/response.js @@ -146,7 +146,7 @@ class Response { // 4. If body is non-null, then set bodyWithType to the result of extracting body. if (body != null) { const [extractedBody, type] = extractBody(body) - bodyWithType = { body: extractedBody, type } + bodyWithType = { body: extractedBody, type, source: body } } // 5. Perform initialize a response given this, init, and bodyWithType. diff --git a/lib/web/fetch/util.js b/lib/web/fetch/util.js index 8c73f909604..7e6afba3cf1 100644 --- a/lib/web/fetch/util.js +++ b/lib/web/fetch/util.js @@ -1055,6 +1055,11 @@ async function fullyReadBody (body, processBody, processBodyError) { // with taskDestination. const errorSteps = processBodyError + if (typeof body.source === 'string') { + successSteps(new TextEncoder().encode(body.source)) + return + } + // 4. Let reader be the result of getting a reader for body’s stream. // If that threw an exception, then run errorSteps with that // exception and return.