Skip to content
Myr

feat(etag): support conditional requests for the QUERY method (#5111)

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

authored by James Ross · committed by Yusuke Wada · parent 6f101a7 · Browse files · 2 files+48 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+48 added−1 removed

  • tests:+47 added−0 removed
  • other:+1 added−1 removed

2 files+48 added−1 removed

modified:src/middleware/etag/index.test.ts+47 added
224 unmodified lines
225 })226 expect(res.status).toBe(304)227 })228229 it('Should handle conditional QUERY requests', async () => {230 const app = new Hono()231 app.use('/etag/*', etag())232 app.on('QUERY', '/etag/query', (c) => c.text('Hono is great'))233234 // unconditional QUERY235 let res = await app.request('http://localhost/etag/query', {236 method: 'QUERY',237 body: 'select *',238 })239 expect(res.status).toBe(200)240 expect(res.headers.get('ETag')).not.toBeFalsy()241 const etagHeaderValue = res.headers.get('ETag') || ''242243 // conditional QUERY with the wrong ETag:244 res = await app.request('http://localhost/etag/query', {245 method: 'QUERY',246 body: 'select *',247 headers: {248 'If-None-Match': '"not the right etag"',249 },250 })251 expect(res.status).toBe(200)252253 // conditional QUERY with matching ETag:254 res = await app.request('http://localhost/etag/query', {255 method: 'QUERY',256 body: 'select *',257 headers: {258 'If-None-Match': etagHeaderValue,259 },260 })261 expect(res.status).toBe(304)262 expect(res.headers.get('ETag')).toBe(etagHeaderValue)263 expect(await res.text()).toBe('')264265 // conditional QUERY with `*` wildcard:266 res = await app.request('http://localhost/etag/query', {267 method: 'QUERY',268 body: 'select *',269 headers: {270 'If-None-Match': '*',271 },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 () => {277 const app = new Hono()278 app.use('/etag/*', etag())279 app.put('/etag/put', (c) => c.text('created', 201))
118 unmodified lines
modified:src/middleware/etag/index.ts+1 added-1 removed