haproxy/reg-tests/sample_fetches
Willy Tarreau 54496a6a5b MINOR: vars: make the vars() sample fetch function support a default value
It is quite common to see in configurations constructions like the
following one:

    http-request set-var(txn.bodylen) 0
    http-request set-var(txn.bodylen) req.hdr(content-length)
    ...
    http-request set-header orig-len %[var(txn.bodylen)]

The set-var() rules are almost always duplicated when manipulating
integers or any other value that is mandatory along operations. This is
a problem because it makes the configurations complicated to maintain
and slower than needed. And it becomes even more complicated when several
conditions may set the same variable because the risk of forgetting to
initialize it or to accidentally reset it is high.

This patch extends the var() sample fetch function to take an optional
argument which contains a default value to be returned if the variable
was not set. This way it becomes much simpler to use the variable, just
set it where needed, and read it with a fall back to the default value:

    http-request set-var(txn.bodylen) req.hdr(content-length)
    ...
    http-request set-header orig-len %[var(txn.bodylen,0)]

The default value is always passed as a string, thus it will experience
a cast to the output type. It doesn't seem userful to complicate the
configuration to pass an explicit type at this point.

The vars.vtc regtest was updated accordingly.
2021-09-03 12:08:54 +02:00
..
cook.vtc
hashes.vtc REGTESTS: mark sample_fetches/hashes.vtc as 2.4-only 2021-02-04 18:07:59 +01:00
so_name.vtc
srv_name.vtc
ubase64.vtc REGTESTS: disable inter-thread idle connection sharing on sensitive tests 2021-05-09 14:41:41 +02:00
vars.vtc MINOR: vars: make the vars() sample fetch function support a default value 2021-09-03 12:08:54 +02:00