2

I'm making a simple GET request using the Fetch API and the response has:

Transfer-Encoding: chunked

The network inspector in the Firefox dev tools shows me a chunk (a partial JSON response) in the payload, but I can't figure out how to access it in JavaScript.

Interestingly, even though the response status is 200, response.ok is false.

So how can I access the payload?

2
  • I observe the same behavior. It seems browsers don't properly implement fetch for Transfer-Encoding: chunked responses. I will try to just return the response without specifying that transfer encoding and without separating chunks, just sending data slowly over the tcp socket... Commented Mar 26, 2022 at 17:53
  • 1
    hmm, I got it working by using CORS properly, i.e. removing mode: 'no-cors', Commented Mar 26, 2022 at 18:29

1 Answer 1

1

You might be able to use the fetch response's body field, which is a stream like object with support for streaming reads. As long as you're reading data you've received, you should be OK to process it in a streaming manner.

Here is an example of using the Reader associated with the body stream to read chunks.

Sign up to request clarification or add additional context in comments.

2 Comments

unfortunately, response.body is undefined, which was the surprise that sent me here. I should have mentioned that.
Does that change when you receive the whole response?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.