Skip to content
Myr

refactor(request): `toLowerCase()` is unnecessary for `req.header()` (#3880)

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 093d3fd · Browse files · 2 files+15 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+15 added−1 removed

  • tests:+14 added−0 removed
  • other:+1 added−1 removed

2 files+15 added−1 removed

modified:src/request.test.ts+14 added
159 unmodified lines
160 const req = new HonoRequest(new Request('http://localhost', { headers: { foo: '' } }))161 const foo = req.header('foo')162 expect(foo).toEqual('')163 })164165 test('Keys of the arguments for req.header() are not case-sensitive', () => {166 const req = new HonoRequest(167 new Request('http://localhost', {168 headers: {169 'Content-Type': 'application/json',170 apikey: 'abc',171 lowercase: 'lowercase value',172 },173 })174 )175 expect(req.header('Content-Type')).toBe('application/json')176 expect(req.header('ApiKey')).toBe('abc')177 })178})179180const text = '{"foo":"bar"}'181const json = { foo: 'bar' }
148 unmodified lines
modified:src/request.ts+1 added-1 removed
176 unmodified lines
177 header(name: string): string | undefined178 header(): Record<RequestHeader | (string & CustomHeader), string>179 header(name?: string) {180 if (name) {181 return this.raw.headers.get(name.toLowerCase()) ?? undefined181 return this.raw.headers.get(name) ?? undefined182 }183184 const headerData: Record<string, string | undefined> = {}185 this.raw.headers.forEach((value, key) => {
221 unmodified lines