]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: h1: preserve version and method flags when restarting on output_full
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 1 Dec 2026 14:31:07 +0000 (15:31 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 3 Dec 2026 12:41:06 +0000 (13:41 +0100)
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).

src/h1_htx.c

index d4d2df56af49858752cd3d6412a0d0bfa29d6004..10838b12be6ef3ae85f4ea0c1dd6b500c9d94211 100644 (file)
@@ -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);