From cb674081eff3e455d3f7fb3013a74de60592c823 Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Sat, 1 Feb 2025 19:36:32 +0900 Subject: [PATCH] refactor(request): `toLowerCase()` is unnecessary for `req.header()` --- src/request.test.ts | 14 ++++++++++++++ src/request.ts | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/request.test.ts b/src/request.test.ts index 61654c130..11f85fb30 100644 --- a/src/request.test.ts +++ b/src/request.test.ts @@ -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"}' diff --git a/src/request.ts b/src/request.ts index 68c710c35..647129ab7 100644 --- a/src/request.ts +++ b/src/request.ts @@ -178,7 +178,7 @@ export class HonoRequest

{ header(): Record header(name?: string) { if (name) { - return this.raw.headers.get(name.toLowerCase()) ?? undefined + return this.raw.headers.get(name) ?? undefined } const headerData: Record = {}