Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Varnish: Misc

Adding header depending on if request was fetched or passed

 

 

Varnish misc RSS feed   Index | Next | Previous | View Threaded


connor.walls at skillpages

Aug 10, 2012, 1:49 AM

Post #1 of 2 (215 views)
Permalink
Adding header depending on if request was fetched or passed

Hi all,

So, as it stands we have the fairly common set up in our vcl_deliver to add a header to indicate whether or not the object was served from cache or not:

if (obj.hits > 0)
{
set resp.http.X-Cache = "HIT";
}
else
{
set resp.http.X-Cache = "MISS";
}

Now, in addition to this, I was wondering if it would be possible to add a header to indicate whether or not we attempted to fetch the object from cache, i.e. if the request had gone through vcl_fetch or vcl_pass. My initial thought was to add some form of header in those subroutines but obviously I'm not able to access resp here. Is there anything that obj would be able to tell me in vcl_deliver about this?

Thanks for any help,
Connor

_______________________________________________
varnish-misc mailing list
varnish-misc [at] varnish-cache
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc


hugo.cisneiros at gmail

Aug 10, 2012, 2:52 PM

Post #2 of 2 (201 views)
Permalink
Re: Adding header depending on if request was fetched or passed [In reply to]

On Fri, Aug 10, 2012 at 5:49 AM, Connor Walls
<connor.walls [at] skillpages> wrote:
> Hi all,
>
> So, as it stands we have the fairly common set up in our vcl_deliver to add a header to indicate whether or not the object was served from cache or not:
[...]
> Now, in addition to this, I was wondering if it would be possible to add a header to indicate whether or not we attempted to fetch the object from cache, i.e. if the request had gone through vcl_fetch or vcl_pass. My initial thought was to add some form of header in those subroutines but obviously I'm not able to access resp here. Is there anything that obj would be able to tell me in vcl_deliver about this?

Try setting http headers on vcl_miss (when it needs to fetch from
backend) and vcl_hit (when it doesn't). Then o vcl_deliver you set de
resp.http.* based on these. Example:

sub vcl_hit {
set req.http.X-Varnish-TTL = obj.ttl;
set req.http.X-Varnish-Cache = "hit";
}

sub vcl_miss {
set req.http.X-Varnish-TTL = 0;
set req.http.X-Varnish-Cache = "miss";
}

sub vcl_deliver {
set resp.http.X-Varnish-TTL = req.http.X-Varnish-TTL;
set resp.http.X-Varnish-Cache = req.http.X-Varnish-Cache;
}

--
[]'s
Hugo
www.devin.com.br

_______________________________________________
varnish-misc mailing list
varnish-misc [at] varnish-cache
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc

Varnish misc RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.