Skip to content
Myr

fix(etag): treat If-None-Match: `*` as a match (#5084)

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

* fix(etag): treat If-None-Match: `*` as a match * support HEAD and !ok patterns

authored by Yusuke Wada · committed by GitHub · parent 0fc7ffc · Browse files · 2 files+39 added−1 removed
This commit

State

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

Diff stats

2 files+39 added−1 removed

  • tests:+33 added−0 removed
  • other:+6 added−1 removed

2 files+39 added−1 removed

modified:src/middleware/etag/index.test.ts+33 added
214 unmodified lines
215 'If-None-Match': `"mismatch 1", ${etagHeaderValue}, "mismatch 2"`,216 },217 })218 expect(res.status).toBe(304)219220 // conditional GET with `*` wildcard:221 res = await app.request('http://localhost/etag/ghi', {222 headers: {223 'If-None-Match': '*',224 },225 })226 expect(res.status).toBe(304)227 })228229 it('Should not return 304 for `If-None-Match: *` on unsafe methods or error responses', async () => {230 const app = new Hono()231 app.use('/etag/*', etag())232 app.put('/etag/put', (c) => c.text('created', 201))233 app.get('/etag/not-found', (c) => c.text('not found', 404))234235 // `*` does not apply to unsafe methods:236 let res = await app.request('http://localhost/etag/put', {237 method: 'PUT',238 headers: {239 'If-None-Match': '*',240 },241 })242 expect(res.status).toBe(201)243 expect(await res.text()).toBe('created')244245 // `*` does not apply when there is no current representation:246 res = await app.request('http://localhost/etag/not-found', {247 headers: {248 'If-None-Match': '*',249 },250 })251 expect(res.status).toBe(404)252 })253254 it('Should not return duplicate etag header values', async () => {255 const app = new Hono()256 app.use('/etag/*', etag())257 app.use('/etag/*', etag())
93 unmodified lines
modified:src/middleware/etag/index.ts+6 added-1 removed