From: Christopher Faulet Date: Thu, 3 Dec 2026 14:04:43 +0000 (+0100) Subject: BUG/MINOR: mux-h2: don't reject an empty DATA frame ending a bodyless response X-Git-Url: https://git.kaiwu.me/web/http/static//%22?a=commitdiff_plain;h=a7133aa892292c5271b04da59bbdb191d97d9876;p=haproxy.git BUG/MINOR: mux-h2: don't reject an empty DATA frame ending a bodyless response 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. --- diff --git a/reg-tests/http-messaging/http_bodyless_response.vtc b/reg-tests/http-messaging/http_bodyless_response.vtc index e54782e37..55f698674 100644 --- a/reg-tests/http-messaging/http_bodyless_response.vtc +++ b/reg-tests/http-messaging/http_bodyless_response.vtc @@ -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" +} diff --git a/src/mux_h2.c b/src/mux_h2.c index e91fe679c..18f20ec1b 100644 --- a/src/mux_h2.c +++ b/src/mux_h2.c @@ -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);