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.
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"
+}
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);