Determining the director used v3 to v5
Mark Hanford
mark at hanfordonline.co.uk
Wed Apr 5 17:17:07 CEST 2017
Hi folks. In order to make diagnostics easier, in v3 I would set some
headers so we could see in the browser how Varnish decided which Director
and backend to use.
So in vcl_recv, we would make all sorts of judgements based on host names
and urls etc, then set the backend to the relevant director:
if (req.host == "mydomain.com") {
set req.backend = product1_randomdirector;
}
if (req.host == "myotherdomain.com") {
set req.backend = product2_clientdirector;
}
....
set req.http.X-Director = req.backend;
And then later on in vcl_deliver, I would put that into information into a
header so we can see it in the browser (if it is a trusted IP):
set resp.http.X-Host = req.http.host;
set resp.http.X-Director = req.http.X-Director;
But in v5, I don't set the backend to a director, I set it to an actual
backend:
if (req.host == "mydomain.com") {
set req.backend_hint = product1_randomdirector.backend();
}
if (req.host == "myotherdomain.com") {
set req.backend_hint = product2_sharddirector.backend(KEY,
product2_sharddirector.key(req.http.X-Real-Ip));
}
How can I set a response header with the director that was chosen? I need
to be able to have tests that look at the X-Director for a give request, to
confirm the correct choices are being made. I'd rather not manually set a
header every time I use `set backend_hint`.
thanks,
Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20170405/882bea35/attachment.html>
More information about the varnish-misc
mailing list