Repository navigation
Stop output/response caching from reordering request values - #69112
Conversation
Co-authored-by: Youssef1313 <[email protected]>
2c4e4a9 to
2d0b6c1
Compare
|
Hi @copilot. Please make sure you've updated the PR description to use the Shiproom Template. Also, make sure this PR is not marked as a draft and is ready-to-merge. To learn more about how to prepare a servicing PR click here. |
|
@copilot Fix response caching as well |
Co-authored-by: Youssef1313 <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Key-generation behavior changes (order-sensitivity vs canonicalization) need resolution/clarification, and there are test naming consistency fixes requested.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR updates the OutputCaching and ResponseCaching key providers to avoid mutating live HttpRequest.Headers / HttpRequest.Query value ordering during cache-key generation, and adjusts/adds tests to cover the new behavior.
Changes:
- Removed in-place sorting of repeated header/query values during vary-by key generation in OutputCaching and ResponseCaching.
- Updated existing key-generation test expectations to reflect preserved repeated-value order.
- Added targeted regression tests asserting request header/query value order is unchanged after key generation.
File summaries
| File | Description |
|---|---|
| src/Middleware/ResponseCaching/test/ResponseCachingKeyProviderTests.cs | Updates expected vary-by keys and adds tests to ensure request value order isn’t mutated. |
| src/Middleware/ResponseCaching/src/ResponseCachingKeyProvider.cs | Removes sorting of repeated header/query values when building the vary-by storage key. |
| src/Middleware/OutputCaching/test/OutputCacheKeyProviderTests.cs | Updates expected cache keys and adds tests to ensure request value order isn’t mutated. |
| src/Middleware/OutputCaching/src/OutputCacheKeyProvider.cs | Removes sorting of repeated header/query values when appending vary-by segments to the storage key. |
Review details
Suppressed comments (2)
src/Middleware/ResponseCaching/test/ResponseCachingKeyProviderTests.cs:246
- Test method prefix uses "CreateStorageVaryByKey" while the rest of this file uses "CreateStorageVaryKey"; for consistency within the suite, consider renaming this method to match the established pattern.
public void ResponseCachingKeyProvider_CreateStorageVaryByKey_ExplicitQueryValues_DoesNotMutateRequestQueryValueOrder()
src/Middleware/ResponseCaching/test/ResponseCachingKeyProviderTests.cs:262
- Test method prefix uses "CreateStorageVaryByKey" while the rest of this file uses "CreateStorageVaryKey"; for consistency within the suite, consider renaming this method to match the established pattern.
public void ResponseCachingKeyProvider_CreateStorageVaryByKey_WildcardQueryValues_DoesNotMutateRequestQueryValueOrder()
- Files reviewed: 4/4 changed files
- Comments generated: 3
- Review effort level: Lite
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
halter73
left a comment
There was a problem hiding this comment.
Initially, I was worried we were also dropping query parameter name sorting, which could cause unnecessary cache misses.
But on closer inspection, I realize ?a=1&b=2 still matches ?b=2&a=1 after this PR, and only the value order within each name becomes significant. Given our APIs expose those values as ordered StringValues, it’s easy for application code to depend on that order for both query parameters and headers. Preserving it in the cache key makes sense. LGTM.
Avoids sorting headers and query parameters when calculating the cache key.
Fixes #69109