Created
October 17, 2019 17:18
-
-
Save grahamb/91f1ffa4bd16a03b4c2193d5ec3dfe57 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// AWS sends some request headers as all-lower-case, and others as mixed-case. Normalize them for great justice. | |
// Hat-tip: | |
// https://architecture-as-text.slack.com/archives/C6BGT0D08/p1571179244177200?thread_ts=1571178938.175700&cid=C6BGT0D08 | |
module.exports = req => { | |
const headerKeys = Object.keys(req.headers); | |
const normalizedHeaders = { | |
...req.headers, | |
}; | |
headerKeys.forEach(header => { | |
const lcHeader = header.toLowerCase(); | |
if (!req.headers.hasOwnProperty(lcHeader)) { | |
normalizedHeaders[lcHeader] = req.headers[header]; | |
} | |
}); | |
req.headers = normalizedHeaders; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment