Skip to content

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

Merged
KBaichoo merged 7 commits into
envoyproxy:mainfrom
rafaelgaspar:feat/compressor/35152-weaken-etag
Mar 25, 2026
Merged

compressor: add weaken_etag_on_compress to weaken strong ETags when compressing#43755
KBaichoo merged 7 commits into
envoyproxy:mainfrom
rafaelgaspar:feat/compressor/35152-weaken-etag

Conversation

@rafaelgaspar
Copy link
Copy Markdown
Contributor

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown
Member

cc @adisuissa Gentle ping for the review.

@agrawroh
Copy link
Copy Markdown
Member

@rafaelgaspar It also needs a main merge.

/wait

Copy link
Copy Markdown
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.

Comment thread api/envoy/extensions/filters/http/compressor/v3/compressor.proto Outdated
Comment thread api/envoy/extensions/filters/http/compressor/v3/compressor.proto Outdated
@rafaelgaspar rafaelgaspar force-pushed the feat/compressor/35152-weaken-etag branch from 3bcab8f to 974d00d Compare March 10, 2026 22:14
@rafaelgaspar
Copy link
Copy Markdown
Contributor Author

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

@paul-r-gall
Copy link
Copy Markdown
Contributor

@adisuissa re-ping for "stalled" bit.

Copy link
Copy Markdown
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.

/lgtm api

@adisuissa
Copy link
Copy Markdown
Contributor

This requires a compressor filter owner review.
/assign @KBaichoo

KBaichoo
KBaichoo previously approved these changes Mar 19, 2026
Copy link
Copy Markdown
Contributor

@KBaichoo KBaichoo left a comment

Choose a reason for hiding this comment

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

looks good otherwise, thanks

Comment thread source/extensions/filters/http/compressor/compressor_filter.cc Outdated
Comment thread source/extensions/filters/http/compressor/compressor_filter.cc Outdated
@KBaichoo
Copy link
Copy Markdown
Contributor

/wait

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>
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>
Introduced a helper function `isWeakEtag` to streamline the logic for identifying weak ETags in the `sanitizeEtagHeader` and `weakenEtagHeader` methods.

Signed-off-by: Rafael Antunes <rafael.gaspar@me.com>
Updated the initialization of the `weaken_etag_on_compress` member variable to directly use the value from the response direction configuration, simplifying the logic and ensuring consistent behavior.

Signed-off-by: Rafael Antunes <rafael.gaspar@me.com>
@rafaelgaspar
Copy link
Copy Markdown
Contributor Author

@KBaichoo addressed the comments, and did a rebase. Let me know if there is anything else.

Copy link
Copy Markdown
Contributor

@KBaichoo KBaichoo left a comment

Choose a reason for hiding this comment

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

/wait

Comment thread source/extensions/filters/http/compressor/compressor_filter.cc Outdated
Updated the CompressorFilter to remove strong ETags of length two during compression, aligning their treatment with longer strong ETags. Documentation has been updated to reflect this change, ensuring clarity on the behavior of the `weaken_etag_on_compress` option.

Signed-off-by: Rafael Antunes <rafael.gaspar@me.com>
@rafaelgaspar rafaelgaspar temporarily deployed to external-contributors March 24, 2026 10:04 — with GitHub Actions Inactive
@rafaelgaspar rafaelgaspar requested a review from KBaichoo March 24, 2026 10:04
@rafaelgaspar
Copy link
Copy Markdown
Contributor Author

@KBaichoo done, please let me know if there is anything else.

KBaichoo
KBaichoo previously approved these changes Mar 24, 2026
Signed-off-by: Rafael Antunes <rafael.gaspar@me.com>
@rafaelgaspar
Copy link
Copy Markdown
Contributor Author

@KBaichoo fixed the formatter issue, could you trigger CI again?

@rafaelgaspar rafaelgaspar temporarily deployed to external-contributors March 25, 2026 16:06 — with GitHub Actions Inactive
@KBaichoo KBaichoo merged commit 97f4cec into envoyproxy:main Mar 25, 2026
30 checks passed
TAOXUY pushed a commit to TAOXUY/envoy that referenced this pull request Apr 1, 2026
…ompressing (envoyproxy#43755)

**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 envoyproxy#35152

Signed-off-by: Rafael Antunes <rafael.gaspar@me.com>
Signed-off-by: Xuyang Tao <taoxuy@google.com>
citrus7 pushed a commit to citrus7/envoy that referenced this pull request Apr 1, 2026
…ompressing (envoyproxy#43755)

**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 envoyproxy#35152

Signed-off-by: Rafael Antunes <rafael.gaspar@me.com>
Signed-off-by: Jonathan Wu <jtwu@google.com>
nshipilov pushed a commit to nshipilov/envoy that referenced this pull request Apr 13, 2026
…ompressing (envoyproxy#43755)

**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 envoyproxy#35152

Signed-off-by: Rafael Antunes <rafael.gaspar@me.com>
Signed-off-by: Nick Shipilov <nick.shipilov.n@gmail.com>
krinkinmu pushed a commit to grnmeira/envoy that referenced this pull request Apr 20, 2026
…ompressing (envoyproxy#43755)

**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 envoyproxy#35152

Signed-off-by: Rafael Antunes <rafael.gaspar@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support to weaken strong ETags when compressing/decompressing

5 participants