Enabling "Transfer-Encoding : chunked"

Maxim Dounin mdounin at mdounin.ru
Mon Sep 24 15:04:39 UTC 2018


Hello!

On Mon, Sep 24, 2018 at 09:53:26AM -0400, anish10dec wrote:

> In order to support CMAF and Low latency for HLS streaming through Nginx, it
> is required change in content header.
> 
> Instead of "Content-Length" in Header , expected value by player is
> "Transfer-Encoding : chunked" so that for a 6 sec chunk of media segment
> player will start streaming fetching data in 200 msec part wise and thus
> streaming will have low latency . This is supported by HTTP 1.1 
> 
> Tried below parameter to enable same in Nginx Configuration  
> chunked_transfer_encoding on;
> 
> But its not adding the same in header. 
> 
> Please suggest better way to do it. 
> https://gist.github.com/CMCDragonkai/6bfade6431e9ffb7fe88

The text you are referring to is misleading.

There is no difference between "Content-Length" and 
"Transfer-Encoding: chunked" from the streaming point of view, 
except that with "Content-Length" the client knows expected full 
response size in advance.  Nothing stops the client from rendering 
responses with "Content-Length" once data arrives.  If your client 
for some reason requires "Transfer-Encoding: chunked", it looks 
like a bug and/or misfeature of the particular client.

The only case when it makes sense to use "Transfer-Encoding: 
chunked" is when the full response length is not known in advance, 
and hence "Content-Length" cannot be used.

As for low-latency HLS streaming, the key part is that 
"Transfer-Encoding: chunked" is used by the encoder to return 
already available parts of the currently-being-produced HLS 
segment.  As the segment is not yet complete, its full length is 
not known and hence "Content-Length" cannot be used in the 
response.

For this to work, you'll need appropriate support in your HLS 
encoder - that is, it needs to return the last segment via HTTP 
while the segment is being produced.  If nginx is used to proxy 
such requests, everything is expected to work out of the box - 
nginx will use "Transfer-Encoding: chunked" as the length of the 
response is not known.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx mailing list