whatwg / fetch

Fetch Standard
https://fetch.spec.whatwg.org/
Other
2.12k stars 332 forks source link

Response body being null on 204/205/304 etc doesn't match any implementation #1779

Open noamr opened 1 month ago

noamr commented 1 month ago

What is the issue with the Fetch Standard?

As per the standard, Response.body returns null if the body is null, https://fetch.spec.whatwg.org/#dom-body-body and https://fetch.spec.whatwg.org/#ref-for-null-body-status. However, no browser implements this. In all the implementations, a 204/205/304 response etc. would result in a Response.body of an empty stream.

Perhaps the fetch spec should be fixed to reflect implemented reality?

annevk commented 1 month ago

It's unfortunate to not reflect the actual HTTP semantics, but it's probably okay? We do return null in certain cases though (new Response().body), so it's a bit weird.

noamr commented 1 month ago

It's unfortunate to not reflect the actual HTTP semantics, but it's probably okay? We do return null in certain cases though (new Response().body), so it's a bit weird.

Yea thinking to spec it so that an http null body status would end up with an empty stream, but Response.body would still account for null like today.