MINOR: mux-h1: Rely on a H1S flag to know a WS key was found or not

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.
This commit is contained in:
Christopher Faulet 2022-11-02 08:42:08 +01:00
parent 7f6aa56d47
commit 62138aab3e
2 changed files with 6 additions and 5 deletions

View 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;

View 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"),