How override/remove cache headers from backend?

Espen Braastad espen at linpro.no
Wed Dec 3 15:37:06 CET 2008


Hi,

I'm having a bit of a problem with a not-so-trustworthy backend which is 
sending the following headers:

[...]
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Vary: Accept-Encoding,Cookie
[...]

The goal is to get varnish to ignore/remove the headers and still put 
the element into cache. I've tried the following minimal configuration 
unsuccessfully:

[...]
sub vcl_recv {
    remove req.http.Cookie;
}

sub vcl_fetch {
    remove obj.http.Cache-control;
    remove obj.http.Expires;
    remove obj.http.Pragma;
    remove obj.http.Vary;
    deliver;
}
[...]

This configuration strips the headers *after* varnish determines if the 
element should be put in cache or not; something like:

1. Fetching element from backend.
2. Determine if element should be put in cache => in this case don't.
3. Remove the headers.
4. Deliver element to client (without the cache headers).


Is there a way to manipulate reply headers from the backend before 
varnish decides whether or not to put the element into cache?



The complete varnishlog from one request (with the previous mentioned 
configuration):

    9 SessionOpen  c 10.0.0.2 59453 0.0.0.0:80
    9 ReqStart     c 10.0.0.2 59453 683810183
    9 RxRequest    c GET
    9 RxURL        c /page/Main_Page
    9 RxProtocol   c HTTP/1.1
    9 RxHeader     c Connection: close
    9 RxHeader     c Host: www.example.com
    9 RxHeader     c User-Agent: lwp-request/2.08
    9 VCL_call     c recv
    9 VCL_return   c lookup
    9 VCL_call     c hash
    9 VCL_return   c hash
    9 VCL_call     c miss
    9 VCL_return   c fetch
   10 BackendClose - default
   10 BackendOpen  b default 127.0.0.1 47939 127.0.0.1 8080
    9 Backend      c 10 default default
   10 TxRequest    b GET
   10 TxURL        b /page/Main_Page
   10 TxProtocol   b HTTP/1.1
   10 TxHeader     b Host: www.example.com
   10 TxHeader     b User-Agent: lwp-request/2.08
   10 TxHeader     b X-Varnish: 683810183
   10 TxHeader     b X-Forwarded-For: 10.0.0.2
   10 RxProtocol   b HTTP/1.1
   10 RxStatus     b 200
   10 RxResponse   b OK
   10 RxHeader     b Date: Wed, 03 Dec 2008 14:28:14 GMT
   10 RxHeader     b Server: Apache
   10 RxHeader     b Content-language: en
   10 RxHeader     b Vary: Accept-Encoding,Cookie
   10 RxHeader     b Expires: Thu, 01 Jan 1970 00:00:00 GMT
   10 RxHeader     b Cache-Control: no-cache, no-store, max-age=0, 
must-revalidate
   10 RxHeader     b Pragma: no-cache
   10 RxHeader     b Transfer-Encoding: chunked
   10 RxHeader     b Content-Type: text/html; charset=utf-8
    9 ObjProtocol  c HTTP/1.1
    9 ObjStatus    c 200
    9 ObjResponse  c OK
    9 ObjHeader    c Date: Wed, 03 Dec 2008 14:28:14 GMT
    9 ObjHeader    c Server: Apache
    9 ObjHeader    c Content-language: en
    9 ObjHeader    c Vary: Accept-Encoding,Cookie
    9 ObjHeader    c Expires: Thu, 01 Jan 1970 00:00:00 GMT
    9 ObjHeader    c Cache-Control: no-cache, no-store, max-age=0, 
must-revalidate
    9 ObjHeader    c Pragma: no-cache
    9 ObjHeader    c Content-Type: text/html; charset=utf-8
   10 BackendReuse b default
    9 TTL          c 683810183 RFC 0 1228314496 0 0 0 0
    9 VCL_call     c fetch
    9 VCL_return   c deliver
    9 Length       c 18524
    9 VCL_call     c deliver
    9 VCL_return   c deliver
    9 TxProtocol   c HTTP/1.1
    9 TxStatus     c 200
    9 TxResponse   c OK
    9 TxHeader     c Server: Apache
    9 TxHeader     c Content-language: en
    9 TxHeader     c Content-Type: text/html; charset=utf-8
    9 TxHeader     c Content-Length: 18524
    9 TxHeader     c Date: Wed, 03 Dec 2008 14:28:16 GMT
    9 TxHeader     c X-Varnish: 683810183
    9 TxHeader     c Age: 0
    9 TxHeader     c Via: 1.1 varnish
    9 TxHeader     c Connection: close
    9 ReqEnd       c 683810183 1228314494.178344011 1228314496.532316923 
0.001534939 2.351898909 0.002074003
    9 SessionClose c Connection: close
    9 StatSess     c 10.0.0.2 59453 2 1 1 0 0 1 224 18524

Thanks,

-- 
Espen Braastad
Redpill Linpro AB - Changing the game
Kontor:  +47 21 54 41 37





More information about the varnish-misc mailing list