@middy/http-header-normalizer 3.0.0-alpha.3 → 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.
- package/README.md +25 -15
- package/index.js +2 -94
- 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="
|
|
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://
|
|
20
|
-
<img src="https://img.shields.io/
|
|
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"
|
|
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)
|
|
61
|
+
- `normalizeHeaderKey` (function): a function that accepts an header name as a parameter and returns its
|
|
52
62
|
canonical representation.
|
|
53
|
-
- `canonical` (
|
|
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,95 +1,3 @@
|
|
|
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
|
-
]
|
|
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
|
|
31
2
|
|
|
32
|
-
|
|
33
|
-
acc[curr.toLowerCase()] = curr
|
|
34
|
-
return acc
|
|
35
|
-
}, {})
|
|
36
|
-
|
|
37
|
-
const normalizeHeaderKey = (key, canonical) => {
|
|
38
|
-
if (exceptions[key.toLowerCase()]) {
|
|
39
|
-
return exceptions[key.toLowerCase()]
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!canonical) {
|
|
43
|
-
return key.toLowerCase()
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return key
|
|
47
|
-
.split('-')
|
|
48
|
-
.map((text) => text[0].toUpperCase() + text.substr(1).toLowerCase())
|
|
49
|
-
.join('-')
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const defaults = {
|
|
53
|
-
canonical: false,
|
|
54
|
-
normalizeHeaderKey
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const httpHeaderNormalizerMiddleware = (opts = {}) => {
|
|
58
|
-
const options = { ...defaults, ...opts }
|
|
59
|
-
|
|
60
|
-
const httpHeaderNormalizerMiddlewareBefore = async (request) => {
|
|
61
|
-
if (request.event.headers) {
|
|
62
|
-
const rawHeaders = {}
|
|
63
|
-
const headers = {}
|
|
64
|
-
|
|
65
|
-
Object.keys(request.event.headers).forEach((key) => {
|
|
66
|
-
rawHeaders[key] = request.event.headers[key]
|
|
67
|
-
headers[options.normalizeHeaderKey(key, options.canonical)] =
|
|
68
|
-
request.event.headers[key]
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
request.event.headers = headers
|
|
72
|
-
request.event.rawHeaders = rawHeaders
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (request.event.multiValueHeaders) {
|
|
76
|
-
const rawHeaders = {}
|
|
77
|
-
const headers = {}
|
|
78
|
-
|
|
79
|
-
Object.keys(request.event.multiValueHeaders).forEach((key) => {
|
|
80
|
-
rawHeaders[key] = request.event.multiValueHeaders[key]
|
|
81
|
-
headers[options.normalizeHeaderKey(key, options.canonical)] =
|
|
82
|
-
request.event.multiValueHeaders[key]
|
|
83
|
-
})
|
|
84
|
-
|
|
85
|
-
request.event.multiValueHeaders = headers
|
|
86
|
-
request.event.rawMultiValueHeaders = rawHeaders
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return {
|
|
91
|
-
before: httpHeaderNormalizerMiddlewareBefore
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
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.
|
|
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": "
|
|
52
|
+
"gitHead": "5cef39ebe49c201f97d71bb0680004de4b82cb91",
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@middy/core": "^3.0.0-alpha.
|
|
54
|
+
"@middy/core": "^3.0.0-alpha.7"
|
|
55
55
|
}
|
|
56
56
|
}
|