From: Christopher Faulet Date: Tue, 1 Dec 2026 14:31:07 +0000 (+0100) Subject: MINOR: h1: preserve version and method flags when restarting on output_full X-Git-Url: https://git.kaiwu.me/web/http/static/%7B@url%7D?a=commitdiff_plain;h=2cd436ff576aa816c5d1d2cb928bf2d850e59813;p=haproxy.git MINOR: h1: preserve version and method flags when restarting on output_full When the conversion of the parsed headers into HTX does not fit in the destination, h1_postparse_req_hdrs() and h1_postparse_res_hdrs() reset the message parser state to restart the parsing once the destination was drained. But the reset dropped some flags not derived from the message itself: on the response side, the HEAD or CONNECT method flags set by the mux from the request, and the version flag, which is only set by the mux for a response without start line (FCGI). On the next parsing they would not be set again: for a FCGI response, the version is never re-derived from the message, so the synthesized start line could get the wrong HTTP version, and a response to a HEAD request could be framed with a body. On the request side, the version flag is preserved too, for consistency. This cannot be triggered today: the reset is only reachable on the H1 side, where the mux sets the method flags again before each parsing attempt and the parser sets the version flag from the start line, and a FCGI response cannot hit output_full (there is only one response per stream, so the destination HTX is empty when its headers are parsed, and a too large message takes the error path instead). This is a hardening aligning the reset with the restart convention of h1_headers_to_hdr_list() (H1_MF_RESTART_MASK plus H1_MF_VER_11). --- diff --git a/src/h1_htx.c b/src/h1_htx.c index d4d2df56a..10838b12b 100644 --- a/src/h1_htx.c +++ b/src/h1_htx.c @@ -291,9 +291,11 @@ static int h1_postparse_req_hdrs(struct h1m *h1m, union h1_sl *h1sl, struct htx output_full: /* The connection header values may have been cleaned up, so the - * corresponding flags must be preserved for the next parsing. + * corresponding flags must be preserved for the next parsing. The + * version flag is preserved for consistency with the restart of the + * parsing in h1_headers_to_hdr_list(). */ - flags = h1m->flags & (H1_MF_CONN_CLO|H1_MF_CONN_KAL); + flags = h1m->flags & (H1_MF_CONN_CLO|H1_MF_CONN_KAL|H1_MF_VER_11); lenient = (h1m->err_pos >= -1); h1m_init_req(h1m); h1m->flags |= (H1_MF_NO_PHDR|H1_MF_CLEAN_CONN_HDR|flags); @@ -434,9 +436,13 @@ static int h1_postparse_res_hdrs(struct h1m *h1m, union h1_sl *h1sl, struct htx output_full: /* The connection header values may have been cleaned up, so the - * corresponding flags must be preserved for the next parsing. + * corresponding flags must be preserved for the next parsing. The + * flags set by the mux from the request (version, HEAD or CONNECT + * method) must also be preserved: there is no start line in a FCGI + * response, so they are never re-set by the parsing in this case. */ - flags = h1m->flags & (H1_MF_CONN_CLO|H1_MF_CONN_KAL); + flags = h1m->flags & (H1_MF_CONN_CLO|H1_MF_CONN_KAL|H1_MF_VER_11| + H1_MF_METH_HEAD|H1_MF_METH_CONNECT); lenient = (h1m->err_pos >= -1); h1m_init_res(h1m); h1m->flags |= (H1_MF_NO_PHDR|H1_MF_CLEAN_CONN_HDR|flags);