Skip to content
Myr

fix(context): fixed bug raw `Response` content-type is overwritten (#836)

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

authored by Yusuke Wada · committed by GitHub · parent 1908be8 · Browse files · 4 files+33 added−3 removed
This commit

State

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

Diff stats

4 files+33 added−3 removed

  • tests:+31 added−3 removed
  • other:+2 added−0 removed

4 files+33 added−3 removed

modified:deno_dist/context.ts+1 added
64 unmodified lines
65 }6667 set res(_res: Response) {68 if (this._res) {69 this._res.headers.delete('content-type')70 this._res.headers.forEach((v, k) => {71 _res.headers.set(k, v)72 })73 }
177 unmodified lines
modified:src/context.test.ts+6 added-3 removed
modified:src/context.ts+1 added
64 unmodified lines
65 }6667 set res(_res: Response) {68 if (this._res) {69 this._res.headers.delete('content-type')70 this._res.headers.forEach((v, k) => {71 _res.headers.set(k, v)72 })73 }
177 unmodified lines
modified:src/hono.test.ts+25 added
433 unmodified lines
434 app.get('/hello', (c) => {435 return c.text('hello')436 })437438 app.use('/json/*', async (c, next) => {439 c.res.headers.append('foo', 'bar')440 await next()441 })442443 app.get('/json', (c) => {444 // With a raw response445 return new Response(446 JSON.stringify({447 message: 'hello',448 }),449 {450 headers: {451 'content-type': 'application/json',452 },453 }454 )455 })456457 app.get('/hello/:message', (c) => {458 const message = c.req.param('message')459 return c.text(`${message}`)460 })
22 unmodified lines
483 expect(res.headers.get('x-custom')).toBe('root')484 expect(res.headers.get('x-message-2')).toBe('custom-header-2')485 })486487 it('should return correct the content-type header', async () => {488 const res = await app.request('http://localhost/json')489 expect(res.status).toBe(200)490 expect(res.headers.get('content-type')).toMatch(/^application\/json/)491 })492493 it('not found', async () => {494 const res = await app.request('http://localhost/foo')495 expect(res.status).toBe(404)496 expect(await res.text()).toBe('Not Found Foo')
949 unmodified lines