Simply put, Transfer-Encoding: chunked
, in a HTTP response header, tells us the body will be received in several chunks.
This is ideal in 2 scenarios:
- When the size of the body isn’t known in advance, like when generating output from a database.
- When the size of the body is too big to be fully loaded in RAM before being sent to the client.
In practice, the body has each of its chunks separated with X\r\n
, where X
is the size of the chunk in hexadecimal. For instance: