]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MEDIUM: compression: Don't forget to update htx_sl and http_msg flags
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 15 Apr 2022 13:32:03 +0000 (15:32 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 15 Apr 2022 14:22:33 +0000 (16:22 +0200)
If the response is compressed, we must update the HTX start-line flags and
the HTTP message flags. It is especially important if there is another
filter enabled. Otherwise, there is no way to know the C-L header was
removed and T-E one was added. Except by looping on headers.

This patch is related to the issue #1660. It must backported as far as 2.0
(for HTX part only).

src/flt_http_comp.c

index 08f684e511fda5d982f96c08bcf09d70ac7a810f..cac7dc04be8225620e360d279616af7dd150d340 100644 (file)
@@ -301,6 +301,7 @@ static int
 set_compression_response_header(struct comp_state *st, struct stream *s, struct http_msg *msg)
 {
        struct htx *htx = htxbuf(&msg->chn->buf);
+       struct htx_sl *sl;
        struct http_hdr_ctx ctx;
 
        /*
@@ -316,17 +317,25 @@ set_compression_response_header(struct comp_state *st, struct stream *s, struct
                        goto error;
        }
 
+       sl = http_get_stline(htx);
+       if (!sl)
+               goto error;
+
        /* remove Content-Length header */
        if (msg->flags & HTTP_MSGF_CNT_LEN) {
                ctx.blk = NULL;
                while (http_find_header(htx, ist("Content-Length"), &ctx, 1))
                        http_remove_header(htx, &ctx);
+               msg->flags &= ~HTTP_MSGF_CNT_LEN;
+               sl->flags &= ~HTX_SL_F_CLEN;
        }
 
        /* add "Transfer-Encoding: chunked" header */
        if (!(msg->flags & HTTP_MSGF_TE_CHNK)) {
                if (!http_add_header(htx, ist("Transfer-Encoding"), ist("chunked")))
                        goto error;
+               msg->flags |= HTTP_MSGF_TE_CHNK;
+               sl->flags |= (HTX_SL_F_XFER_ENC|HTX_SL_F_CHNK);
        }
 
        /* convert "ETag" header to a weak ETag */