@middy/http-header-normalizer 3.0.2 → 3.1.0-rc.0

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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2017-2022 Luciano Mammino, will Farrell and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
3
+ Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell) and the [Middy team](https://github.com/middyjs/middy/graphs/contributors)
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -9,8 +9,8 @@
9
9
  <a href="https://packagephobia.com/result?p=@middy/http-header-normalizer">
10
10
  <img src="https://packagephobia.com/badge?p=@middy/http-header-normalizer" alt="npm install size" style="max-width:100%;">
11
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%;">
12
+ <a href="https://github.com/middyjs/middy/actions/workflows/tests.yml">
13
+ <img src="https://github.com/middyjs/middy/actions/workflows/tests.yml/badge.svg?branch=main&event=push" alt="GitHub Actions CI status badge" style="max-width:100%;">
14
14
  </a>
15
15
  <br/>
16
16
  <a href="https://standardjs.com/">
@@ -33,6 +33,7 @@
33
33
  <img src="https://img.shields.io/badge/StackOverflow-[middy]-yellow" alt="Ask questions on StackOverflow" style="max-width:100%;">
34
34
  </a>
35
35
  </p>
36
+ <p>You can read the documentation at: <a href="https://middy.js.org/docs/middlewares/http-header-normalizer">https://middy.js.org/docs/middlewares/http-header-normalizer</a></p>
36
37
  </div>
37
38
 
38
39
  This middleware normalizes HTTP header names to their canonical format. Very useful if clients are
@@ -90,7 +91,7 @@ Everyone is very welcome to contribute to this repository. Feel free to [raise i
90
91
 
91
92
  ## License
92
93
 
93
- Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 Luciano Mammino, will Farrell, and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
94
+ Licensed under [MIT License](LICENSE). Copyright (c) 2017-2022 [Luciano Mammino](https://github.com/lmammino), [will Farrell](https://github.com/willfarrell), and the [Middy team](https://github.com/middyjs/middy/graphs/contributors).
94
95
 
95
96
  <a href="https://app.fossa.io/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy?ref=badge_large">
96
97
  <img src="https://app.fossa.io/api/projects/git%2Bgithub.com%2Fmiddyjs%2Fmiddy.svg?type=large" alt="FOSSA Status" style="max-width:100%;">
package/index.cjs CHANGED
@@ -1,3 +1,89 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;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)=>{const lowerCaseKey=key.toLowerCase();if(!canonical){return lowerCaseKey}if(exceptions[lowerCaseKey]){return exceptions[lowerCaseKey]}return lowerCaseKey.split("-").map(text=>text[0].toUpperCase()+text.substr(1)).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={};for(const key of Object.keys(request.event.headers)){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={};for(const key of Object.keys(request.event.multiValueHeaders)){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}};var _default=httpHeaderNormalizerMiddleware;exports.default=_default
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ module.exports = void 0;
6
+ const exceptionsList = [
7
+ 'ALPN',
8
+ 'C-PEP',
9
+ 'C-PEP-Info',
10
+ 'CalDAV-Timezones',
11
+ 'Content-ID',
12
+ 'Content-MD5',
13
+ 'DASL',
14
+ 'DAV',
15
+ 'DNT',
16
+ 'ETag',
17
+ 'GetProfile',
18
+ 'HTTP2-Settings',
19
+ 'Last-Event-ID',
20
+ 'MIME-Version',
21
+ 'Optional-WWW-Authenticate',
22
+ 'Sec-WebSocket-Accept',
23
+ 'Sec-WebSocket-Extensions',
24
+ 'Sec-WebSocket-Key',
25
+ 'Sec-WebSocket-Protocol',
26
+ 'Sec-WebSocket-Version',
27
+ 'SLUG',
28
+ 'TCN',
29
+ 'TE',
30
+ 'TTL',
31
+ 'WWW-Authenticate',
32
+ 'X-ATT-DeviceId',
33
+ 'X-DNSPrefetch-Control',
34
+ 'X-UIDH'
35
+ ];
36
+ const exceptions = exceptionsList.reduce((acc, curr)=>{
37
+ acc[curr.toLowerCase()] = curr;
38
+ return acc;
39
+ }, {});
40
+ const normalizeHeaderKey = (key, canonical)=>{
41
+ const lowerCaseKey = key.toLowerCase();
42
+ if (!canonical) {
43
+ return lowerCaseKey;
44
+ }
45
+ if (exceptions[lowerCaseKey]) {
46
+ return exceptions[lowerCaseKey];
47
+ }
48
+ return lowerCaseKey.split('-').map((text)=>text[0].toUpperCase() + text.substr(1)).join('-');
49
+ };
50
+ const defaults = {
51
+ canonical: false,
52
+ normalizeHeaderKey
53
+ };
54
+ const httpHeaderNormalizerMiddleware = (opts = {})=>{
55
+ const options = {
56
+ ...defaults,
57
+ ...opts
58
+ };
59
+ const httpHeaderNormalizerMiddlewareBefore = async (request)=>{
60
+ if (request.event.headers) {
61
+ const rawHeaders = {};
62
+ const headers = {};
63
+ for (const key of Object.keys(request.event.headers)){
64
+ rawHeaders[key] = request.event.headers[key];
65
+ headers[options.normalizeHeaderKey(key, options.canonical)] = request.event.headers[key];
66
+ }
67
+ request.event.headers = headers;
68
+ request.event.rawHeaders = rawHeaders;
69
+ }
70
+ if (request.event.multiValueHeaders) {
71
+ const rawHeaders = {};
72
+ const headers = {};
73
+ for (const key of Object.keys(request.event.multiValueHeaders)){
74
+ rawHeaders[key] = request.event.multiValueHeaders[key];
75
+ headers[options.normalizeHeaderKey(key, options.canonical)] = request.event.multiValueHeaders[key];
76
+ }
77
+ request.event.multiValueHeaders = headers;
78
+ request.event.rawMultiValueHeaders = rawHeaders;
79
+ }
80
+ };
81
+ return {
82
+ before: httpHeaderNormalizerMiddlewareBefore
83
+ };
84
+ };
85
+ var _default = httpHeaderNormalizerMiddleware;
86
+ module.exports = _default;
87
+
2
88
 
3
89
  //# sourceMappingURL=index.cjs.map
package/index.js CHANGED
@@ -1,3 +1,83 @@
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)=>{const lowerCaseKey=key.toLowerCase();if(!canonical){return lowerCaseKey}if(exceptions[lowerCaseKey]){return exceptions[lowerCaseKey]}return lowerCaseKey.split("-").map(text=>text[0].toUpperCase()+text.substr(1)).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={};for(const key of Object.keys(request.event.headers)){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={};for(const key of Object.keys(request.event.multiValueHeaders)){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
1
+ const exceptionsList = [
2
+ 'ALPN',
3
+ 'C-PEP',
4
+ 'C-PEP-Info',
5
+ 'CalDAV-Timezones',
6
+ 'Content-ID',
7
+ 'Content-MD5',
8
+ 'DASL',
9
+ 'DAV',
10
+ 'DNT',
11
+ 'ETag',
12
+ 'GetProfile',
13
+ 'HTTP2-Settings',
14
+ 'Last-Event-ID',
15
+ 'MIME-Version',
16
+ 'Optional-WWW-Authenticate',
17
+ 'Sec-WebSocket-Accept',
18
+ 'Sec-WebSocket-Extensions',
19
+ 'Sec-WebSocket-Key',
20
+ 'Sec-WebSocket-Protocol',
21
+ 'Sec-WebSocket-Version',
22
+ 'SLUG',
23
+ 'TCN',
24
+ 'TE',
25
+ 'TTL',
26
+ 'WWW-Authenticate',
27
+ 'X-ATT-DeviceId',
28
+ 'X-DNSPrefetch-Control',
29
+ 'X-UIDH'
30
+ ];
31
+ const exceptions = exceptionsList.reduce((acc, curr)=>{
32
+ acc[curr.toLowerCase()] = curr;
33
+ return acc;
34
+ }, {});
35
+ const normalizeHeaderKey = (key, canonical)=>{
36
+ const lowerCaseKey = key.toLowerCase();
37
+ if (!canonical) {
38
+ return lowerCaseKey;
39
+ }
40
+ if (exceptions[lowerCaseKey]) {
41
+ return exceptions[lowerCaseKey];
42
+ }
43
+ return lowerCaseKey.split('-').map((text)=>text[0].toUpperCase() + text.substr(1)).join('-');
44
+ };
45
+ const defaults = {
46
+ canonical: false,
47
+ normalizeHeaderKey
48
+ };
49
+ const httpHeaderNormalizerMiddleware = (opts = {})=>{
50
+ const options = {
51
+ ...defaults,
52
+ ...opts
53
+ };
54
+ const httpHeaderNormalizerMiddlewareBefore = async (request)=>{
55
+ if (request.event.headers) {
56
+ const rawHeaders = {};
57
+ const headers = {};
58
+ for (const key of Object.keys(request.event.headers)){
59
+ rawHeaders[key] = request.event.headers[key];
60
+ headers[options.normalizeHeaderKey(key, options.canonical)] = request.event.headers[key];
61
+ }
62
+ request.event.headers = headers;
63
+ request.event.rawHeaders = rawHeaders;
64
+ }
65
+ if (request.event.multiValueHeaders) {
66
+ const rawHeaders = {};
67
+ const headers = {};
68
+ for (const key of Object.keys(request.event.multiValueHeaders)){
69
+ rawHeaders[key] = request.event.multiValueHeaders[key];
70
+ headers[options.normalizeHeaderKey(key, options.canonical)] = request.event.multiValueHeaders[key];
71
+ }
72
+ request.event.multiValueHeaders = headers;
73
+ request.event.rawMultiValueHeaders = rawHeaders;
74
+ }
75
+ };
76
+ return {
77
+ before: httpHeaderNormalizerMiddlewareBefore
78
+ };
79
+ };
80
+ export default httpHeaderNormalizerMiddleware;
81
+
2
82
 
3
83
  //# 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.2",
3
+ "version": "3.1.0-rc.0",
4
4
  "description": "Http header normalizer middleware for the middy framework",
5
5
  "type": "module",
6
6
  "engines": {
@@ -10,11 +10,17 @@
10
10
  "publishConfig": {
11
11
  "access": "public"
12
12
  },
13
+ "main": "./index.cjs",
13
14
  "exports": {
14
15
  ".": {
15
- "import": "./index.js",
16
- "require": "./index.cjs",
17
- "types": "./index.d.ts"
16
+ "import": {
17
+ "types": "./index.d.ts",
18
+ "default": "./index.js"
19
+ },
20
+ "require": {
21
+ "types": "./index.d.ts",
22
+ "default": "./index.cjs"
23
+ }
18
24
  }
19
25
  },
20
26
  "types": "index.d.ts",
@@ -56,8 +62,8 @@
56
62
  "url": "https://github.com/middyjs/middy/issues"
57
63
  },
58
64
  "homepage": "https://middy.js.org",
59
- "gitHead": "983649b8359ea32a786e75dfc2953aeee8ec6052",
65
+ "gitHead": "03a8794d3cdb4319eca49ba4c55420bea5d66430",
60
66
  "devDependencies": {
61
- "@middy/core": "^3.0.2"
67
+ "@middy/core": "3.1.0-rc.0"
62
68
  }
63
69
  }