]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MEDIUM: cache: do not store unused HTX blocks with the headers
authorOlivier Houchard <ohouchard@haproxy.com>
Thu, 3 Dec 2026 10:30:40 +0000 (11:30 +0100)
committerOlivier Houchard <cognet@ci0.org>
Thu, 3 Dec 2026 10:21:05 +0000 (11:21 +0100)
When a response is stored, http_action_store_cache() copies all the
blocks of the headers, including the unused ones left by a removed
header, such as after "http-response del-header" or "set-header" on a
header which is not the last one. When the object is served, the applet
tries to add this empty block again, which htx_add_blk() refuses since
commit 58ce50527 ("MINOR: htx: never create, leave nor accept an empty
HTX block"), so each cache hit ends with a 500.

Skip the unused blocks when storing the headers. This can be tested
with "http-response del-header X-Test" before "http-response
cache-store", and a server sending X-Test followed by another header:
the second request for the same URL gets a 500.

This should fix github issue #3616. It must be backported to 3.5.

src/cache.c

index 8b390a83081e70721ba2fb7c5be60d2edab69e9f..525c1b3c1bc41f92854bf7792b35b4294117579e 100644 (file)
@@ -1883,6 +1883,9 @@ enum act_return http_action_store_cache(struct act_rule *rule, struct proxy *px,
                        uint32_t sz = htx_get_blksz(blk);
                        struct ist header_name = IST_NULL;
 
+                       if (type == HTX_BLK_UNUSED)
+                               continue;
+
                        /* The cache serves its copies with a freshly computed
                         * Age, so the Age headers are not stored. They are left
                         * in the response which is forwarded as-is.