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

Response.bodyUsed is not spec compliant #1794

Closed
tkrotoff opened this issue Dec 1, 2022 · 2 comments
Closed

Response.bodyUsed is not spec compliant #1794

tkrotoff opened this issue Dec 1, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@tkrotoff
Copy link

tkrotoff commented Dec 1, 2022

Bug Description

Response.bodyUsed does not comply with specs

const response = new Response();
expect(response.bodyUsed).toEqual(false); // OK

expect(await response.text()).toEqual('');
expect(response.bodyUsed).toEqual(true); // Fail

Once the response has been read bodyUsed should be true
This what Chrome, Firefox, WebKit, old Edge, node-fetch and whatwg-fetch do

From the spec: https://fetch.spec.whatwg.org/#dom-body-bodyused

The bodyUsed getter steps are to return true if this’s body is non-null and this’s body’s stream is disturbed; otherwise false.

Environment

  • Tested with Node.js v18.12.1 without undici package
  • Tested with Node.js v18.12.1 and undici package v5.13.0
@tkrotoff tkrotoff added the bug Something isn't working label Dec 1, 2022
@ronag
Copy link
Member

ronag commented Dec 1, 2022

Chrome console disagrees:

<< const response = new Response()
>> undefined
<< response.bodyUsed
>> false
<< await response.text()
>> ''
<< response.bodyUsed
>> false

You can only have bodyUsed if there is a body, the default constructed Response has no body.

@tkrotoff
Copy link
Author

tkrotoff commented Dec 1, 2022

You are right, I'm sorry about this bad issue

FYI it's node-fetch & whatwg-fetch that are not spec compliant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants