I'm currently working on a Varnish (v3) set up, but I was wondering if anyone had any advice on the following.
I'm trying to use PHP's Header() function to set a custom header, for example, Test: CustomHeader. The ultimate aim is to allow Varnish to serve cached pages UNLESS a browser, in this case, has added something to a shopping basket. I was thinking that in my VCL config file, I can do something like:
if (bereq.http.Test ~ "CustomHeader") {
set beresp.ttl = 0s;
return (hit_for_pass);
}
However, this is always evaluate as false\no match. If I set it to
if (bereq.http.Test != "CustomHeader") {
set beresp.ttl = 0s;
return (hit_for_pass);
}
Then hit_for_pass is always triggered, which leads me to believe there's something amiss with my header setting. I thought it might be because the PHP header won't be set due to the whole point of the cache, but examining the headers in varnishlog DOES show the customer header appearing though, which is confusing! Additionally, accessing the page in question always performs a cache hit. Does anyone have any tips\advice on this kind of header manipulation in Varnish? Many thanks -B