]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: compression: Add a flag to know the filter is still processing data
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 9 Jun 2021 15:12:44 +0000 (17:12 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 10 Jun 2021 06:57:55 +0000 (08:57 +0200)
Since the commit acfd71b97 ("BUG/MINOR: http-comp: Preserve
HTTP_MSGF_COMPRESSIONG flag on the response"), there is no more flag to know
when the compression ends. This means it is possible to finish the
compression several time if there are trailers.

So, we reintroduce almost the same mechanism but with a dedicated flag. So
now, there is a bits field in the compression filter context.

The commit above is marked to be backported as far as 2.0. Thus this patch
must also be backported as far as 2.0.

src/flt_http_comp.c

index e7bfa6d5f96d474acb45032bd0ea9fe29b2e6a92..774b982e4ef7e0a43c4619504dc729e0e6d42797 100644 (file)
@@ -25,6 +25,8 @@
 #include <haproxy/stream.h>
 #include <haproxy/tools.h>
 
+#define COMP_STATE_PROCESSING 0x01
+
 const char *http_comp_flt_id = "compression filter";
 
 struct flt_ops comp_ops;
@@ -32,6 +34,7 @@ struct flt_ops comp_ops;
 struct comp_state {
        struct comp_ctx  *comp_ctx;   /* compression context */
        struct comp_algo *comp_algo;  /* compression algorithm if not NULL */
+       unsigned int      flags;      /* COMP_STATE_* */
 };
 
 /* Pools used to allocate comp_state structs */
@@ -93,6 +96,7 @@ comp_strm_init(struct stream *s, struct filter *filter)
 
        st->comp_algo = NULL;
        st->comp_ctx  = NULL;
+       st->flags     = 0;
        filter->ctx   = st;
 
        /* Register post-analyzer on AN_RES_WAIT_HTTP because we need to
@@ -135,6 +139,7 @@ comp_http_headers(struct stream *s, struct filter *filter, struct http_msg *msg)
                        if (!set_compression_response_header(st, s, msg))
                                goto end;
                        register_data_filter(s, msg->chn, filter);
+                       st->flags |= COMP_STATE_PROCESSING;
                }
        }
 
@@ -183,6 +188,9 @@ comp_http_payload(struct stream *s, struct filter *filter, struct http_msg *msg,
                while (next && htx_get_blk_type(next) == HTX_BLK_UNUSED)
                        next = htx_get_next_blk(htx, next);
 
+               if (!(st->flags & COMP_STATE_PROCESSING))
+                       goto consume;
+
                if (htx_compression_buffer_init(htx, &trash) < 0) {
                        msg->chn->flags |= CF_WAKE_WRITE;
                        goto end;
@@ -214,6 +222,8 @@ comp_http_payload(struct stream *s, struct filter *filter, struct http_msg *msg,
                                len -= ret;
                                consumed += ret;
                                to_forward += b_data(&trash);
+                               if (last)
+                                       st->flags &= ~COMP_STATE_PROCESSING;
                                break;
 
                        case HTX_BLK_TLR:
@@ -230,6 +240,7 @@ comp_http_payload(struct stream *s, struct filter *filter, struct http_msg *msg,
                                        next = htx_get_next_blk(htx, blk);
                                        to_forward += b_data(&trash);
                                }
+                               st->flags &= ~COMP_STATE_PROCESSING;
                                /* fall through */
 
                        default: