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

RESOLVED FIXED in Firefox 59



3 years ago
a month ago


(Reporter: xidorn, Assigned: xidorn)


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


Firefox Tracking Flags

(firefox59 fixed)



(1 attachment)



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.

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.

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:

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


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)

Comment 10

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

Comment 11

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

Comment 13

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

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

Comment 14

a year ago
Pushed by
Accept null for body param in constructor of Response. r=bkelly

Comment 15

a year ago
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:
* Adding a note to the Fx59 rel notes:

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

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.