Varnish 'client.ip' not available in method 'vcl_backend_response'
The field client
isn’t available in the backend worker thread in Varnish v4.x.
As a work around, you can store the client’s IP (or in this case probably just the fact that they passed the ACL check) in req.http
as a new header, and then you can access that same header via bereq.http
from your vcl_backend_response
subroutine:
sub vcl_recv {
set req.http.foo = client.ip;
}
sub vcl_backend_response {
set beresp.http.Some-Header = bereq.http.foo;
}
You need to generally be careful when using information from the original request in vcl_backend_response
, as there’s a chance that a response prepared (and cached) for one user might end up getting re-used (served from the cache) for another.