Skip to content
Myr

perf(cors): pre-join static array header options during initialization (#5210)

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

* perf(cors): pre-join static array header options during initialization * fix(cors): normalize function return for allowMethods to preserve missing header semantics

authored by Nanasi · committed by GitHub · parent d982f63 · Browse files · 2 files+30 added−12 removed
This commit

State

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

Trailers

  • Co-authored-by: Taku Amano <taku@taaas.jp>

Diff stats

2 files+30 added−12 removed

  • tests:+11 added−0 removed
  • other:+19 added−12 removed

2 files+30 added−12 removed

modified:src/middleware/cors/index.test.ts+11 added
380 unmodified lines
381 expect(res2.headers.get('Access-Control-Allow-Origin')).toBe('*')382 expect(res2.headers.get('Access-Control-Allow-Methods')).toBe('GET,HEAD')383 })384385 it('Does not set allow methods when function returns an empty array', async () => {386 for (const allowMethods of [() => [], async () => []]) {387 const app = new Hono()388 app.use(cors({ allowMethods }))389390 const res = await app.request('http://localhost/', { method: 'OPTIONS' })391392 expect(res.headers.get('Access-Control-Allow-Methods')).toBeNull()393 }394 })395396 it('Emits the wildcard, not the reflected origin, when credentials is true with wildcard origin', async () => {397 const res = await app.request('http://localhost/api10/abc', {398 headers: {399 Origin: 'http://example.com',
105 unmodified lines
modified:src/middleware/cors/index.ts+19 added-12 removed