Add ETag value normalization to HttpCacheMiddleware - #31
Open
KalimeroMK wants to merge 2 commits into
Open
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 118 +6
===========================================
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%.
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.