mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-23 06:41:32 +02:00
MINOR: acl: add the new "env()" fetch method to retrieve an environment variable
This is useful in order to take different actions across restarts without touching the configuration (eg: soft-stop), or to pass some information such as the local host name to the next hop.
This commit is contained in:
parent
3c4beb1feb
commit
595ec54d38
@ -8795,6 +8795,20 @@ connslots([<backend>]) : integer
|
|||||||
then this fetch clearly does not make sense, in which case the value returned
|
then this fetch clearly does not make sense, in which case the value returned
|
||||||
will be -1.
|
will be -1.
|
||||||
|
|
||||||
|
env(<name>) : string
|
||||||
|
Returns a string containing the value of environment variable <name>. As a
|
||||||
|
reminder, environment variables are per-process and are sampled when the
|
||||||
|
process starts. This can be useful to pass some information to a next hop
|
||||||
|
server, or with ACLs to take specific action when the process is started a
|
||||||
|
certain way.
|
||||||
|
|
||||||
|
Examples :
|
||||||
|
# Pass the Via header to next hop with the local hostname in it
|
||||||
|
http-request add-header Via 1.1\ %[env(HOSTNAME)]
|
||||||
|
|
||||||
|
# reject cookie-less requests when the STOP environment variable is set
|
||||||
|
http-request deny if !{ cook(SESSIONID) -m found } { env(STOP) -m found }
|
||||||
|
|
||||||
fe_conn([<frontend>]) : integer
|
fe_conn([<frontend>]) : integer
|
||||||
Returns the number of currently established connections on the frontend,
|
Returns the number of currently established connections on the frontend,
|
||||||
possibly including the connection being evaluated. If no frontend name is
|
possibly including the connection being evaluated. If no frontend name is
|
||||||
|
21
src/acl.c
21
src/acl.c
@ -1980,6 +1980,26 @@ smp_fetch_false(struct proxy *px, struct session *s, void *l7, unsigned int opt,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* retrieve environment variable $1 as a string */
|
||||||
|
static int
|
||||||
|
smp_fetch_env(struct proxy *px, struct session *s, void *l7, unsigned int opt,
|
||||||
|
const struct arg *args, struct sample *smp)
|
||||||
|
{
|
||||||
|
char *env;
|
||||||
|
|
||||||
|
if (!args || args[0].type != ARGT_STR)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
env = getenv(args[0].data.str.str);
|
||||||
|
if (!env)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
smp->type = SMP_T_CSTR;
|
||||||
|
smp->data.str.str = env;
|
||||||
|
smp->data.str.len = strlen(env);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************/
|
/************************************************************************/
|
||||||
/* All supported sample and ACL keywords must be declared here. */
|
/* All supported sample and ACL keywords must be declared here. */
|
||||||
@ -1993,6 +2013,7 @@ smp_fetch_false(struct proxy *px, struct session *s, void *l7, unsigned int opt,
|
|||||||
static struct sample_fetch_kw_list smp_kws = {{ },{
|
static struct sample_fetch_kw_list smp_kws = {{ },{
|
||||||
{ "always_false", smp_fetch_false, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN },
|
{ "always_false", smp_fetch_false, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN },
|
||||||
{ "always_true", smp_fetch_true, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN },
|
{ "always_true", smp_fetch_true, 0, NULL, SMP_T_BOOL, SMP_USE_INTRN },
|
||||||
|
{ "env", smp_fetch_env, ARG1(1,STR), NULL, SMP_T_CSTR, SMP_USE_INTRN },
|
||||||
{ /* END */ },
|
{ /* END */ },
|
||||||
}};
|
}};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user