]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http-ana: Save the message version in the http_msg structure
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 25 Feb 2026 15:10:28 +0000 (16:10 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 5 Mar 2026 14:34:46 +0000 (15:34 +0100)
When the request or the response is received, the numerical value of the
message version is now saved. To do so, the field "vsn" was added in the
http_msg structure. It is an unsigned char. The 4 MSB bits are used for the
major digit and the 4 LSB bits for the minor one.

Of couse, the version must be valid. the HTX_SL_F_NOT_HTTP flag of the
start-line is used to be sure the version is valid. But because this flag is
quite new, we also take care the string representation of the version is 8
bytes length. 0 means the version is not valid.

include/haproxy/http_ana-t.h
src/http_ana.c

index aa496e394fc92e220c1dfe6769846ce71160c23b..56b9e5b83ea03b59885eee5c6051783d5989083a 100644 (file)
@@ -228,7 +228,8 @@ enum h1_state {
  */
 struct http_msg {
        enum h1_state msg_state;               /* where we are in the current message parsing */
-       /* 3 bytes unused here */
+       unsigned char vsn;                     /* HTTP version, 4 bits per digit */
+       /* 2 bytes unused here */
        unsigned int flags;                    /* flags describing the message (HTTP version, ...) */
        struct channel *chn;                   /* pointer to the channel transporting the message */
 };
index fa061b69824a8231d919ae8228cbf3eb5776cf50..399c75906821a3fe0f0a9c3f75f0a51b8efaa0b1 100644 (file)
@@ -97,7 +97,6 @@ int http_wait_for_request(struct stream *s, struct channel *req, int an_bit)
        struct htx *htx;
        struct htx_sl *sl;
        char http_ver;
-       int len;
 
        DBG_TRACE_ENTER(STRM_EV_STRM_ANA|STRM_EV_HTTP_ANA, s, txn, msg);
 
@@ -131,14 +130,16 @@ int http_wait_for_request(struct stream *s, struct channel *req, int an_bit)
 
        htx = htxbuf(&req->buf);
        sl = http_get_stline(htx);
-       len = HTX_SL_REQ_VLEN(sl);
-       if (len < 6) {
+       if ((sl->flags & HTX_SL_F_NOT_HTTP) || HTX_SL_REQ_VLEN(sl) != 8) {
+               /* Not an HTTP request */
                http_ver = 0;
+               msg->vsn = 0;
        }
        else {
                char *ptr;
 
                ptr = HTX_SL_REQ_VPTR(sl);
+               msg->vsn = ((ptr[5] - '0') << 4) + (ptr[7] - '0');
                http_ver = ptr[5] - '0';
        }
 
@@ -1470,6 +1471,18 @@ int http_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
        BUG_ON(htx_get_first_type(htx) != HTX_BLK_RES_SL);
        sl = http_get_stline(htx);
 
+       if ((sl->flags & HTX_SL_F_NOT_HTTP) || HTX_SL_RES_VLEN(sl) != 8)  {
+               /* Not an HTTP response */
+               msg->vsn = 0;
+       }
+       else {
+               /* HTTP response from a server, use it to set the response version */
+               char *ptr;
+
+               ptr = HTX_SL_RES_VPTR(sl);
+               msg->vsn = ((ptr[5] - '0') << 4) + (ptr[7] - '0');
+       }
+
        /* Adjust server's health based on status code. Note: status codes 501
         * and 505 are triggered on demand by client request, so we must not
         * count them as server failures.