Search code examples
javascriptfetch-apihttp-chunked

Does Fetch's Response.body chunks correspond to HTTP chunks?


I'm doing a Fetch-api request where the server replies using the HTTP chunked transfer encoding (with text data). I'm consuming the data using the Response.body as a stream.

I'm wondering: Is it safe to assume that the chunks generated by the stream correspond to the HTTP chunks? I've seen some questions[1-3] where this assumption seems to be made, but I cannot find anything about this in the spec.

[1] JS Fetch use Chunked Transfer Encoding (translating curl to Fetch)
[2] Consuming chunked data asyncrhonously in javascript
[3] Read chunked binary response with Fetch API


Solution

  • Per comments from the author of the Fetch spec: “no such guarantee… e.g., if there’s a delay after half of an HTTP chunk I’d expect two or so”.