]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: cache: allow opting out of early hints at the rule level
authorMaxime Henrion <mhenrion@haproxy.com>
Fri, 26 Jun 2026 20:45:23 +0000 (16:45 -0400)
committerWilly Tarreau <w@1wt.eu>
Fri, 10 Jul 2026 14:42:35 +0000 (16:42 +0200)
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.

doc/configuration.txt
src/cache.c

index 5e0625d5afb6a491e8b42a9d434811968ad2769a..f25c460056dc233319363fd23717766291029958 100644 (file)
@@ -15418,7 +15418,7 @@ cache-store <name>
   See section 6.2 about cache setup.
 
 
-cache-use <name>
+cache-use <name> [no-early-hints]
   Usable in:  QUIC Ini|    TCP RqCon| RqSes| RqCnt| RsCnt|    HTTP Req| Res| Aft
                     - |          -  |   -  |   -  |   -  |          X |  - |  -
 
@@ -15427,6 +15427,12 @@ cache-use <name>
   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 <on/off>
   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 <seconds>
   Define the maximum expiration duration. The expiration is set as the lowest
index d5dad45d61807f1353b9332b72954f831c6032c0..6b2e8c28de0ac14a8be1e311b6f2bf1a03ef876a 100644 (file)
@@ -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;
 }