Skip to content
Myr

fix(etag): stabilize digest across stream chunks (#5205)

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

* fix(etag): stabilize digest across stream chunks * perf(etag): optimize fixed-size digest chunks

authored by Taku Amano · committed by GitHub · parent 7075369 · Browse files · 2 files+84 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+84 added−1 removed

  • tests:+31 added−0 removed
  • other:+53 added−1 removed

2 files+84 added−1 removed

modified:src/middleware/etag/digest.ts+53 added-1 removed
modified:src/middleware/etag/index.test.ts+31 added
128 unmodified lines
129 res = await app.request('http://localhost/etag/rs2')130 expect(res.headers.get('ETag')).not.toBe(hash)131 })132133 it('Should return the same etag regardless of ReadableStream chunk boundaries', async () => {134 const app = new Hono()135 app.use('/etag/*', etag())136 app.get('/etag/rs1', (c) => {137 return c.body(138 new ReadableStream({139 start(controller) {140 controller.enqueue(new Uint8Array(1_000_000))141 controller.close()142 },143 })144 )145 })146 app.get('/etag/rs2', (c) => {147 return c.body(148 new ReadableStream({149 start(controller) {150 controller.enqueue(new Uint8Array(1))151 controller.enqueue(new Uint8Array(32_768))152 controller.enqueue(new Uint8Array(967_231))153 controller.close()154 },155 })156 )157 })158159 const res1 = await app.request('http://localhost/etag/rs1')160 const res2 = await app.request('http://localhost/etag/rs2')161 expect(res2.headers.get('ETag')).toBe(res1.headers.get('ETag'))162 })163164 it('Should not return etag header when the stream is empty', async () => {165 const app = new Hono()166 app.use('/etag/*', etag())167 app.get('/etag/abc', (c) => {
277 unmodified lines