Skip to content

Conversation

@bneradt
Copy link
Contributor

@bneradt bneradt commented Nov 20, 2025

This adds support for targeted Cache-Control headers (like CDN-Cache-Control) that allow cache directives to be targeted at specific caches. The implementation includes a configurable, priority-ordered list of targeted headers via proxy.config.http.cache.targeted_cache_control_headers, which is overridable per-remap rule. When a targeted header is present, it takes precedence over the standard Cache-Control header for caching decisions. Targeted headers are passed through downstream to allow proper cache hierarchy behavior.

Fixes: #9113

@bneradt bneradt added this to the 10.2.0 milestone Nov 20, 2025
@bneradt bneradt self-assigned this Nov 20, 2025
@zwoop zwoop requested review from Copilot and zwoop November 20, 2025 20:06
Copilot finished reviewing on behalf of zwoop November 20, 2025 20:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements RFC 9213 Targeted HTTP Cache Control, allowing cache directives to be targeted at specific caches through custom headers (e.g., CDN-Cache-Control). When configured, these targeted headers take precedence over standard Cache-Control for caching decisions, while still being passed through to downstream caches.

Key changes:

  • Added configurable, priority-ordered list of targeted cache control headers via proxy.config.http.cache.targeted_cache_control_headers
  • Modified cache control parsing logic to check targeted headers first before falling back to standard Cache-Control
  • Made configuration overridable per-remap rule for flexible deployment scenarios

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/proxy/hdrs/MIME.cc Core cache control parsing logic updated to check targeted headers in priority order
src/proxy/http/HttpSM.cc Integration point where targeted headers config is passed to cache control recomputation
include/proxy/hdrs/MIME.h Added flag to track if cache control came from targeted header; updated signature
src/records/RecordsConfig.cc Added new configuration record for targeted headers
src/proxy/http/HttpConfig.cc Config initialization and reconfiguration handling with proper memory management
include/proxy/http/HttpConfig.h Added char* field for targeted headers config
src/shared/overridable_txn_vars.cc Made config overridable for per-transaction use
src/api/InkAPI.cc API support for reading/writing targeted headers config; added char** converter
src/api/InkAPITest.cc Added new config key to API test list
plugins/lua/ts_lua_http_config.cc Added Lua plugin support for the new config
include/ts/apidefs.h.in Added enum value for new config key
tests/gold_tests/cache/targeted-cache-control.test.py Test harness for RFC 9213 functionality
tests/gold_tests/cache/replay/targeted-cache-control.replay.yaml Comprehensive test scenarios covering priority, fallback, and per-remap override
doc/admin-guide/files/records.yaml.en.rst Configuration reference documentation
doc/admin-guide/configuration/cache-basics.en.rst User guide with examples and use cases
doc/developer-guide/api/types/TSOverridableConfigKey.en.rst API enum documentation
doc/developer-guide/api/functions/TSHttpOverridableConfig.en.rst API function documentation
doc/admin-guide/plugins/lua.en.rst Lua plugin constant documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 3733 to 3752
field = nullptr;

// Check for targeted cache control headers first (in priority order).
if (targeted_headers_str && *targeted_headers_str) {
swoc::TextView config_view{targeted_headers_str};
while (config_view) {
swoc::TextView header_name = config_view.take_prefix_at(',').trim_if(&isspace);
if (!header_name.empty()) {
field = mime_hdr_field_find(this, std::string_view{header_name.data(), header_name.size()});
if (field) {
// Found a targeted header! Mark it and stop searching.
m_cooked_stuff.m_cache_control.m_from_targeted_header = true;
break;
}
}
}
}

// If no targeted header was found, fall back to standard Cache-Control.
if (!field) {
field = mime_hdr_field_find(this, static_cast<std::string_view>(MIME_FIELD_CACHE_CONTROL));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actualy interesting production change (part 1).

Comment on lines +2069 to +2075
// Recompute cooked cache control with targeted headers (pass nullptr if not configured).
const char *targeted_headers =
(t_state.txn_conf->targeted_cache_control_headers && t_state.txn_conf->targeted_cache_control_headers[0] != '\0') ?
t_state.txn_conf->targeted_cache_control_headers :
nullptr;
t_state.hdr_info.server_response.m_mime->recompute_cooked_stuff(nullptr, targeted_headers);

Copy link
Contributor Author

@bneradt bneradt Nov 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the other interesting production change (part 2).

This is "recooked" here to avoid intermingling the targeted cache control configuration into the MIME/parser interface. The recompute should be cheap, so I think this is OK. But if wanted, I can look into trying to get the parse to happen initially at parse_resp.

@bneradt bneradt force-pushed the targeted_cache_control branch 2 times, most recently from 5061c02 to 57898a7 Compare November 20, 2025 21:27
This adds support for targeted Cache-Control headers (like CDN-Cache-Control)
that allow cache directives to be targeted at specific caches. The
implementation includes a configurable, priority-ordered list of targeted
headers via proxy.config.http.cache.targeted_cache_control_headers, which is
overridable per-remap rule. When a targeted header is present, it takes
precedence over the standard Cache-Control header for caching decisions.
Targeted headers are passed through downstream to allow proper cache hierarchy
behavior.

Fixes: apache#9113
@bneradt bneradt force-pushed the targeted_cache_control branch from 57898a7 to c82d967 Compare November 24, 2025 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Targeted HTTP Cache Control“ specs supports

1 participant