]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: compression: Test payload size only if content-length is specified
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 18 Sep 2025 07:08:11 +0000 (09:08 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 25 Sep 2025 08:16:53 +0000 (10:16 +0200)
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.

src/flt_http_comp.c

index 1de08ebba6cada49186374fd6cbf7ecdacc7294f..1d5ea88c219506977843ca870f41e0a6b34df667 100644 (file)
@@ -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);