Skip to content

Instantly share code, notes, and snippets.

@grahamb
Created October 17, 2019 17:18
Show Gist options
  • Save grahamb/91f1ffa4bd16a03b4c2193d5ec3dfe57 to your computer and use it in GitHub Desktop.
Save grahamb/91f1ffa4bd16a03b4c2193d5ec3dfe57 to your computer and use it in GitHub Desktop.
// 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