@middy/http-header-normalizer 3.0.0-alpha.2 → 3.0.0-alpha.3
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/index.js +70 -33
- package/package.json +5 -4
package/index.js
CHANGED
|
@@ -1,58 +1,95 @@
|
|
|
1
|
-
const exceptionsList = [
|
|
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
|
+
|
|
2
32
|
const exceptions = exceptionsList.reduce((acc, curr) => {
|
|
3
|
-
acc[curr.toLowerCase()] = curr
|
|
4
|
-
return acc
|
|
5
|
-
}, {})
|
|
33
|
+
acc[curr.toLowerCase()] = curr
|
|
34
|
+
return acc
|
|
35
|
+
}, {})
|
|
6
36
|
|
|
7
37
|
const normalizeHeaderKey = (key, canonical) => {
|
|
8
38
|
if (exceptions[key.toLowerCase()]) {
|
|
9
|
-
return exceptions[key.toLowerCase()]
|
|
39
|
+
return exceptions[key.toLowerCase()]
|
|
10
40
|
}
|
|
11
41
|
|
|
12
42
|
if (!canonical) {
|
|
13
|
-
return key.toLowerCase()
|
|
43
|
+
return key.toLowerCase()
|
|
14
44
|
}
|
|
15
45
|
|
|
16
|
-
return key
|
|
17
|
-
|
|
46
|
+
return key
|
|
47
|
+
.split('-')
|
|
48
|
+
.map((text) => text[0].toUpperCase() + text.substr(1).toLowerCase())
|
|
49
|
+
.join('-')
|
|
50
|
+
}
|
|
18
51
|
|
|
19
52
|
const defaults = {
|
|
20
53
|
canonical: false,
|
|
21
54
|
normalizeHeaderKey
|
|
22
|
-
}
|
|
55
|
+
}
|
|
23
56
|
|
|
24
57
|
const httpHeaderNormalizerMiddleware = (opts = {}) => {
|
|
25
|
-
const options = { ...defaults,
|
|
26
|
-
...opts
|
|
27
|
-
};
|
|
58
|
+
const options = { ...defaults, ...opts }
|
|
28
59
|
|
|
29
|
-
const httpHeaderNormalizerMiddlewareBefore = async request => {
|
|
60
|
+
const httpHeaderNormalizerMiddlewareBefore = async (request) => {
|
|
30
61
|
if (request.event.headers) {
|
|
31
|
-
const rawHeaders = {}
|
|
32
|
-
const headers = {}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
|
39
73
|
}
|
|
40
74
|
|
|
41
75
|
if (request.event.multiValueHeaders) {
|
|
42
|
-
const rawHeaders = {}
|
|
43
|
-
const headers = {}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
|
50
87
|
}
|
|
51
|
-
}
|
|
88
|
+
}
|
|
52
89
|
|
|
53
90
|
return {
|
|
54
91
|
before: httpHeaderNormalizerMiddlewareBefore
|
|
55
|
-
}
|
|
56
|
-
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
57
94
|
|
|
58
|
-
export default httpHeaderNormalizerMiddleware
|
|
95
|
+
export default httpHeaderNormalizerMiddleware
|
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.3",
|
|
4
4
|
"description": "Http header normalizer middleware for the middy framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
20
|
"test": "npm run test:unit",
|
|
21
|
-
"test:unit": "ava"
|
|
21
|
+
"test:unit": "ava",
|
|
22
|
+
"test:benchmark": "node __benchmarks__/index.js"
|
|
22
23
|
},
|
|
23
24
|
"license": "MIT",
|
|
24
25
|
"keywords": [
|
|
@@ -48,8 +49,8 @@
|
|
|
48
49
|
"url": "https://github.com/middyjs/middy/issues"
|
|
49
50
|
},
|
|
50
51
|
"homepage": "https://github.com/middyjs/middy#readme",
|
|
51
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "1441158711580313765e6d156046ef0fade0d156",
|
|
52
53
|
"devDependencies": {
|
|
53
|
-
"@middy/core": "^3.0.0-alpha.
|
|
54
|
+
"@middy/core": "^3.0.0-alpha.3"
|
|
54
55
|
}
|
|
55
56
|
}
|