Varnish caching and the X-Requested-With header

Angelo Höngens A.Hongens at netmatch.nl
Thu Jun 16 14:33:40 CEST 2016


While talking to other peeps at varnishcon here I remembered I hadn't answered this issue. I solved it on my side back in Januari by overriding this behavior in vcl_recv. No idea though why varnish decided they were uncacheable in the first place.

sub vcl_recv {
  ..
  # By default varnish won't cache object with the X-Requested-With header, like
  # for AJAX requests. We will override this behaviour. NetMatch Ticket #43946
  if(req.http.X-Requested-With == "XMLHttpRequest") {
    return (hash);
  }
  ..
}

Angelo.


> Hi Angelo,
> 
> Your first step should be to look at the varnishlog, find the relevant
> request, and compare with what your vcl (and the builtin one) to understand
> the behaviour.
> 
> -- 
> Guillaume Quintard
> 
> On Thu, Jan 14, 2016 at 8:55 PM, Angelo Höngens <A.Hongens at netmatch.nl>
> wrote:
> 
>> Hey, I'm trying to debug varnish not caching some request. I see the
>> uncacheable object has the request header X-Requested-With: XMLHttpRequest,
>> and I guess that somehow make Varnish not cache the request. But I cannot
>> find this anywhere in the documentation. Is this expected behavior? In
>> which module (vcl_recv, vcl_deliver) can I undo this behavior?
>>
>> --
>>
>> With kind regards,
>>
>> Angelo Höngens
>> Systems Administrator





More information about the varnish-misc mailing list