Skip to content

Commit

Permalink
fix: convert all header names to lowercase if headers object is json
Browse files Browse the repository at this point in the history
  • Loading branch information
gamemaker1 committed Sep 21, 2023
1 parent ce1cff4 commit 524e351
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions source/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,27 @@ export const getRateLimits = (
'headers' in input &&
typeof input.headers === 'object' &&
!Array.isArray(input.headers)
)
) {
// The input is a fetch-style response object, the headers are a property on
// the object.
headers = input.headers
else if ('getHeaders' in input && typeof input.getHeaders === 'function')
} else if ('getHeaders' in input && typeof input.getHeaders === 'function') {
// The input is a node-style response object, get the headers using the
// `getHeaders` function.
headers = input.getHeaders()
else headers = input as HeadersObject
} else if (
'getSetCookie' in input &&
typeof input.getSetCookie === 'function'
) {
// The input is a node-style response object.
headers = input as HeadersObject
} else {
// The input is a JSON object that contains all the headers. Make sure all
// the header names are in lower case.
headers = Object.fromEntries(
Object.entries(input).map(([k, v]) => [k.toLowerCase(), v]),
) as HeadersObject
}

// If the header is a combined header, parse it according to the 7th draft of
// the IETF spec.
Expand Down

0 comments on commit 524e351

Please sign in to comment.