Skip to content
Myr

fix(etag): avoid skipping headers when filtering 304 response headers (#5234)

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

* fix(etag): avoid skipping headers when filtering 304 response headers * refactor(etag): use Array.from() to snapshot header keys

authored by Nanasi · committed by GitHub · parent 7195c24 · Browse files · 2 files+31 added−2 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: Taku Amano <taku@taaas.jp>

Diff stats

2 files+31 added−2 removed

  • tests:+29 added−0 removed
  • other:+2 added−2 removed

2 files+31 added−2 removed

modified:src/middleware/etag/index.test.ts+29 added
459 unmodified lines
460 expect(res.status).toBe(200)461 expect(res.headers.get('ETag')).toBeNull()462 })463 })464465 it('Should remove all non-retained headers on 304 without skipping any', async () => {466 const app = new Hono()467 app.use('/etag/*', etag())468 app.get('/etag/multi-headers', (c) => {469 c.header('X-Custom-1', 'val1')470 c.header('X-Custom-2', 'val2')471 c.header('X-Custom-3', 'val3')472 c.header('X-Custom-4', 'val4')473 c.header('Cache-Control', 'max-age=3600')474 return c.text('Hono is hot')475 })476 const res1 = await app.request('http://localhost/etag/multi-headers')477 const etagHeader = res1.headers.get('ETag')!478 expect(res1.status).toBe(200)479480 const res2 = await app.request('http://localhost/etag/multi-headers', {481 headers: {482 'If-None-Match': etagHeader,483 },484 })485 expect(res2.status).toBe(304)486 expect(res2.headers.get('ETag')).toBe(etagHeader)487 expect(res2.headers.get('Cache-Control')).toBe('max-age=3600')488 expect(res2.headers.get('X-Custom-1')).toBeNull()489 expect(res2.headers.get('X-Custom-2')).toBeNull()490 expect(res2.headers.get('X-Custom-3')).toBeNull()491 expect(res2.headers.get('X-Custom-4')).toBeNull()492 })493})
modified:src/middleware/etag/index.ts+2 added-2 removed