Naive use of regsub to set req.backend

Poul-Henning Kamp phk at phk.freebsd.dk
Mon May 5 21:41:16 CEST 2008


In message <481F5ED4.6030705 at openfares.com>, Pierre Fortin Carrier writes:

>  backend LB {
>    set backend.host = "10.0.0.1";
>    set backend.port = "8080";
>  }
>
>  backend node1 {
>[...]
>      set req.backend = regsub(req.http.host, "\.webapp\.example\.com", "");

The bad news for this approach is that in VCL variables have types.
Some variables are time-intervals, obj.ttl for instance, others are
backends, like req.backend and some are strings (req.http.*)

The reason I have chosen this approach, is that it allows things to
be checked much more carefully at compile time.

Your example above could lead to a req.backend being set to a backend
which was not declared in VCL, resulting in a run-time error when
a request happened to hit that condition.

With VCL variable typing, that is simply not possible, as you saw.
(Admittedly, the error message could be better).

I agree that the if elseif elseif elseif... thing can become quite
tedious but I don't have a good way to avoid it.

I thought about having a way to set the backend to a string and
if the string didn't match any of the available backends a default
backend would be used (to avoid the run-time error) but it is not
obvious to me how useful that would be.

-- 
Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
phk at FreeBSD.ORG         | TCP/IP since RFC 956
FreeBSD committer       | BSD since 4.3-tahoe    
Never attribute to malice what can adequately be explained by incompetence.



More information about the varnish-misc mailing list