]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: connection: report the major HTTP version from the MUX for logging (fc_http_major)
authorWilly Tarreau <w@1wt.eu>
Fri, 18 Aug 2017 13:26:54 +0000 (15:26 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 17:03:23 +0000 (18:03 +0100)
A new sample fetch function reports either 1 or 2 for the on-wire encoding,
to indicate if the request was received using the HTTP/1.x format or HTTP/2
format. Note that it reports the on-wire encoding, not the version presented
in the request header.

This will possibly have to evolve if it becomes necessary to report the
encoding on the server side as well.

doc/configuration.txt
src/connection.c

index 8ee56e417efe13936496ccc789afbd82f194ac23..0ef8103a63aff97545a59d9825330eee9bf1a8ba 100644 (file)
@@ -13591,6 +13591,11 @@ dst_port : integer
   a same server, or to pass the destination port information to a server using
   an HTTP header.
 
+fc_http_major : integer
+  Reports the front 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 on the version present in the request header.
+
 fc_rcvd_proxy : boolean
   Returns true if the client initiated the connection with a PROXY protocol
   header.
index 43ec32878e4acdc7a8727e797f0802721bd99c7d..b61a9dd847a7db9d40628b2e363145e3f24b94ae 100644 (file)
@@ -1077,6 +1077,19 @@ int make_proxy_line_v2(char *buf, int buf_len, struct server *srv, struct connec
        return ret;
 }
 
+/* return the major HTTP version as 1 or 2 depending on how the request arrived
+ * before being processed.
+ */
+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);
+
+       smp->data.type = SMP_T_SINT;
+       smp->data.u.sint = (conn && strcmp(conn_get_mux_name(conn), "H2") == 0) ? 2 : 1;
+       return 1;
+}
+
 /* fetch if the received connection used a PROXY protocol header */
 int smp_fetch_fc_rcvd_proxy(const struct arg *args, struct sample *smp, const char *kw, void *private)
 {
@@ -1104,6 +1117,7 @@ int smp_fetch_fc_rcvd_proxy(const struct arg *args, struct sample *smp, const ch
  * instance v4/v6 must be declared v4.
  */
 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 },
        { "fc_rcvd_proxy", smp_fetch_fc_rcvd_proxy, 0, NULL, SMP_T_BOOL, SMP_USE_L4CLI },
        { /* END */ },
 }};