]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: mux-h2: don't reject an empty DATA frame ending a bodyless response
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 3 Dec 2026 14:04:43 +0000 (15:04 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 4 Dec 2026 13:53:05 +0000 (14:53 +0100)
On the backend side, a HEAD response (or a 204/304) may announce a
content-length and be ended by an empty DATA frame with the END_STREAM
flag. It is valid (RFC 9113 #8.1.1). But h2c_handle_data() reported "ES
on DATA frame before content-length" in this case: the stream was reset
with a PROTOCOL_ERROR, a glitch was counted and the stream protocol
errors counter was incremented. The response itself was properly
forwarded because h2_frt_transfer_data() already handled this case.
However, with "tune.h2.be.glitches-threshold", a compliant server could
lose its connection.

Now, like for the END_STREAM flag on the HEADERS frame, the content-length
check is skipped for bodyless responses on the backend side.

The reg-test http_bodyless_response.vtc was extended to check the stream
protocol errors counter of the H2 backend. The HEAD responses received from
the H2 server were already in this case.

This patch should be backported to all stable versions.

reg-tests/http-messaging/http_bodyless_response.vtc
src/mux_h2.c

index e54782e37438a306998df7906a286ff351ffa774..55f6986747b0038f80266cdca8b23d5eec6b5615 100644 (file)
@@ -128,3 +128,11 @@ client c2 -connect ${h1_fe2_sock} {
         expect resp.status == 200
         expect resp.body == "last response"
 } -run
+
+# The H2 server may end a bodyless response announcing a content-length with
+# an empty DATA frame carrying ES. It must not be reported as a protocol
+# error.
+haproxy h1 -cli {
+        send "show stat fe2 2 -1 typed"
+        expect ~ "B\\.[0-9.]*h2_detected_strm_protocol_errors\\.1:MCPV:u64:0\n"
+}
index e91fe679ca6d7ef2f5d539a60d52460cfcd315ab..18f20ec1be5c32ba42ebf8fd61d5246b22f0c166 100644 (file)
@@ -4148,7 +4148,11 @@ static int h2c_handle_data(struct h2c *h2c, struct h2s *h2s)
                else
                        h2s_close(h2s);
 
-               if (h2s->flags & H2_SF_DATA_CLEN && h2s->body_len) {
+               /* Note that bodyless only applies to responses, even when
+                * reported on the request (e.g. HEAD).
+                */
+               if ((h2s->flags & H2_SF_DATA_CLEN) && h2s->body_len &&
+                   (!(h2c->flags & H2_CF_IS_BACK) || !(h2s->flags & H2_SF_BODYLESS_RESP))) {
                        /* RFC7540#8.1.2 */
                        h2c_report_glitch(h2c, 1, "ES on DATA frame before content-length");
                        TRACE_ERROR("ES on DATA frame before content-length", H2_EV_RX_FRAME|H2_EV_RX_DATA, h2c->conn, h2s);