Add ETag value normalization to HttpCacheMiddleware - #31
Merged
Merged
Conversation
Introduce ETagValueNormalizerInterface to normalize raw ETag values from the If-None-Match request header before comparison. This fixes cache validation when a web server compression module (e.g. Apache mod_deflate or mod_brotli) appends a suffix such as -gzip or -br to the ETag value. Includes NullETagValueNormalizer (default, no changes) and SuffixETagValueNormalizer (removes the first matching suffix). Fixes yiisoft#11
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #31 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 112 117 +5
===========================================
Files 23 25 +2
Lines 274 282 +8
===========================================
+ Hits 274 282 +8 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
- Remove redundant early return for an empty If-None-Match header value: in_array() with an empty list already returns false (equivalent mutant reported by Infection). - Add a test asserting the ETag value normalizer is not called for an empty If-None-Match header value. MSI for the file is now 100%.
vjik
approved these changes
Aug 23, 2026
There was a problem hiding this comment.
Pull request overview
Adds opt-in normalization of If-None-Match ETag values in HttpCacheMiddleware to handle server-added compression suffixes (e.g. -gzip, -br) so cache validation can still hit.
Changes:
- Introduces
ETagValueNormalizerInterfacewithNullETagValueNormalizer(default no-op) andSuffixETagValueNormalizer(removes first matching suffix). - Extends
HttpCacheMiddlewarewith a new optional$eTagValueNormalizerconstructor dependency and applies it when extracting request ETags. - Adds unit tests for the new normalizers and middleware behavior, plus documentation and changelog updates.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/HttpCache/HttpCacheMiddlewareTest.php | Adds coverage ensuring suffix-normalized If-None-Match matches generated ETags and that empty headers skip normalization. |
| tests/HttpCache/ETagValueNormalizer/SuffixETagValueNormalizerTest.php | Validates suffix stripping behavior, including first-match-only semantics and empty-suffix handling. |
| tests/HttpCache/ETagValueNormalizer/NullETagValueNormalizerTest.php | Confirms the default normalizer is a pass-through. |
| src/HttpCache/HttpCacheMiddleware.php | Wires in the new normalizer and applies it when extracting If-None-Match values. |
| src/HttpCache/ETagValueNormalizer/SuffixETagValueNormalizer.php | Implements configurable suffix removal for raw ETag values. |
| src/HttpCache/ETagValueNormalizer/NullETagValueNormalizer.php | Implements the default no-op normalizer. |
| src/HttpCache/ETagValueNormalizer/ETagValueNormalizerInterface.php | Defines the normalization contract for request ETag values. |
| docs/guide/en/http-cache-middleware.md | Documents the new $eTagValueNormalizer option and provides an example configuration. |
| CHANGELOG.md | Records the new feature under the upcoming release. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
samdark
approved these changes
Aug 23, 2026
KalimeroMK
pushed a commit
to KalimeroMK/KalimeroMK
that referenced
this pull request
Aug 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #11
When a web server compression module (e.g. Apache
mod_deflateormod_brotli) modifies theETagheader value by appending a suffix (-gzip,-br), the client sends the modified value back inIf-None-Matchand it no longer matches the application generated ETag, so the cache never hits.Following the direction from #11 (comment) (normalize raw values after retrieving them from the request), this PR adds:
ETagValueNormalizerInterface— normalizes raw ETag values obtained from theIf-None-Matchrequest header before comparison.NullETagValueNormalizer— default, returns values unmodified.SuffixETagValueNormalizer— removes the first matching suffix from a given list (e.g.['-gzip', '-br']).HttpCacheMiddlewareconstructor parameter$eTagValueNormalizer(defaults toNullETagValueNormalizer, no BC break).Note: the
W/weak prefix (the Nginx case) was already handled by the existing value extraction; this PR covers the suffix case.