Skip to content

Commit 04abb0d

Browse files
committed
fix: normalize header keys to lowercase for compliance with RFC 2616
1 parent 6d4c0fc commit 04abb0d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/utils.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,17 +343,18 @@ export function processHeaders(
343343

344344
const headersObject: HeadersObject = {};
345345

346-
// Handle Headers object with entries() method
346+
// Normalize keys to lowercase as per RFC 2616 4.2
347+
// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2
347348
if (headers instanceof Headers) {
348349
headers.forEach((value, key) => {
349-
headersObject[key] = value;
350+
headersObject[key.toLowerCase()] = value;
350351
});
351352
} else if (isObject(headers)) {
352-
// Handle plain object
353-
for (const [key, value] of Object.entries(headers)) {
354-
// Normalize keys to lowercase as per RFC 2616 4.2
355-
// https://datatracker.ietf.org/doc/html/rfc2616#section-4.2
356-
headersObject[key.toLowerCase()] = value;
353+
// Handle plain object — use for...in to avoid Object.entries() allocation
354+
for (const key in headers) {
355+
if (Object.prototype.hasOwnProperty.call(headers, key)) {
356+
headersObject[key.toLowerCase()] = headers[key];
357+
}
357358
}
358359
}
359360

0 commit comments

Comments
 (0)