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

fix: when no body supplied, do not set bodyUsed to true #1357

Merged
merged 1 commit into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ if (support.iterable) {
}

function consumed(body) {
if (body._noBody) return
if (body.bodyUsed) {
return Promise.reject(new TypeError('Already read'))
}
Expand Down Expand Up @@ -231,6 +232,7 @@ function Body() {
this.bodyUsed = this.bodyUsed
this._bodyInit = body
if (!body) {
this._noBody = true;
this._bodyText = ''
} else if (typeof body === 'string') {
this._bodyText = body
Expand Down
9 changes: 9 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,15 @@ exercise.forEach(function(exerciseMode) {
assert(error instanceof TypeError, 'Promise rejected after body consumed')
})
})

test('does not set bodyUsed to true if no body supplied', function() {
var response = new Response();
assert(response.text, 'Body does not implement text')
assert.equal(response.bodyUsed, false)
response.text()
assert.equal(response.bodyUsed, false)
return response.text()
})
})
})

Expand Down