Skip to content

compressor: add weaken_etag_on_compress to weaken strong ETags when compressing#43755

Open
rafaelgaspar wants to merge 3 commits intoenvoyproxy:mainfrom
rafaelgaspar:feat/compressor/35152-weaken-etag
Open

compressor: add weaken_etag_on_compress to weaken strong ETags when compressing#43755
rafaelgaspar wants to merge 3 commits intoenvoyproxy:mainfrom
rafaelgaspar:feat/compressor/35152-weaken-etag

Conversation

@rafaelgaspar
Copy link

Generative AI Disclaimer: This PR was prepared with assistance from generative AI (Cursor). The implementation, tests, and documentation have been fully reviewed by me as the PR author, and I take responsibility for the changes.

Commit Message:
compressor: add weaken_etag_on_compress to weaken strong ETags when compressing

Additional Description:
Adds a new option weaken_etag_on_compress to the compressor filter's
response_direction_config. When enabled, strong ETag response headers
are weakened by prepending W/ to the value (e.g. "abc123" becomes
W/"abc123") instead of being removed when compression is applied. Weak
ETags (already starting with W/) are left unchanged.

This allows caches and conditional requests to keep working while indicating
that the representation was modified by compression, matching behavior used in
other proxies (e.g. Varnish). The default remains false, preserving
existing behavior (strong ETags are removed when compressing).

Fixes #35152

Risk Level: Low

Testing:
New unit tests in compressor_filter_test.cc:

  • WeakenEtagOnCompressStrongEtag – strong ETag is weakened when compressing
  • WeakenEtagOnCompressStrongEtagWithQuotes – strong ETag with quotes is weakened
  • WeakenEtagOnCompressWeakEtagUnchanged – weak ETag is preserved
  • WeakenEtagOnCompressWithStatusHeaderEnabled – weaken behavior with status header enabled

Docs Changes: Yes

  • Updated docs/root/configuration/http/http_filters/compressor_filter.rst with an "ETag handling" section describing disable_on_etag_header and weaken_etag_on_compress, and added a YAML example for weaken_etag_on_compress.
  • Updated "When response compression is applied" and compression-skip conditions to reference ETag handling.
  • Clarified EtagNotAllowed status and not_compressed_etag stat descriptions.

Release Notes: Yes

  • Added entry under new_features in changelogs/current.yaml for the compressor filter's weaken_etag_on_compress option.

Platform Specific Features: N/A

@repokitteh-read-only
Copy link

Hi @rafaelgaspar, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #43755 was opened by rafaelgaspar.

see: more, trace.

@repokitteh-read-only
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @adisuissa
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #43755 was opened by rafaelgaspar.

see: more, trace.

@rafaelgaspar rafaelgaspar force-pushed the feat/compressor/35152-weaken-etag branch from ba6a487 to 3bcab8f Compare March 4, 2026 11:38
@agrawroh
Copy link
Member

cc @adisuissa Gentle ping for the review.

@agrawroh
Copy link
Member

@rafaelgaspar It also needs a main merge.

/wait

Copy link
Contributor

@adisuissa adisuissa left a comment

Choose a reason for hiding this comment

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

Thanks! left a couple of high-level API comments.

// response body was modified by compression. When ``false`` (default), strong ETags are
// removed when compression is applied. This option has no effect when ``disable_on_etag_header``
// is ``true`` (compression is skipped for responses with ETag).
bool weaken_etag_on_compress = 6;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move next to the disable_on_etag_header field.

Comment on lines +104 to +105
// removed when compression is applied. This option has no effect when ``disable_on_etag_header``
// is ``true`` (compression is skipped for responses with ETag).
Copy link
Contributor

Choose a reason for hiding this comment

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

If the fields weaken_etag_on_compress and disable_on_etag_header are conflicting (cannot set both to true), then the suggested API flow will be prioritizing the new field over the old one in the case both are set.
The reason is to support gradual rollout of the feature support to clients and servers.

Introduces a new configuration option, `weaken_etag_on_compress`, to the compressor filter's response direction configuration. When enabled, strong ETag headers are modified to include a "W/" prefix instead of being removed during compression, allowing for better cache and conditional request handling. Updates to documentation and tests have been made to reflect this new behavior.

Signed-off-by: Rafael Antunes <rafael.gaspar@me.com>
@rafaelgaspar rafaelgaspar force-pushed the feat/compressor/35152-weaken-etag branch from 3bcab8f to 974d00d Compare March 10, 2026 22:14
Updated the compressor filter to clarify the precedence of the `weaken_etag_on_compress` option when both it and `disable_on_etag_header` are enabled. Compression will now be applied, and the ETag will be weakened, allowing for better cache management. Documentation and tests have been updated to reflect this behavior.

Signed-off-by: Rafael Antunes <rafael.gaspar@me.com>
Signed-off-by: Rafael Antunes <rafael.gaspar@me.com>
@rafaelgaspar rafaelgaspar requested a deployment to external-contributors March 10, 2026 22:33 — with GitHub Actions Waiting
@rafaelgaspar
Copy link
Author

@adisuissa both suggestions have been incorporated into the code, let me know if there is anything else.

@paul-r-gall
Copy link
Contributor

@adisuissa re-ping for "stalled" bit.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support to weaken strong ETags when compressing/decompressing

4 participants