Fix HTTP caching compliance by adding Vary headers for compressible content - #12741
Conversation
|
@JakeChampion because of big recent changes to compress. |
|
In case it's helpful: |
55731c9 to
e7ae730
Compare
…ontent The compress plugin was only adding Vary: Accept-Encoding headers when content was actually going to be compressed, not when content could be compressed. This can cause downstream caches to never get the compressed version in cache. Now adds Vary: Accept-Encoding headers for all compressible content regardless of whether compression is applied, ensuring proper HTTP cache behavior. Co-Authored-By: Claude <noreply@anthropic.com>
e7ae730 to
95eb749
Compare
|
Sorry for the initial build failures -- it was building locally :( (The Rocky crash looks to be in a cache subsystem regression test). |
cmcfarlen
left a comment
There was a problem hiding this comment.
Seems good. I looked for, but did didn't notice any, missing API handle cleanup.
There was a problem hiding this comment.
Pull request overview
This PR fixes HTTP caching compliance by ensuring the Vary: Accept-Encoding header is added for all compressible content, not just when compression is actually applied. Previously, the compress plugin only added this header when actively compressing responses, which could cause downstream caches to incorrectly serve uncompressed versions to clients that accept compression.
Key changes:
- Refactored compression eligibility logic into separate functions (
is_content_compressibleandclient_accepts_compression) for clearer separation of concerns - Added dedicated function to set Vary header for all compressible content regardless of whether compression is applied
- Introduced orchestration function that handles both compression transformation and Vary header addition
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
plugins/compress/compress.cc |
Refactored transformable function into is_content_compressible and client_accepts_compression; added add_vary_header_for_compressible_content and handle_compression_and_vary functions to ensure Vary header is added for all compressible content; removed vary_header check from compression transform initialization |
tests/gold_tests/pluginTest/compress/compress.test.py |
Added test cases to verify Vary header is present for compressible content without Accept-Encoding header and with unsupported Accept-Encoding values |
tests/gold_tests/pluginTest/compress/compress.gold |
Updated expectations to show Vary header appearing before Content-Encoding in header order, and added Vary header expectations for compressible but non-compressed responses |
tests/gold_tests/pluginTest/compress/compress_userver.gold |
Added expectations for new test cases testing vary header behavior with non-standard accept-encoding values |
tests/gold_tests/pluginTest/compress/compress_vary.gold |
New gold file containing expected Vary header output for new test cases |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ontent (apache#12741) The compress plugin was only adding Vary: Accept-Encoding headers when content was actually going to be compressed, not when content could be compressed. This can cause downstream caches to never get the compressed version in cache. Now adds Vary: Accept-Encoding headers for all compressible content regardless of whether compression is applied, ensuring proper HTTP cache behavior. Co-authored-by: Claude <noreply@anthropic.com> (cherry picked from commit 0d52043)
#12764) * Fix HTTP caching compliance by adding Vary headers for compressible content (#12741) The compress plugin was only adding Vary: Accept-Encoding headers when content was actually going to be compressed, not when content could be compressed. This can cause downstream caches to never get the compressed version in cache. Now adds Vary: Accept-Encoding headers for all compressible content regardless of whether compression is applied, ensuring proper HTTP cache behavior. Co-authored-by: Claude <noreply@anthropic.com> (cherry picked from commit 0d52043) * fix gold wildcards * Add whitespace back --------- Co-authored-by: mlibbey <mlibbey@apache.org> Co-authored-by: Claude <noreply@anthropic.com>
|
Added to 10.1.1 milestone via #12764 |
The compress plugin was only adding Vary: Accept-Encoding headers when content was actually going to be compressed, not when content could be compressed. This can cause downstream caches to never get the compressed version in cache.
Now adds Vary: Accept-Encoding headers for all compressible content regardless of whether compression is applied, ensuring proper HTTP cache behavior.