From: Christopher Faulet Date: Thu, 18 Sep 2025 07:08:11 +0000 (+0200) Subject: BUG/MINOR: compression: Test payload size only if content-length is specified X-Git-Tag: v3.3-dev9~43 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=23e5d272af1b3125338c7ff45d0941d716f13a55;p=thirdparty%2Fhaproxy.git BUG/MINOR: compression: Test payload size only if content-length is specified When a minimum size is defined to performe the comression, the message payload size is tested. To do so, information from the HTX message a used to determine the message length. However it is performed regardless the payload length is fully known or not. Concretely, the test must on be performed when a content-length value was speficied or when the message was fully received (EOM flag set). Otherwise, we are unable to really determine the real payload length. Because of this bug, compression may be skipped for a large chunked message because the first chunks received are too small. But this does not mean the whole message is small. This patch must be backported to 3.2. --- diff --git a/src/flt_http_comp.c b/src/flt_http_comp.c index 1de08ebba..1d5ea88c2 100644 --- a/src/flt_http_comp.c +++ b/src/flt_http_comp.c @@ -151,8 +151,9 @@ comp_prepare_compress_request(struct comp_state *st, struct stream *s, struct ht comp_type = NULL; /* compress only if body size is >= than the min size */ - if ((s->be->comp && (comp_minsize = s->be->comp->minsize_req)) || - (strm_fe(s)->comp && (comp_minsize = strm_fe(s)->comp->minsize_req))) { + if (((msg->flags & HTTP_MSGF_CNT_LEN) || (htx->flags & HTX_FL_EOM)) && + ((s->be->comp && (comp_minsize = s->be->comp->minsize_req)) || + (strm_fe(s)->comp && (comp_minsize = strm_fe(s)->comp->minsize_req)))) { for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { struct htx_blk *blk = htx_get_blk(htx, pos); enum htx_blk_type type = htx_get_blk_type(blk); @@ -684,8 +685,9 @@ select_compression_response_header(struct comp_state *st, struct stream *s, stru goto fail; /* compress only if body size is >= than the min size */ - if ((s->be->comp && (comp_minsize = s->be->comp->minsize_res)) || - (strm_fe(s)->comp && (comp_minsize = strm_fe(s)->comp->minsize_res))) { + if (((msg->flags & HTTP_MSGF_CNT_LEN) || (htx->flags & HTX_FL_EOM)) && + ((s->be->comp && (comp_minsize = s->be->comp->minsize_res)) || + (strm_fe(s)->comp && (comp_minsize = strm_fe(s)->comp->minsize_res)))) { for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) { struct htx_blk *blk = htx_get_blk(htx, pos); enum htx_blk_type type = htx_get_blk_type(blk);