diff --git a/include/haproxy/mux_h1-t.h b/include/haproxy/mux_h1-t.h index 23b5822186..8d4c3a4add 100644 --- a/include/haproxy/mux_h1-t.h +++ b/include/haproxy/mux_h1-t.h @@ -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; diff --git a/src/mux_h1.c b/src/mux_h1.c index d600c78f8c..36a55f9765 100644 --- a/src/mux_h1.c +++ b/src/mux_h1.c @@ -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"),