]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: mux-h1: Rely on a H1S flag to know a WS key was found or not
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 2 Nov 2022 07:42:08 +0000 (08:42 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 17 Nov 2022 13:33:15 +0000 (14:33 +0100)
h1_process_mux() is written to allow partial headers formatting. For now,
all headers are forwarded in one time. But it is still good to keep this
ability at the H1 mux level. So we must rely on a H1S flag instead of a
local variable to know a WebSocket key was found in headers to be able to
generate a key if necessary.

There is no reason to backport this patch.

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

index 23b5822186cc80da12610e0480204aabe099ea06..8d4c3a4add9fd3ce9e347f0286d8246255af7c62 100644 (file)
@@ -101,6 +101,7 @@ static forceinline char *h1c_show_flags(char *buf, size_t len, const char *delim
 
 #define H1S_F_HAVE_SRV_NAME  0x00002000 /* Set during output process if the server name header was added to the request */
 #define H1S_F_HAVE_O_CONN    0x00004000 /* Set during output process to know connection mode was processed */
+#define H1S_F_HAVE_WS_KEY    0x00008000 /* Set during output process to know WS key was found or generated */
 
 /* This function is used to report flags in debugging tools. Please reflect
  * below any single-bit flag addition above in the same order via the
@@ -116,7 +117,7 @@ static forceinline char *h1s_show_flags(char *buf, size_t len, const char *delim
        _(H1S_F_WANT_KAL, _(H1S_F_WANT_TUN, _(H1S_F_WANT_CLO,
        _(H1S_F_NOT_FIRST, _(H1S_F_BODYLESS_RESP,
        _(H1S_F_INTERNAL_ERROR, _(H1S_F_NOT_IMPL_ERROR, _(H1S_F_PARSING_ERROR, _(H1S_F_PROCESSING_ERROR,
-       _(H1S_F_HAVE_SRV_NAME, _(H1S_F_HAVE_O_CONN))))))))))))));
+       _(H1S_F_HAVE_SRV_NAME, _(H1S_F_HAVE_O_CONN, _(H1S_F_HAVE_WS_KEY)))))))))))))));
        /* epilogue */
        _(~0U);
        return buf;
index d600c78f8cf087fb8e1a4721470ab90f0db8ce12..36a55f976527cf86316dcf89f8371e51990352f2 100644 (file)
@@ -1938,7 +1938,6 @@ static size_t h1_process_mux(struct h1c *h1c, struct buffer *buf, size_t count)
        struct buffer tmp;
        size_t total = 0;
        int last_data = 0;
-       int ws_key_found = 0;
 
        chn_htx = htxbuf(buf);
        TRACE_ENTER(H1_EV_TX_DATA, h1c->conn, h1s, chn_htx, (size_t[]){count});
@@ -2150,7 +2149,7 @@ static size_t h1_process_mux(struct h1c *h1c, struct buffer *buf, size_t count)
                                          h1m->flags & H1_MF_RESP) ||
                                         (isteq(n, ist("sec-websocket-key")) &&
                                          !(h1m->flags & H1_MF_RESP))) {
-                                       ws_key_found = 1;
+                                       h1s->flags |= H1S_F_HAVE_WS_KEY;
                                }
                                else if (isteq(n, ist("te"))) {
                                        /* "te" may only be sent with "trailers" if this value
@@ -2251,8 +2250,8 @@ static size_t h1_process_mux(struct h1c *h1c, struct buffer *buf, size_t count)
                                }
 
                                /* Add websocket handshake key if needed */
-                               if ((h1m->flags & (H1_MF_CONN_UPG|H1_MF_UPG_WEBSOCKET)) == (H1_MF_CONN_UPG|H1_MF_UPG_WEBSOCKET) &&
-                                   !ws_key_found) {
+                               if (!(h1s->flags & H1S_F_HAVE_WS_KEY) &&
+                                   (h1m->flags & (H1_MF_CONN_UPG|H1_MF_UPG_WEBSOCKET)) == (H1_MF_CONN_UPG|H1_MF_UPG_WEBSOCKET)) {
                                        if (!(h1m->flags & H1_MF_RESP)) {
                                                /* generate a random websocket key
                                                 * stored in the session to
@@ -2276,6 +2275,7 @@ static size_t h1_process_mux(struct h1c *h1c, struct buffer *buf, size_t count)
                                                        goto full;
                                                }
                                        }
+                                       h1s->flags |= H1S_F_HAVE_WS_KEY;
                                }
 
                                TRACE_PROTO((!(h1m->flags & H1_MF_RESP) ? "H1 request headers xferred" : "H1 response headers xferred"),