JSPM

@middy/http-header-normalizer

3.0.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 71820
  • Score
    100M100P100Q179318F
  • License MIT

Http header normalizer middleware for the middy framework

Package Exports

  • @middy/http-header-normalizer

Readme

Middy http-header-normalizer middleware

Middy logo

HTTP header normalizer middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda

npm version npm install size GitHub Actions CI status badge
Standard Code Style Known Vulnerabilities Language grade: JavaScript Core Infrastructure Initiative (CII) Best Practices
Chat on Gitter Ask questions on StackOverflow

You can read the documentation at: https://middy.js.org/docs/middlewares/http-header-normalizer

This middleware normalizes HTTP header names to their canonical format. Very useful if clients are not using the canonical names of header (e.g. content-type as opposed to Content-Type).

API Gateway does not perform any normalization, so the headers are propagated to Lambda exactly as they were sent by the client.

Other middlewares like jsonBodyParser or urlEncodeBodyParser will rely on headers to be in the canonical format, so if you want to support non-normalized headers in your app you have to use this middleware before those ones.

This middleware will copy the original headers in event.rawHeaders.

Install

To install this middleware you can use NPM:

npm install --save @middy/http-header-normalizer

Options

  • normalizeHeaderKey (function): a function that accepts an header name as a parameter and returns its canonical representation.
  • canonical (boolean) (default false): if true, modifies the headers to canonical format, otherwise the headers are normalized to lowercase

Sample usage

import middy from '@middy/core'
import httpHeaderNormalizer from '@middy/http-header-normalizer'

const handler = middy((event, context) => {
  return {}
})

handler
  .use(httpHeaderNormalizer({canonical: true}))

Middy documentation and examples

For more documentation and examples, refers to the main Middy monorepo on GitHub or Middy official website.

Contributing

Everyone is very welcome to contribute to this repository. Feel free to raise issues or to submit Pull Requests.

License

Licensed under MIT License. Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the Middy team.

FOSSA Status