]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: add bc_http_major
authorJérôme Magnin <jmagnin@haproxy.com>
Fri, 7 Dec 2018 08:03:11 +0000 (09:03 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 7 Dec 2018 14:34:39 +0000 (15:34 +0100)
This adds the sample fetch bc_http_major. It returns the backend connection's HTTP
version encoding, which may be 1 for HTTP/0.9 to HTTP/1.1 or 2 for HTTP/2.0. It is
based on the on-wire encoding, and not the version present in the request header.

doc/configuration.txt
src/connection.c

index e6678c17c52ff48171c39ef346aa61d686d12916..2d7fb68879feddef09906c909f7e0a99e0a5eede 100644 (file)
@@ -14352,6 +14352,11 @@ table may be specified with the "sc*" form, in which case the currently
 tracked key will be looked up into this alternate table instead of the table
 currently being tracked.
 
+bc_http_major: integer
+  Returns the backend connection's HTTP major version encoding, which may be 1
+  for HTTP/0.9 to HTTP/1.1 or 2 for HTTP/2. Note, this is based on the on-wire
+  encoding and not the version present in the request header.
+
 be_id : integer
   Returns an integer containing the current backend's id. It can be used in
   frontends with responses to check which backend processed the request.
index 054e1998fd2e7c2769322f5062236817bd58adf6..2b0063e6a9d407c921ad591bc84af65e628d7df3 100644 (file)
@@ -1258,7 +1258,8 @@ int make_proxy_line_v2(char *buf, int buf_len, struct server *srv, struct connec
 static int
 smp_fetch_fc_http_major(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
-       struct connection *conn = objt_conn(smp->sess->origin);
+       struct connection *conn = (kw[0] != 'b') ? objt_conn(smp->sess->origin) :
+                                                                               smp->strm ? cs_conn(objt_cs(smp->strm->si[1].end)) : NULL;
 
        smp->data.type = SMP_T_SINT;
        smp->data.u.sint = (conn && strcmp(conn_get_mux_name(conn), "H2") == 0) ? 2 : 1;
@@ -1293,6 +1294,7 @@ int smp_fetch_fc_rcvd_proxy(const struct arg *args, struct sample *smp, const ch
  */
 static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
        { "fc_http_major", smp_fetch_fc_http_major, 0, NULL, SMP_T_SINT, SMP_USE_L4CLI },
+       { "bc_http_major", smp_fetch_fc_http_major, 0, NULL, SMP_T_SINT, SMP_USE_L4SRV },
        { "fc_rcvd_proxy", smp_fetch_fc_rcvd_proxy, 0, NULL, SMP_T_BOOL, SMP_USE_L4CLI },
        { /* END */ },
 }};