-
Notifications
You must be signed in to change notification settings - Fork 841
Implement RFC 9213 Targeted HTTP Cache Control #12679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
| 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)); | ||
| } |
There was a problem hiding this comment.
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).
| // 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); | ||
|
|
There was a problem hiding this comment.
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.
5061c02 to
57898a7
Compare
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
57898a7 to
c82d967
Compare
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