From: Maxime Henrion Date: Fri, 26 Jun 2026 20:45:23 +0000 (-0400) Subject: MINOR: cache: allow opting out of early hints at the rule level X-Git-Url: http://git.kaiwu.me/web/doc/static/gitweb.js?a=commitdiff_plain;h=954614c03abc745cbdbfab85b442500b8bf3979e;p=haproxy.git MINOR: cache: allow opting out of early hints at the rule level A "cache-use" directive can now specify the "no-early-hints" keyword to suppress 103 Early Hints emission for matching requests, when used with a cache that has the "early-hints" setting enabled. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 5e0625d5a..f25c46005 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -15418,7 +15418,7 @@ cache-store See section 6.2 about cache setup. -cache-use +cache-use [no-early-hints] Usable in: QUIC Ini| TCP RqCon| RqSes| RqCnt| RsCnt| HTTP Req| Res| Aft - | - | - | - | - | X | - | - @@ -15427,6 +15427,12 @@ cache-use use a condition for both storage and delivering that's a good idea to put it after this one. + When the named cache has "early-hints" enabled, lookups handled by this + rule may emit a 103 Early Hints response if the requested URL has known + "Link" hints in the cache. The optional "no-early-hints" keyword + suppresses 103 emission for requests handled by this rule, regardless of + the cache-level setting. + See section 6.2 about cache setup. @@ -20251,8 +20257,9 @@ early-hints cannot serve the full response from the cache but the URL's "Link" hints are still known, the cache emits a 103 Early Hints response carrying those hints before forwarding the request to the backend, giving the client a - head start on fetching subresources while the backend produces the body. The - default value is off (disabled). + head start on fetching subresources while the backend produces the body. + Individual "cache-use" rules may opt out of this behavior with the + "no-early-hints" keyword. The default value is off (disabled). max-age Define the maximum expiration duration. The expiration is set as the lowest diff --git a/src/cache.c b/src/cache.c index d5dad45d6..6b2e8c28d 100644 --- a/src/cache.c +++ b/src/cache.c @@ -2544,7 +2544,8 @@ enum act_return http_action_req_cache_use(struct act_rule *rule, struct proxy *p shctx_row_detach(shctx, entry_block); detached = 1; } else { - if ((cache->flags & CACHE_CF_EARLY_HINTS) && + /* p[1] holds the "no-early-hints" opt-out set by parse_cache_use(). */ + if ((cache->flags & CACHE_CF_EARLY_HINTS) && !rule->arg.act.p[1] && (res->flags & (CACHE_EF_STRIPPED | CACHE_EF_COMPLETE))) { /* The emitted hints are best-effort and may not exactly * match the response finally served: with Vary they may @@ -2715,6 +2716,14 @@ enum act_parse_ret parse_cache_use(const char **args, int *orig_arg, struct prox return ACT_RET_PRS_ERR; (*orig_arg)++; + + /* Stash the "no-early-hints" opt-out in p[1], read back by + * http_action_req_cache_use() to skip 103 emission. */ + if (*args[*orig_arg] && strcmp(args[*orig_arg], "no-early-hints") == 0) { + rule->arg.act.p[1] = (void *)(uintptr_t)1; + (*orig_arg)++; + } + return ACT_RET_PRS_OK; }