Determining the director used v3 to v5

Mark Hanford mark at
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 ( == "") {
        set req.backend = product1_randomdirector;
    if ( == "") {
        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 =;
    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

    if ( == "") {
        set req.backend_hint = product1_randomdirector.backend();
    if ( == "") {
        set req.backend_hint = product2_sharddirector.backend(KEY,

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`.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the varnish-misc mailing list