@middy/http-header-normalizer 3.0.0-alpha.6 → 3.0.0-alpha.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +25 -15
  2. package/index.js +2 -57
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -1,26 +1,36 @@
1
- # Middy http-header-normalizer middleware
2
-
3
- <div align="center">
4
- <img alt="Middy logo" src="https://raw.githubusercontent.com/middyjs/middy/main/docs/img/middy-logo.png"/>
5
- </div>
6
-
7
1
  <div align="center">
2
+ <h1>Middy http-header-normalizer middleware</h1>
3
+ <img alt="Middy logo" src="https://raw.githubusercontent.com/middyjs/middy/main/docs/img/middy-logo.svg"/>
8
4
  <p><strong>HTTP header normalizer middleware for the middy framework, the stylish Node.js middleware engine for AWS Lambda</strong></p>
9
- </div>
10
-
11
- <div align="center">
12
5
  <p>
13
- <a href="http://badge.fury.io/js/%40middy%2Fhttp-header-normalizer">
6
+ <a href="https://www.npmjs.com/package/@middy/http-header-normalizer?activeTab=versions">
14
7
  <img src="https://badge.fury.io/js/%40middy%2Fhttp-header-normalizer.svg" alt="npm version" style="max-width:100%;">
15
8
  </a>
9
+ <a href="https://packagephobia.com/result?p=@middy/http-header-normalizer">
10
+ <img src="https://packagephobia.com/badge?p=@middy/http-header-normalizer" alt="npm install size" style="max-width:100%;">
11
+ </a>
12
+ <a href="https://github.com/middyjs/middy/actions">
13
+ <img src="https://github.com/middyjs/middy/workflows/Tests/badge.svg" alt="GitHub Actions test status badge" style="max-width:100%;">
14
+ </a>
15
+ <br/>
16
+ <a href="https://standardjs.com/">
17
+ <img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="Standard Code Style" style="max-width:100%;">
18
+ </a>
16
19
  <a href="https://snyk.io/test/github/middyjs/middy">
17
20
  <img src="https://snyk.io/test/github/middyjs/middy/badge.svg" alt="Known Vulnerabilities" data-canonical-src="https://snyk.io/test/github/middyjs/middy" style="max-width:100%;">
18
21
  </a>
19
- <a href="https://standardjs.com/">
20
- <img src="https://img.shields.io/badge/code_style-standard-brightgreen.svg" alt="Standard Code Style" style="max-width:100%;">
22
+ <a href="https://lgtm.com/projects/g/middyjs/middy/context:javascript">
23
+ <img src="https://img.shields.io/lgtm/grade/javascript/g/middyjs/middy.svg?logo=lgtm&logoWidth=18" alt="Language grade: JavaScript" style="max-width:100%;">
24
+ </a>
25
+ <a href="https://bestpractices.coreinfrastructure.org/projects/5280">
26
+ <img src="https://bestpractices.coreinfrastructure.org/projects/5280/badge" alt="Core Infrastructure Initiative (CII) Best Practices" style="max-width:100%;">
21
27
  </a>
28
+ <br/>
22
29
  <a href="https://gitter.im/middyjs/Lobby">
23
- <img src="https://badges.gitter.im/gitterHQ/gitter.svg" alt="Chat on Gitter" style="max-width:100%;">
30
+ <img src="https://badges.gitter.im/gitterHQ/gitter.svg" alt="Chat on Gitter" style="max-width:100%;">
31
+ </a>
32
+ <a href="https://stackoverflow.com/questions/tagged/middy?sort=Newest&uqlId=35052">
33
+ <img src="https://img.shields.io/badge/StackOverflow-[middy]-yellow" alt="Ask questions on StackOverflow" style="max-width:100%;">
24
34
  </a>
25
35
  </p>
26
36
  </div>
@@ -48,9 +58,9 @@ npm install --save @middy/http-header-normalizer
48
58
 
49
59
  ## Options
50
60
 
51
- - `normalizeHeaderKey` (function) (optional): a function that accepts an header name as a parameter and returns its
61
+ - `normalizeHeaderKey` (function): a function that accepts an header name as a parameter and returns its
52
62
  canonical representation.
53
- - `canonical` (bool) (optional): if true, modifies the headers to canonical format, otherwise the headers are normalized to lowercase (default `false`)
63
+ - `canonical` (boolean) (default `false`): if true, modifies the headers to canonical format, otherwise the headers are normalized to lowercase
54
64
 
55
65
 
56
66
  ## Sample usage
package/index.js CHANGED
@@ -1,58 +1,3 @@
1
- const exceptionsList = ['ALPN', 'C-PEP', 'C-PEP-Info', 'CalDAV-Timezones', 'Content-ID', 'Content-MD5', 'DASL', 'DAV', 'DNT', 'ETag', 'GetProfile', 'HTTP2-Settings', 'Last-Event-ID', 'MIME-Version', 'Optional-WWW-Authenticate', 'Sec-WebSocket-Accept', 'Sec-WebSocket-Extensions', 'Sec-WebSocket-Key', 'Sec-WebSocket-Protocol', 'Sec-WebSocket-Version', 'SLUG', 'TCN', 'TE', 'TTL', 'WWW-Authenticate', 'X-ATT-DeviceId', 'X-DNSPrefetch-Control', 'X-UIDH'];
2
- const exceptions = exceptionsList.reduce((acc, curr) => {
3
- acc[curr.toLowerCase()] = curr;
4
- return acc;
5
- }, {});
1
+ const exceptionsList=['ALPN','C-PEP','C-PEP-Info','CalDAV-Timezones','Content-ID','Content-MD5','DASL','DAV','DNT','ETag','GetProfile','HTTP2-Settings','Last-Event-ID','MIME-Version','Optional-WWW-Authenticate','Sec-WebSocket-Accept','Sec-WebSocket-Extensions','Sec-WebSocket-Key','Sec-WebSocket-Protocol','Sec-WebSocket-Version','SLUG','TCN','TE','TTL','WWW-Authenticate','X-ATT-DeviceId','X-DNSPrefetch-Control','X-UIDH'];const exceptions=exceptionsList.reduce((acc,curr)=>{acc[curr.toLowerCase()]=curr;return acc},{});const normalizeHeaderKey=(key,canonical)=>{if(exceptions[key.toLowerCase()]){return exceptions[key.toLowerCase()]}if(!canonical){return key.toLowerCase()}return key.split('-').map(text=>text[0].toUpperCase()+text.substr(1).toLowerCase()).join('-')};const defaults={canonical:false,normalizeHeaderKey};const httpHeaderNormalizerMiddleware=(opts={})=>{const options={...defaults,...opts};const httpHeaderNormalizerMiddlewareBefore=async request=>{if(request.event.headers){const rawHeaders={};const headers={};Object.keys(request.event.headers).forEach(key=>{rawHeaders[key]=request.event.headers[key];headers[options.normalizeHeaderKey(key,options.canonical)]=request.event.headers[key]});request.event.headers=headers;request.event.rawHeaders=rawHeaders}if(request.event.multiValueHeaders){const rawHeaders={};const headers={};Object.keys(request.event.multiValueHeaders).forEach(key=>{rawHeaders[key]=request.event.multiValueHeaders[key];headers[options.normalizeHeaderKey(key,options.canonical)]=request.event.multiValueHeaders[key]});request.event.multiValueHeaders=headers;request.event.rawMultiValueHeaders=rawHeaders}};return{before:httpHeaderNormalizerMiddlewareBefore}};export default httpHeaderNormalizerMiddleware
6
2
 
7
- const normalizeHeaderKey = (key, canonical) => {
8
- if (exceptions[key.toLowerCase()]) {
9
- return exceptions[key.toLowerCase()];
10
- }
11
-
12
- if (!canonical) {
13
- return key.toLowerCase();
14
- }
15
-
16
- return key.split('-').map(text => text[0].toUpperCase() + text.substr(1).toLowerCase()).join('-');
17
- };
18
-
19
- const defaults = {
20
- canonical: false,
21
- normalizeHeaderKey
22
- };
23
-
24
- const httpHeaderNormalizerMiddleware = (opts = {}) => {
25
- const options = { ...defaults,
26
- ...opts
27
- };
28
-
29
- const httpHeaderNormalizerMiddlewareBefore = async request => {
30
- if (request.event.headers) {
31
- const rawHeaders = {};
32
- const headers = {};
33
- Object.keys(request.event.headers).forEach(key => {
34
- rawHeaders[key] = request.event.headers[key];
35
- headers[options.normalizeHeaderKey(key, options.canonical)] = request.event.headers[key];
36
- });
37
- request.event.headers = headers;
38
- request.event.rawHeaders = rawHeaders;
39
- }
40
-
41
- if (request.event.multiValueHeaders) {
42
- const rawHeaders = {};
43
- const headers = {};
44
- Object.keys(request.event.multiValueHeaders).forEach(key => {
45
- rawHeaders[key] = request.event.multiValueHeaders[key];
46
- headers[options.normalizeHeaderKey(key, options.canonical)] = request.event.multiValueHeaders[key];
47
- });
48
- request.event.multiValueHeaders = headers;
49
- request.event.rawMultiValueHeaders = rawHeaders;
50
- }
51
- };
52
-
53
- return {
54
- before: httpHeaderNormalizerMiddlewareBefore
55
- };
56
- };
57
-
58
- export default httpHeaderNormalizerMiddleware;
3
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middy/http-header-normalizer",
3
- "version": "3.0.0-alpha.6",
3
+ "version": "3.0.0-alpha.7",
4
4
  "description": "Http header normalizer middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -49,8 +49,8 @@
49
49
  "url": "https://github.com/middyjs/middy/issues"
50
50
  },
51
51
  "homepage": "https://github.com/middyjs/middy#readme",
52
- "gitHead": "176660ed3e0716d6bfb635c77251b301e0e24720",
52
+ "gitHead": "5cef39ebe49c201f97d71bb0680004de4b82cb91",
53
53
  "devDependencies": {
54
- "@middy/core": "^3.0.0-alpha.6"
54
+ "@middy/core": "^3.0.0-alpha.7"
55
55
  }
56
56
  }