0

Varnish (running on fastly) is caching objects for longer than I (think I) have specified. To debug this issue, I'm adding headers everywhere in the following fashion:

sub vcl_miss {
  set req.http.Debugmiss = "vcl_miss";
#FASTLY miss
  return(fetch);
}
sub vcl_deliver {
#FASTLY deliver
  set resp.http.Debugmiss = req.http.Debugmiss;
  return(deliver);
}

I've done this for vcl_recv, vcl_hit, vcl_miss, vcl_pass, vcl_hash and vcl_fetch; however, the only functions that seem to be called according to the headers are vcl_recv (which does a lookup) and vcl_deliver. For example, according to the state diagram (https://www.varnish-software.com/book/3/_images/vcl.png) after vcl_recv returns the lookup code, the vcr_hash function should be called. If it is, it doesn't seem to set any headers.

Is there something I'm overlooking?

These are the response headers that curl returns:

< HTTP/1.1 200 OK
< Server: Cowboy
< X-Frame-Options: SAMEORIGIN
< X-Xss-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Access-Control-Allow-Origin: *
< Content-Type: application/json; charset=utf-8
< Etag: W/"9fbfd39142780bd83fed663b051c83d9"
< X-Request-Id: a2a9b83a-4143-4b40-b788-94969dd5ce91
< X-Runtime: 0.020195
< X-Rack-Cache: miss
< Via: 1.1 vegur
< Content-Length: 434
< Accept-Ranges: bytes
< Date: Wed, 02 Sep 2015 13:41:41 GMT
< Via: 1.1 varnish
< Age: 4
< Connection: keep-alive
< X-Served-By: cache-lhr6332-LHR
< X-Cache: HIT
< X-Cache-Hits: 1
< X-Timer: S1441201301.048931,VS0,VE2
< Cache-Control: no-cache, no-store, private, must-revalidate, max-age=0, max-stale=0, post-check=0, pre-check=0
< Expires: 0
< Pragma: no-cache
< Debugrecv: vcl_recv
< Debugrecvreturn: lookup
< debugme: vcl_deliver; desperate8

The entire vcl can be found here: https://gist.github.com/mdemare/2e0fa52e62691806e0a0

Michiel de Mare
  • 41,982
  • 29
  • 103
  • 134

1 Answers1

1

I think the problem is in the vcl functions where you set headers for req which is the request object, not the response. So when you look at the response headers, the ones set to the req object won't show up.

You can try either looking at the request headers or you can use varnishlog (more info)

Community
  • 1
  • 1
Redithion
  • 986
  • 1
  • 19
  • 32
  • In most vcl functions I don't have write access to the response object. In `vcl_deliver`, line 317-323, I copy the request headers to the response headers. That strategy seems to work for the `vcl_recv` function at least. – Michiel de Mare Sep 08 '15 at 09:08
  • 1
    I strongly recommend to use varnishlog for this kind of situations. Maybe that way you can even find why the headers are not showing up. – Redithion Sep 08 '15 at 12:58