Skip to content
Myr

fix(cache): deduplicate Cache-Control directives case-insensitively (#5025)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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.

authored by nyxst4ck · committed by GitHub · parent 3bb9a0e · Browse files · 2 files+19 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: nyxst4ck <289980115+nyxst4ck@users.noreply.github.com>

Diff stats

2 files+19 added−1 removed

  • tests:+15 added−0 removed
  • other:+4 added−1 removed

2 files+19 added−1 removed

modified:src/middleware/cache/index.test.ts+15 added
152 unmodified lines
153 c.header('Cache-Control', 'private')154 return c.text('cached')155 })156157 app.use('/wait5/*', cache({ cacheName: 'my-app-v1', wait: true, cacheControl: 'max-age=10' }))158 app.get('/wait5/', (c) => {159 c.header('Cache-Control', 'Max-Age=3600')160 return c.text('cached')161 })162163 app.use('/vary1/*', cache({ cacheName: 'my-app-v1', wait: true, vary: ['Accept'] }))164 app.get('/vary1/', (c) => {165 return c.text('cached')166 })
113 unmodified lines
280 expect(res.status).toBe(200)281 expect(res.headers.get('cache-control')).toBe('private, max-age=10')282 })283284 it('Should not duplicate a Cache-Control directive that differs only in case', async () => {285 const res = await app.request('/wait5/')286 expect(res).not.toBeNull()287 expect(res.status).toBe(200)288 // Directive names are case-insensitive (RFC 7234 §5.2); the handler's289 // `Max-Age` must suppress the middleware's configured `max-age`.290 expect(res.headers.get('cache-control')).toBe('Max-Age=3600')291 })292293 it('Should correctly apply a single Vary header from middleware', async () => {294 const res = await app.request('http://localhost/vary1/')295 expect(res).not.toBeNull()296 expect(res.status).toBe(200)
472 unmodified lines
modified:src/middleware/cache/index.ts+4 added-1 removed