Skip to content
Myr

fix(etag): fallback if `res.clone()` is not supported (#4198)

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

* fix(etag): fallback if `res.clone()` is not supported * update the comments * updated the comments

authored by Yusuke Wada · committed by GitHub · parent 53656e1 · Browse files · 3 files+44 added−11 removed
This commit

State

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

Diff stats

3 files+44 added−11 removed

  • tests:+23 added−0 removed
  • other:+21 added−11 removed

3 files+44 added−11 removed

modified:src/middleware/etag/digest.ts+12 added-10 removed
modified:src/middleware/etag/index.test.ts+23 added
153 unmodified lines
154 expect(res.status).toBe(500)155 expect(res.headers.get('ETag')).toBeNull()156 })157158 it('Should handle clone() not supported (Lambda-like environment)', async () => {159 const app = new Hono()160 app.use('/etag/*', etag())161 app.get('/etag/no-clone', (c) => {162 const originalResponse = c.text('Lambda test content')163 // Mock AWS Lambda environment where clone() doesn't work properly164 const mockResponse = new Response(originalResponse.body, {165 status: originalResponse.status,166 statusText: originalResponse.statusText,167 headers: originalResponse.headers,168 })169 // Override clone to throw error (AWS Lambda-like behavior)170 mockResponse.clone = () => {171 throw new Error('clone() not supported in AWS Lambda')172 }173 return mockResponse174 })175 const res = await app.request('/etag/no-clone')176 expect(res.status).toBe(200)177 expect(res.headers.get('ETag')).not.toBeNull()178 expect(await res.text()).toBe('Lambda test content')179 })180181 it('Should return etag header - weak', async () => {182 const app = new Hono()183 app.use('/etag/*', etag({ weak: true }))184 app.get('/etag/abc', (c) => {
156 unmodified lines
modified:src/middleware/etag/index.ts+9 added-1 removed