I have the following VCL file:
vcl 4.0;
import std;
import directors;
backend one {
.host = "localhost";
.port = "3333";
}
backend two {
.host = "127.0.0.1";
.port = "3334";
}
sub vcl_init {
new random_director = directors.random();
random_director.add_backend(one, 10); # 2/3 to backend one
random_director.add_backend(two, 5); # 1/3 to backend two
}
sub vcl_recv {
set req.backend_hint = random_director.backend();
std.log(req.backend_hint.host);
}
The concept is that I want to re-write the req.url after randomly assigning the user to a backend.
So when a new user arrives, they will be randomly assigned to a backend. Then I will add some logic with an if statement to re-write the URL path one way if they are assigned to backed one, and another way if they are assigned to backend two.
My problem is that after the line
set req.backend_hint = random_director.backend();
I can't figure out which backend the user got assigned to. In other words, I don't know how to examine req.backend_hint.
I tried to use
std.log(req.backend_hint.host);
but that throws a compilation error (not a STRING_LIST).
The example I have above is adapted from here: http://book.varnish-software.com/4.0/chapters/Saving_a_Request.html
So, my question is: how can I inspect req.backend_hint?