title: How do I disable 'Transfer-Encoding: chunked' encoding in Varnish?
body: <p>Using <a href="https://www.varnish-cache.org/content/varnish-cache-400" rel="noreferrer">Varnish 4</a>, I have a set of backends that're responding with a valid <code>Content-Length</code> header and no <code>Transfer-Encoding</code> header.</p>
  
  <p>On the first hit from a client, rather than responding to the client with those headers, Varnish is dropping the <code>Content-Length</code> header and adding <code>Transfer-Encoding: chunked</code> to the response.  (Interestingly, the payload doesn't appear to have any chunks in it - it's one contiguous payload).</p>
  
  <p>This causes serious problems for clients like Flash video players that are trying to do segment-size, bandwidth, etc analysis based on the <code>Content-Length</code> header.  Their analysis fails, and they can't do things like multi-bitrate streaming, etc.</p>
  
  <p>I've tried a number of semi-obvious things like: </p>
  
  <ul>
  <li><code>beresp.do_stream = true</code> </li>
  <li><code>beresp.do_gzip = false</code></li>
  <li><code>unset req.http.Accept-Encoding</code></li>
  </ul>
  
  <p>Sample backend response:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Cache-Control: public, max-age=600
  Content-Type: video/mp4
  Date: Tue, 13 May 2014 19:44:35 GMT
  Server: Apache
  Content-Length: 796618
  Connection: keep-alive
  </code></pre>
  
  <p>Sample varnish response:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Server: Apache
  Cache-Control: public, max-age=600
  Content-Type: video/mp4
  Date: Tue, 13 May 2014 23:10:06 GMT
  X-Varnish: 2
  Age: 0
  Transfer-Encoding: chunked
  Accept-Ranges: bytes
  </code></pre>
  
  <p>Subsequent loads of the object <em>do</em> including the <code>Content-Length</code> header, just not the first load into cache.</p>
  
  <p>VCL: <a href="https://gist.github.com/onethumb/e64a405cc579909cace1" rel="noreferrer">https://gist.github.com/onethumb/e64a405cc579909cace1</a></p>
  
  <p>varnishlog output: <a href="https://gist.github.com/onethumb/e66a2bc4727a3a5340b6" rel="noreferrer">https://gist.github.com/onethumb/e66a2bc4727a3a5340b6</a></p>
  
  <p>Varnish Trac: <a href="https://www.varnish-cache.org/trac/ticket/1506" rel="noreferrer">https://www.varnish-cache.org/trac/ticket/1506</a></p>