Skip to content
Myr

fix(middleware/etag): should return 304 when weak etag is passed in 'If-None-Match' (#4171)

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

* fix(middleware/etag): should return 304 when weak etag is passed in 'If-None-Match' Co-authored-by: EdamAme-x <edame8080@gmail.com> * fix(etag): correct formatting in tests and improve readability of etag matching logic ---------

authored by techfish · committed by GitHub · parent 2590c60 · Browse files · 2 files+25 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: EdamAme-x <edame8080@gmail.com>

Diff stats

2 files+25 added−1 removed

  • tests:+20 added−0 removed
  • other:+5 added−1 removed

2 files+25 added−1 removed

modified:src/middleware/etag/index.test.ts+20 added
268 unmodified lines
269 expect(res.headers.get('x-message-retain')).toBe(message)270 expect(res.headers.get('x-message')).toBeFalsy()271 })272273 it('Should return 304 when weak ETag in If-None-Match matches the generated ETag', async () => {274 const app = new Hono()275 app.use('/etag/*', etag())276 app.get('/etag/abc', (c) => {277 return c.text('Hono is hot')278 })279 let res = await app.request('http://localhost/etag/abc')280 const headerEtag = res.headers.get('ETag')!281282 expect(headerEtag).not.toBeFalsy()283284 res = await app.request('http://localhost/etag/abc', {285 headers: {286 'If-None-Match': 'W/"d104fafdb380655dab607c9bddc4d4982037afa1"',287 },288 })289290 expect(res.status).toBe(304)291 })292293 describe('When crypto is not available', () => {294 let _crypto: Crypto | undefined295 beforeAll(() => {296 _crypto = globalThis.crypto
21 unmodified lines
modified:src/middleware/etag/index.ts+5 added-1 removed