1
votes

I'm trying to get varnish cache response to be chunked... (that's possible, right?)

I have the following scenario:

1 - cache is clean, good to go (service varnish restart)

2 - access the www.mywebsite.com/page for the first time

First time access headers

(no content-length is returned, and chunking is there, great!)

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

2+ time access headers

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

After reading some Varnish docs/blogs (and this: http://book.varnish-software.com/4.0/chapters/VCL_Basics.html), looks like there are two "last" returns: return(fetch) or return(deliver).

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

I've tried adding these to my default.vcl file:

set beresp.do_esi = true; (at vcl_backend_response stage)

and

unset beresp.http.content-length; (at different stages, without success)

So.. how to have Varnish caching working with Transfer-Encoding: chunked?

Thanks for your attention!

1

1 Answers

1
votes

Is there a reason why you want to send it chunked? Chunked transfer encoding is kind of a clumsy workaround for when the content length isn't known ahead of time. What's actually happening here is Varnish is able to compute the length of the gzipped content after caching it for the first time, and so doesn't have to use the workaround! Rest assured that you are not missing out on any performance gains in this scenario.