From: Willy Tarreau Date: Mon, 12 Oct 2026 18:52:49 +0000 (+0000) Subject: MINOR: sample: add h2_enabled to report whether H2 may be used on frontends X-Git-Url: https://git.kaiwu.me/web/%22data:,/doc/static/gitweb.js?a=commitdiff_plain;h=d47985ccccadef2ce71b72a0c285c13c49be4d55;p=haproxy.git MINOR: sample: add h2_enabled to report whether H2 may be used on frontends With "tune.h2.fe.enabled" now able to disable HTTP/2 on frontends, users may need to adapt some of their rules depending on whether or not HTTP/2 may be served to clients (filtering, headers, thresholds, redirects etc), without having to keep them in sync by hand with the global setting. This adds the "h2_enabled" sample fetch, which works like "quic_enabled": it returns true only when HTTP/2 support was built in (USE_H2) and was not disabled on frontends by "tune.h2.fe.enabled off". This should be backported along with the "tune.h2.fe.enabled" setting. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 55e8725ba..ede927fc0 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -4876,7 +4876,8 @@ tune.h2.fe.enabled { on | off } adjusted when they are parsed, this setting must appear in the global section before the proxies, which is normally the case. - See also: "option disable-h2-upgrade", "alpn", "no-alpn", "proto" + See also: "option disable-h2-upgrade", "alpn", "no-alpn", "proto", and the + "h2_enabled" sample fetch. tune.h2.fe.glitches-threshold Sets the threshold for the number of glitches on a frontend connection, where @@ -24991,6 +24992,7 @@ env() string fe_conn([]) integer fe_req_rate([]) integer fe_sess_rate([]) integer +h2_enabled boolean hostname string int() signed ipv4() ipv4 @@ -25282,6 +25284,13 @@ fe_sess_rate([]) : integer tcp-request content accept if ! too_fast tcp-request content accept if WAIT_END +h2_enabled : boolean + Returns true when the support for HTTP/2 was compiled and if HTTP/2 is not + disabled on frontends by the "tune.h2.fe.enabled" global option. This may be + used to adapt some rules depending on whether HTTP/2 may be served to + clients or not, such as filtering, headers, thresholds or redirects. See also + the "tune.h2.fe.enabled" global option. + hostname : string Returns the system hostname. diff --git a/src/sample.c b/src/sample.c index 1cde534d8..a9dfcdb1c 100644 --- a/src/sample.c +++ b/src/sample.c @@ -5719,6 +5719,21 @@ smp_fetch_uptime(const struct arg *args, struct sample *smp, const char *kw, voi } +/* Check if HTTP/2 support was compiled and was not disabled on frontends by + * the "tune.h2.fe.enabled" global option. + */ +static int smp_fetch_h2_enabled(const struct arg *args, struct sample *smp, const char *kw, void *private) +{ + smp->data.type = SMP_T_BOOL; + smp->flags = 0; +#ifdef USE_H2 + smp->data.u.sint = !(global.tune.options2 & GTUNE2_DISABLE_H2_FE); +#else + smp->data.u.sint = 0; +#endif + return 1; +} + /* Check if QUIC support was compiled and was not disabled by "tune.quic.listen" global option */ static int smp_fetch_quic_enabled(const struct arg *args, struct sample *smp, const char *kw, void *private) { @@ -6024,6 +6039,7 @@ static struct sample_fetch_kw_list smp_kws = {ILH, { { "env", smp_fetch_env, ARG1(1,STR), NULL, SMP_T_STR, SMP_USE_CONST }, { "date", smp_fetch_date, ARG2(0,SINT,STR), smp_check_date_unit, SMP_T_SINT, SMP_USE_CONST }, { "date_us", smp_fetch_date_us, 0, NULL, SMP_T_SINT, SMP_USE_CONST }, + { "h2_enabled", smp_fetch_h2_enabled, 0, NULL, SMP_T_BOOL, SMP_USE_CONST }, { "hostname", smp_fetch_hostname, 0, NULL, SMP_T_STR, SMP_USE_CONST }, { "master_id", smp_fetch_master_id, 0, NULL, SMP_T_STR, SMP_USE_CONST }, { "nbproc", smp_fetch_nbproc,0, NULL, SMP_T_SINT, SMP_USE_CONST },