Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetch: limit web streams usage in body mixin methods #3113

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/web/fetch/response.js
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions lib/web/fetch/util.js
Expand Up @@ -1055,6 +1055,12 @@ async function fullyReadBody (body, processBody, processBodyError) {
// with taskDestination.
const errorSteps = processBodyError

if (typeof body.source === 'string') {
const buffer = new TextEncoder().encode(body.source)
successSteps(Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength))
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.
Expand Down