2

I've read about chunked encoding in few places, but still don't quite get why for example a Radio streaming server such as this one sends its data as chunked Transfer-Encoding. A client of such server just continuously reads data from the server. It doesn't in any point needs to know how much data is currently being sent since it is always consuming data (as long as it stays connected).

It seems that the client doesn't use these pieces of data, he just discards them, which adds more job for him.. Can anyone explain this to me?

1 Answer 1

2

HTTP/1.1 needs to either send a Content-Length, or chunked encoding. If you can't know the length, you must use chunked encoding. A continuous stream would in theory have an infinite length.

A HTTP client needs either of these to know when the response ends. After the respons a new HTTP request could be sent.

You are correct that in the case of a continuous stream it's not needed to detect when the stream ends, because it doesn't. It could have been possible for the authors of HTTP/1.1 to have a third 'continuous stream of bytes' option for HTTP. Perhaps that use-case wasn't considered all those years ago.

Note that HTTP/2 doesn't have chunked encoding anymore, but it does something similar and sends multiple body frames.

6
  • Content-Length is optional in HTTP/1.1. Missing Content-Length does not require the server to use chunked encoding. Commented Nov 10, 2022 at 6:38
  • @RememberMonica do you have a source for this?
    – Evert
    Commented Nov 10, 2022 at 16:22
  • As you made the claim that it is required, you would need to provide sources (e.g. cite the part in RFC 7231 that supports your claim). I merely pointed out that your answer isn't correct. Commented Nov 16, 2022 at 17:13
  • @RememberMonica rfc-editor.org/rfc/rfc7230#section-3.3.3
    – Evert
    Commented Nov 16, 2022 at 19:05
  • have you actually read that section? That section does not support your claim, to the contrary, it explicitly contradicts your claim in part 7 and further, which describes behaviour when neither is used, making that case required. Commented Nov 20, 2022 at 15:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.