Skip to content

Fix HTTP caching compliance by adding Vary headers for compressible content - #12741

Merged
mlibbey merged 1 commit into
apache:masterfrom
mlibbey:compress-vary-headers-v2
Dec 16, 2025
Merged

Fix HTTP caching compliance by adding Vary headers for compressible content#12741
mlibbey merged 1 commit into
apache:masterfrom
mlibbey:compress-vary-headers-v2

Conversation

@mlibbey

@mlibbey mlibbey commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

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.

@mlibbey

mlibbey commented Dec 9, 2025

Copy link
Copy Markdown
Contributor Author

@JakeChampion because of big recent changes to compress.

@bneradt

bneradt commented Dec 9, 2025

Copy link
Copy Markdown
Contributor

In case it's helpful:
https://ci.trafficserver.apache.org/job/Github_Builds/job/centos/5791/console

../../../plugins/compress/compress.cc: In function 'void Compress::{anonymous}::handle_range_request(TSMBuffer, TSMLoc, const Compress::HostConfiguration*)':
../../../plugins/compress/compress.cc:100:35: error: passing 'const Compress::HostConfiguration' as 'this' argument discards qualifiers [-fpermissive]
  100 |     switch (hc->range_request_ctl()) {
      |                                   ^
In file included from ../../../plugins/compress/compress_common.h:41,
                 from ../../../plugins/compress/compress.cc:36:
../../../plugins/compress/configuration.h:94:3: note:   in call to 'Compress::RangeRequestCtrl Compress::HostConfiguration::range_request_ctl()'
   94 |   range_request_ctl()
      |   ^~~~~~~~~~~~~~~~~

@mlibbey
mlibbey force-pushed the compress-vary-headers-v2 branch from 55731c9 to e7ae730 Compare December 9, 2025 17:24
…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>
@mlibbey
mlibbey force-pushed the compress-vary-headers-v2 branch from e7ae730 to 95eb749 Compare December 9, 2025 21:38
@mlibbey

mlibbey commented Dec 10, 2025

Copy link
Copy Markdown
Contributor Author

Sorry for the initial build failures -- it was building locally :( (The Rocky crash looks to be in a cache subsystem regression test).
Think it really ready for review.

@cmcfarlen cmcfarlen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems good. I looked for, but did didn't notice any, missing API handle cleanup.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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_compressible and client_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.

@mlibbey
mlibbey merged commit 0d52043 into apache:master Dec 16, 2025
21 checks passed
@github-project-automation github-project-automation Bot moved this to For v10.1.1 in ATS v10.1.x Dec 16, 2025
cmcfarlen pushed a commit to cmcfarlen/trafficserver that referenced this pull request Dec 16, 2025
…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)
cmcfarlen added a commit that referenced this pull request Dec 17, 2025
#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>
@cmcfarlen cmcfarlen moved this from For v10.1.1 to Picked v10.1.1 in ATS v10.1.x Dec 17, 2025
@cmcfarlen cmcfarlen removed this from the 10.2.0 milestone Dec 17, 2025
@cmcfarlen

Copy link
Copy Markdown
Contributor

Added to 10.1.1 milestone via #12764

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Picked v10.1.1

Development

Successfully merging this pull request may close these issues.

5 participants