Skip to content

Allow body to be consumed only once#7

Merged
dgraham merged 4 commits into
masterfrom
body-used
Oct 15, 2014
Merged

Allow body to be consumed only once#7
dgraham merged 4 commits into
masterfrom
body-used

Conversation

@dgraham

@dgraham dgraham commented Oct 15, 2014

Copy link
Copy Markdown
Contributor

This branch enforces Section 5.2 of the spec, which describes how the bodyUsed attribute restricts consuming the body more than once.

fetch('/users').then(function(response) {
  // This promise resolves with the json object.
  var works = response.json()
  // This promise now rejects with a TypeError.
  var fails = response.text()
})

/cc @annevk on spec compliance here

Comment thread fetch.js Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should always return a promise. return error ? Promise.reject(err) : Promise.resolve(...)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jk i didn't look up. hahaha

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the name probably wasn't great. I just changed it from error to rejected to match expectations about its type.

dgraham added a commit that referenced this pull request Oct 15, 2014
Allow body to be consumed only once
@dgraham dgraham merged commit c80dc20 into master Oct 15, 2014
@dgraham dgraham deleted the body-used branch October 15, 2014 16:14
@dgraham

dgraham commented Oct 15, 2014

Copy link
Copy Markdown
Contributor Author

@annevk I'm working on a branch where the body is resolved later than the initial response promise. Right now, it's resolving the response in an XHR onload handler, so it has the full body as well.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants