]> git.kaiwu.me - haproxy.git/commitdiff
MINOR: cache: add config options for early hints support
authorMaxime Henrion <mhenrion@haproxy.com>
Thu, 28 May 2026 20:41:02 +0000 (16:41 -0400)
committerWilly Tarreau <w@1wt.eu>
Fri, 10 Jul 2026 14:42:35 +0000 (16:42 +0200)
Support for 103 early hints responses can now be enabled at the HTTP
cache level with "early-hints on" - defaults to off.

doc/configuration.txt
src/cache.c

index b76c7541feb8a3162f38f9914beec488dd28cc21..5e0625d5afb6a491e8b42a9d434811968ad2769a 100644 (file)
@@ -20243,6 +20243,17 @@ cache <name>
   Declare a cache section, allocate a shared cache memory named <name>, the
   size of cache is mandatory (see keyword "total-max-size" below).
 
+early-hints <on/off>
+  Enable or disable support for HTTP 103 Early Hints responses (see RFC 8297).
+  When enabled, the cache remembers relevant "Link" response headers (with a
+  "rel" parameter of preload, preconnect, dns-prefetch, modulepreload or
+  prefetch) seen on cached responses. When a subsequent "cache-use" lookup
+  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).
+
 max-age <seconds>
   Define the maximum expiration duration. The expiration is set as the lowest
   value between the s-maxage or max-age (in this order) directive in the
index 5ede3472fde07b26da6829d1fd65e01bafc01d84..8a03a3021f8400f9f1c9409909670391924e62ee 100644 (file)
@@ -46,6 +46,7 @@
 
 /* Flags for configuration. */
 #define CACHE_CF_VARY_PROCESSING   0x00000001 /* manage Vary header (disabled by default) */
+#define CACHE_CF_EARLY_HINTS       0x00000002 /* enable HTTP 103 Early Hints (disabled by default) */
 
 static uint64_t cache_hash_seed = 0;
 
@@ -2432,6 +2433,21 @@ int cfg_parse_cache(const char *file, int linenum, char **args, int kwm)
                                   file, linenum, args[0]);
                        err_code |= ERR_WARN;
                }
+       } else if (strcmp(args[0], "early-hints") == 0) {
+               if (alertif_too_many_args(1, file, linenum, args, &err_code)) {
+                       err_code |= ERR_ABORT;
+                       goto out;
+               }
+
+               if (strcmp(args[1], "on") == 0) {
+                       tmp_cache_config->flags |= CACHE_CF_EARLY_HINTS;
+               } else if (strcmp(args[1], "off") == 0) {
+                       tmp_cache_config->flags &= ~CACHE_CF_EARLY_HINTS;
+               } else {
+                       ha_warning("parsing [%s:%d]: '%s' expects \"on\" or \"off\" (enable or disable HTTP 103 Early Hints support).\n",
+                                  file, linenum, args[0]);
+                       err_code |= ERR_WARN;
+               }
        } else if (strcmp(args[0], "max-secondary-entries") == 0) {
                unsigned int max_sec_entries;
                char *err;