{{ message }}
fix(cache): deduplicate Cache-Control directives case-insensitively#5025
Open
nyxst4ck wants to merge 1 commit into
Open
fix(cache): deduplicate Cache-Control directives case-insensitively#5025nyxst4ck wants to merge 1 commit into
nyxst4ck wants to merge 1 commit into
Conversation
The cache middleware extracted existing Cache-Control directive names without lower-casing them, then compared against its own lower-cased directive names. Cache-Control directive names are case-insensitive (RFC 7234), so a handler-set `Max-Age=3600` was not recognised as a duplicate of a configured `max-age=10` and a contradictory directive was appended. Lower-case the extracted names so the de-dup check matches regardless of case.
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.

What
The cache middleware composes its configured
cacheControldirectives onto anexisting
Cache-Controlheader, de-duplicating by directive name. But itextracts the existing directive names without lower-casing them
(
src/middleware/cache/index.ts), while lower-casing its own name before themembership check:
Cache-Control directive names are case-insensitive (RFC 7234 §5.2). So when a
route handler sets e.g.
Cache-Control: Max-Age=3600and the middleware isconfigured with
cacheControl: 'max-age=10', the duplicate isn't detected and acontradictory directive is appended:
The existing
/wait2/de-dup test only passes because both directives there arewritten lower-case by the middleware itself; the handler-set path was the gap.
Fix
Lower-case the extracted existing directive names so the case-insensitive de-dup
check matches handler-set names like
Max-Age.Test
Added a
Cache Middlewarecase (/wait5/) where the handler setsCache-Control: Max-Age=3600against a middlewaremax-age=10. It fails onmain(Max-Age=3600, max-age=10) and passes with the fix (Max-Age=3600).All cache middleware tests pass (139). Prettier + ESLint clean.