Varnish return(fetch/deliver) vs chunked encoding
<p>I'm trying to get varnish cache response to be chunked... (that's possible, right?)</p>

<p>I have the following scenario: </p>

<p><strong>1 - cache is clean, good to go (service varnish restart)</strong></p>

<p><strong>2 - access the www.mywebsite.com/page for the first time</strong></p>

<p><a href="https://i.stack.imgur.com/ejwwJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ejwwJ.png" alt="First time access headers"></a></p>

<p>(no content-length is returned, and chunking is there, great!)</p>

<p><strong>3 - the next time I access the page (like simple reloading) it will be cached.. and now I get this:</strong></p>

<p><a href="https://i.stack.imgur.com/MLH3B.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MLH3B.png" alt="2+ time access headers"></a></p>

<p>(now we have content-length... which means no chunking :( not great!) </p>

<p>After reading some Varnish docs/blogs (and this: <a href="http://book.varnish-software.com/4.0/chapters/VCL_Basics.html" rel="nofollow noreferrer">http://book.varnish-software.com/4.0/chapters/VCL_Basics.html</a>), looks like there are two "last" returns: <strong>return(fetch)</strong> or <strong>return(deliver)</strong>. </p>

<p>When forcing a <strong>return(fetch)</strong>, the chunked encoding works... but it also means that the request won't be cached, right? While <strong>return(deliver)</strong> caches correctly but adds the content-length header.</p>

<p>I've tried adding these to my default.vcl file:</p>

<pre><code>set beresp.do_esi = true; (at vcl_backend_response stage)
</code></pre>

<p>and</p>

<pre><code>unset beresp.http.content-length; (at different stages, without success)
</code></pre>

<p><strong>So.. how to have Varnish caching working with Transfer-Encoding: chunked?</strong> </p>

<p>Thanks for your attention! </p>