specified, a UUID version 4 (fully random) is returned.
Currently, only version 4 is supported.
-var(<var-name>) : undefined
+var(<var-name>[,<default>]) : undefined
Returns a variable with the stored type. If the variable is not set, the
- sample fetch fails. The name of the variable starts with an indication
- about its scope. The scopes allowed are:
+ sample fetch fails, unless a default value is provided, in which case it will
+ return it as a string. Empty strings are permitted. The name of the variable
+ starts with an indication about its scope. The scopes allowed are:
"proc" : the variable is shared with the whole process
"sess" : the variable is shared with the whole session
"txn" : the variable is shared with the transaction (request and
haproxy h1 -conf {
global
+ # note below, str60 is purposely not defined so that the default is used
set-var proc.int12 int(12)
- set-var proc.int5 str(60),div(proc.int12)
+ set-var proc.int5 var(proc.str60,60),div(proc.int12)
set-var proc.str1 str("this is")
set-var proc.str2 str("a string")
set-var proc.str var(proc.str1)
static int smp_fetch_var(const struct arg *args, struct sample *smp, const char *kw, void *private)
{
const struct var_desc *var_desc = &args[0].data.var;
+ const struct buffer *def = NULL;
- return vars_get_by_desc(var_desc, smp, NULL);
+ if (args[1].type == ARGT_STR)
+ def = &args[1].data.str;
+
+ return vars_get_by_desc(var_desc, smp, def);
}
/* This function search in the <head> a variable with the same
static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
- { "var", smp_fetch_var, ARG1(1,STR), smp_check_var, SMP_T_STR, SMP_USE_CONST },
+ { "var", smp_fetch_var, ARG2(1,STR,STR), smp_check_var, SMP_T_STR, SMP_USE_CONST },
{ /* END */ },
}};