Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NormalizeHTTPHeaders middleware #87

Closed
lmammino opened this issue Jan 14, 2018 · 3 comments
Closed

NormalizeHTTPHeaders middleware #87

lmammino opened this issue Jan 14, 2018 · 3 comments

Comments

@lmammino
Copy link
Member

Following several discussions with @vladgolubev and @dkatavic (see #85 and #75) I think we should have a middleware that makes sure that the headers in the lambda-proxy integration from API Gateway are always exposed in canonical format (dash-separated-camelcasing).

The idea of this middleware would be to go over all the available headers and reconstruct the object with all the keys properly normalized.

Thoughts?

@lmammino
Copy link
Member Author

Simple way to normalize header keys:

const assert = require('assert')

const normalize = (str) => str
  .split('-')
  .map((s) => s.charAt(0).toUpperCase() + s.slice(1))
  .join('-')

assert(normalize('content-type') === 'Content-Type')
assert(normalize('x-api-key') === 'X-Api-Key')
assert(normalize('X-Api-Key') === 'X-Api-Key')

@vladholubiev
Copy link
Contributor

@lmammino nice, but beware of some exceptions, see https://github.com/marten-de-vries/header-case-normalizer/blob/master/index.js

@lmammino
Copy link
Member Author

Great finding, thanks @vladgolubev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants