Skip to content
Myr

fix(context): correct set-cookie header values if c.res is set (#2570)

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

* fix(context): correct set-cookie header values if c.res is set * denoify

authored by Yusuke Wada · committed by GitHub · parent 347ef12 · Browse files · 3 files+20 added−14 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+20 added−14 removed

  • tests:+12 added−0 removed
  • other:+8 added−14 removed

3 files+20 added−14 removed

modified:deno_dist/context.ts+4 added-7 removed
380 unmodified lines
381 setHeaders(this.#headers, this.#preparedHeaders)382383 if (this.#res) {384 this.#res.headers.forEach((v, k) => {385 if (k === 'set-cookie' && this.#res) {386 const cookies = this.#res.headers.getSetCookie()387 for (const cookie of cookies) {388 this.#headers?.append('set-cookie', cookie)389 }390 return385 if (k === 'set-cookie') {386 this.#headers?.append(k, v)387 } else {388 this.#headers?.set(k, v)389 }392 this.#headers?.set(k, v)390 })391 setHeaders(this.#headers, this.#preparedHeaders)392 }393
168 unmodified lines
modified:src/context.test.ts+12 added
252 unmodified lines
253 const cookies = res.headers.getSetCookie()254 expect(cookies.includes('foo=bar; Path=/')).toBe(true)255 expect(cookies.includes('foo2=bar2; Path=/')).toBe(true)256 })257258 it('Should set set-cookie header values if c.res is already defined', () => {259 c.res = new Response(null, {260 headers: [261 ['set-cookie', 'a'],262 ['set-cookie', 'b'],263 ['set-cookie', 'c'],264 ],265 })266 const res = c.text('Hi')267 expect(res.headers.get('set-cookie')).toBe('a, b, c')268 })269})270271describe('Pass a ResponseInit to respond methods', () => {272 const req = new HonoRequest(new Request('http://localhost/'))
83 unmodified lines
modified:src/context.ts+4 added-7 removed
380 unmodified lines
381 setHeaders(this.#headers, this.#preparedHeaders)382383 if (this.#res) {384 this.#res.headers.forEach((v, k) => {385 if (k === 'set-cookie' && this.#res) {386 const cookies = this.#res.headers.getSetCookie()387 for (const cookie of cookies) {388 this.#headers?.append('set-cookie', cookie)389 }390 return385 if (k === 'set-cookie') {386 this.#headers?.append(k, v)387 } else {388 this.#headers?.set(k, v)389 }392 this.#headers?.set(k, v)390 })391 setHeaders(this.#headers, this.#preparedHeaders)392 }393
168 unmodified lines