]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: sample: add h2_enabled to report whether H2 may be used on frontends
authorWilly Tarreau <w@1wt.eu>
Mon, 12 Oct 2026 18:52:49 +0000 (18:52 +0000)
committerWilly Tarreau <w@1wt.eu>
Tue, 17 Nov 2026 10:08:46 +0000 (11:08 +0100)
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.

doc/configuration.txt
src/sample.c

index 55e8725ba634d40fedd2f75230c39fe211fa9399..ede927fc07e995b166006dbeb6d7171892c586a5 100644 (file)
@@ -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 <number>
   Sets the threshold for the number of glitches on a frontend connection, where
@@ -24991,6 +24992,7 @@ env(<name>)                                        string
 fe_conn([<frontend>])                              integer
 fe_req_rate([<frontend>])                          integer
 fe_sess_rate([<frontend>])                         integer
+h2_enabled                                         boolean
 hostname                                           string
 int(<integer>)                                     signed
 ipv4(<ipv4>)                                       ipv4
@@ -25282,6 +25284,13 @@ fe_sess_rate([<frontend>]) : 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.
 
index 1cde534d8891dd79a538b7575aecbca1e600c24a..a9dfcdb1c81fc2e18825d0a9282ed44997c962dc 100644 (file)
@@ -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 },