Incorrect TypeError: Response body is given with a null body status.

RESOLVED FIXED in Firefox 59

Status

()

defect
P3
normal
RESOLVED FIXED
3 years ago
a month ago

People

(Reporter: xidorn, Assigned: xidorn)

Tracking

(Blocks 1 bug, {dev-doc-complete})

Trunk
mozilla59
Points:
---

Firefox Tracking Flags

(firefox59 fixed)

Details

Attachments

(1 attachment)

(Assignee)

Description

3 years ago
Steps to reproduce:
1. Open Web Console
2. Enter "new Response(null, {status: 204})"

Expected result:
return a Response object

Actual result:
TypeError: Response body is given with a null body status.


This is an issue for Fetch, but I have no idea what component Fetch belongs to, so just put in ServiceWorker.
(Assignee)

Comment 1

3 years ago
I guess the issue is at [1].

The spec says in [2]:
> If body is non-null, run these substeps:
but the code at [1] only checks whether the value is passed.


[1] https://dxr.mozilla.org/mozilla-central/rev/8a494adbc5cced90a4edf0c98cffde906bf7f3ae/dom/fetch/Response.cpp#194
[2] https://fetch.spec.whatwg.org/#dom-response
Xidorn, I believe null is being converted to "null" because BodyInit is not a nullable type and DOMString is one of its union types.  If you do this, then it works:

  var r = new Response(undefined, { status: 204 })

Does this make sense?
Flags: needinfo?(xidorn+moz)
And fetch just goes in Core/DOM
Component: DOM: Service Workers → DOM
Except the constructor itself has a nullable operator on the BodyInit type.
Flags: needinfo?(xidorn+moz)
Which we are missing in our webidl:

https://dxr.mozilla.org/mozilla-central/source/dom/webidl/Response.webidl#10

Seems we need `optional BodyInit? body` there.
Priority: -- → P3

Comment 6

a year ago
I too have run into this issue. Please refer to the following specs for fetch. The body getter must return null or stream, so 'undefined' will never occur [1]. Also the status reference for response says that it must be null for 101, 204, 205, or 304 [2]. And finally body is allowed to be null, and "body is said to be done if body is null or body’s stream is closed or errored" [3], So creating a Response with a body of 'undefined' is actually not "done" as the spec describes

[1] https://fetch.spec.whatwg.org/#dom-body-body
[2] https://fetch.spec.whatwg.org/#concept-status
[3] https://fetch.spec.whatwg.org/#concept-body

Comment 7

a year ago
noted that Chrome and Edge both allow null as the body when building a Response object

Comment 8

a year ago
Please ignore my previous comment. This is not about what other browsers allow, but rather how Firefox has implemented the standard. Cheers
Comment hidden (mozreview-request)
(Assignee)

Comment 10

a year ago
If there is no test checking this, I'll add a wpt later.
(Assignee)

Comment 11

a year ago
Looks like there is no such test at the moment...
Comment hidden (mozreview-request)

Comment 13

a year ago
mozreview-review
Comment on attachment 8942406 [details]
Bug 1303025 - Accept null for body param in constructor of Response.

https://reviewboard.mozilla.org/r/212712/#review218884

Thanks!
Attachment #8942406 - Flags: review?(bkelly) → review+

Comment 14

a year ago
Pushed by xquan@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/62f5c4a36823
Accept null for body param in constructor of Response. r=bkelly

Comment 15

a year ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/62f5c4a36823
Status: NEW → RESOLVED
Last Resolved: a year ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla59
Assignee: nobody → xidorn+moz
I've documented this by:

* Updating the description and support info on the constructor page: https://developer.mozilla.org/en-US/docs/Web/API/Response/Response
* Adding a note to the Fx59 rel notes: https://developer.mozilla.org/en-US/Firefox/Releases/59#DOM

Let me know if this is OK, thanks!
Flags: needinfo?(xidorn+moz)
(Assignee)

Comment 17

a year ago
Looks good, thanks.
Flags: needinfo?(xidorn+moz)
Component: DOM → DOM: Core & HTML
Product: Core → Core
You need to log in before you can comment on or make changes to this bug.