]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: cache: do not refuse to store responses with "Age: 0"
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 21 Oct 2026 08:35:47 +0000 (08:35 +0000)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 12 Nov 2026 17:20:31 +0000 (18:20 +0100)
Responses carrying an "Age: 0" header are never stored in the cache. This
header is commonly emitted by an upstream cache or CDN delivering an object
it just fetched, so in a setup chaining caches, the haproxy cache simply
never stores these objects and all requests for them reach the servers,
which only affects performance and the load of the servers.

The Age value is parsed with strl2llrc() and only accepted when strictly
positive, any other case jumping to the "out" label as an invalid value.
Zero is a perfectly valid Age value (RFC 9111#5.1), it is not stale and
needs no special treatment, so it is now accepted like positive values.
Negative or non-numerical values are still considered invalid.

This patch may be backported to all supported versions.

src/cache.c

index 834bb3720082ef3154516222bfe265e4ecd1e3c7..9000eb98ddec8f1aedf188d61afa7659a1114aa4 100644 (file)
@@ -1814,7 +1814,7 @@ enum act_return http_action_store_cache(struct act_rule *rule, struct proxy *px,
        ctx.blk = NULL;
        if (http_find_header(htx, ist("Age"), &ctx, 0)) {
                long long hdr_age;
-               if (!strl2llrc(ctx.value.ptr, ctx.value.len, &hdr_age) && hdr_age > 0) {
+               if (!strl2llrc(ctx.value.ptr, ctx.value.len, &hdr_age) && hdr_age >= 0) {
                        if (unlikely(hdr_age > CACHE_ENTRY_MAX_AGE))
                                hdr_age = CACHE_ENTRY_MAX_AGE;
                        /* A response with an Age value greater than its