Skip to content
Myr

fix(etag): skip unsafe methods or error responses on non-* case (#5196)

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

authored by k. Naka · committed by GitHub · parent cd31bc1 · Browse files · 2 files+29 added−9 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+29 added−9 removed

  • tests:+21 added−5 removed
  • other:+8 added−4 removed

2 files+29 added−9 removed

modified:src/middleware/etag/index.test.ts+21 added-5 removed
271 unmodified lines
272 })273 expect(res.status).toBe(304)274 })275276 it('Should not return 304 for `If-None-Match: *` on unsafe methods or error responses', async () => {276 it('Should not return 304 on unsafe methods or error responses', async () => {277 const app = new Hono()278 app.use('/etag/*', etag())279 app.put('/etag/put', (c) => c.text('created', 201))280 app.get('/etag/not-found', (c) => c.text('not found', 404))279 app.put('/etag/put', (c) => c.text('created', 201, { ETag: '"etag-123"' }))280 app.get('/etag/not-found', (c) => c.text('not found', 404, { ETag: '"etag-123"' }))281282 // `*` does not apply to unsafe methods:282 // Unsafe methods:283 let res = await app.request('http://localhost/etag/put', {284 method: 'PUT',285 headers: {286 'If-None-Match': '*',
1 unmodified line
288 })289 expect(res.status).toBe(201)290 expect(await res.text()).toBe('created')291292 // `*` does not apply when there is no current representation:292 res = await app.request('http://localhost/etag/put', {293 method: 'PUT',294 headers: {295 'If-None-Match': '"etag-123"',296 },297 })298 expect(res.status).toBe(201)299 expect(await res.text()).toBe('created')300301 // Error responses:302 res = await app.request('http://localhost/etag/not-found', {303 headers: {304 'If-None-Match': '*',305 },306 })307 expect(res.status).toBe(404)308309 res = await app.request('http://localhost/etag/not-found', {310 headers: {311 'If-None-Match': '"etag-123"',312 },313 })314 expect(res.status).toBe(404)315 })316317 it('Should not return duplicate etag header values', async () => {318 const app = new Hono()
95 unmodified lines
modified:src/middleware/etag/index.ts+8 added-4 removed