Skip to content

Commit

Permalink
refactor(request): toLowerCase() is unnecessary for req.header() (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe authored Feb 2, 2025
1 parent 093d3fd commit 65edaf2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,20 @@ describe('headers', () => {
const foo = req.header('foo')
expect(foo).toEqual('')
})

test('Keys of the arguments for req.header() are not case-sensitive', () => {
const req = new HonoRequest(
new Request('http://localhost', {
headers: {
'Content-Type': 'application/json',
apikey: 'abc',
lowercase: 'lowercase value',
},
})
)
expect(req.header('Content-Type')).toBe('application/json')
expect(req.header('ApiKey')).toBe('abc')
})
})

const text = '{"foo":"bar"}'
Expand Down
2 changes: 1 addition & 1 deletion src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export class HonoRequest<P extends string = '/', I extends Input['out'] = {}> {
header(): Record<RequestHeader | (string & CustomHeader), string>
header(name?: string) {
if (name) {
return this.raw.headers.get(name.toLowerCase()) ?? undefined
return this.raw.headers.get(name) ?? undefined
}

const headerData: Record<string, string | undefined> = {}
Expand Down

0 comments on commit 65edaf2

Please sign in to comment.