@middy/http-header-normalizer 2.5.6 → 2.5.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/index.js +34 -69
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -1,95 +1,60 @@
|
|
|
1
|
-
|
|
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
|
+
"use strict";
|
|
31
2
|
|
|
3
|
+
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'];
|
|
32
4
|
const exceptions = exceptionsList.reduce((acc, curr) => {
|
|
33
|
-
acc[curr.toLowerCase()] = curr
|
|
34
|
-
return acc
|
|
35
|
-
}, {})
|
|
5
|
+
acc[curr.toLowerCase()] = curr;
|
|
6
|
+
return acc;
|
|
7
|
+
}, {});
|
|
36
8
|
|
|
37
9
|
const normalizeHeaderKey = (key, canonical) => {
|
|
38
10
|
if (exceptions[key.toLowerCase()]) {
|
|
39
|
-
return exceptions[key.toLowerCase()]
|
|
11
|
+
return exceptions[key.toLowerCase()];
|
|
40
12
|
}
|
|
41
13
|
|
|
42
14
|
if (!canonical) {
|
|
43
|
-
return key.toLowerCase()
|
|
15
|
+
return key.toLowerCase();
|
|
44
16
|
}
|
|
45
17
|
|
|
46
|
-
return key
|
|
47
|
-
|
|
48
|
-
.map((text) => text[0].toUpperCase() + text.substr(1).toLowerCase())
|
|
49
|
-
.join('-')
|
|
50
|
-
}
|
|
18
|
+
return key.split('-').map(text => text[0].toUpperCase() + text.substr(1).toLowerCase()).join('-');
|
|
19
|
+
};
|
|
51
20
|
|
|
52
21
|
const defaults = {
|
|
53
22
|
canonical: false,
|
|
54
23
|
normalizeHeaderKey
|
|
55
|
-
}
|
|
24
|
+
};
|
|
56
25
|
|
|
57
26
|
const httpHeaderNormalizerMiddleware = (opts = {}) => {
|
|
58
|
-
const options = { ...defaults,
|
|
27
|
+
const options = { ...defaults,
|
|
28
|
+
...opts
|
|
29
|
+
};
|
|
59
30
|
|
|
60
|
-
const httpHeaderNormalizerMiddlewareBefore = async
|
|
31
|
+
const httpHeaderNormalizerMiddlewareBefore = async request => {
|
|
61
32
|
if (request.event.headers) {
|
|
62
|
-
const rawHeaders = {}
|
|
63
|
-
const headers = {}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
request.event.headers = headers
|
|
72
|
-
request.event.rawHeaders = rawHeaders
|
|
33
|
+
const rawHeaders = {};
|
|
34
|
+
const headers = {};
|
|
35
|
+
Object.keys(request.event.headers).forEach(key => {
|
|
36
|
+
rawHeaders[key] = request.event.headers[key];
|
|
37
|
+
headers[options.normalizeHeaderKey(key, options.canonical)] = request.event.headers[key];
|
|
38
|
+
});
|
|
39
|
+
request.event.headers = headers;
|
|
40
|
+
request.event.rawHeaders = rawHeaders;
|
|
73
41
|
}
|
|
74
42
|
|
|
75
43
|
if (request.event.multiValueHeaders) {
|
|
76
|
-
const rawHeaders = {}
|
|
77
|
-
const headers = {}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
request.event.multiValueHeaders = headers
|
|
86
|
-
request.event.rawMultiValueHeaders = rawHeaders
|
|
44
|
+
const rawHeaders = {};
|
|
45
|
+
const headers = {};
|
|
46
|
+
Object.keys(request.event.multiValueHeaders).forEach(key => {
|
|
47
|
+
rawHeaders[key] = request.event.multiValueHeaders[key];
|
|
48
|
+
headers[options.normalizeHeaderKey(key, options.canonical)] = request.event.multiValueHeaders[key];
|
|
49
|
+
});
|
|
50
|
+
request.event.multiValueHeaders = headers;
|
|
51
|
+
request.event.rawMultiValueHeaders = rawHeaders;
|
|
87
52
|
}
|
|
88
|
-
}
|
|
53
|
+
};
|
|
89
54
|
|
|
90
55
|
return {
|
|
91
56
|
before: httpHeaderNormalizerMiddlewareBefore
|
|
92
|
-
}
|
|
93
|
-
}
|
|
57
|
+
};
|
|
58
|
+
};
|
|
94
59
|
|
|
95
|
-
module.exports = httpHeaderNormalizerMiddleware
|
|
60
|
+
module.exports = httpHeaderNormalizerMiddleware;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/http-header-normalizer",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.7",
|
|
4
4
|
"description": "Http header normalizer middleware for the middy framework",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"engines": {
|
|
@@ -47,8 +47,8 @@
|
|
|
47
47
|
"url": "https://github.com/middyjs/middy/issues"
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://github.com/middyjs/middy#readme",
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "3983c4b138e1a4d7fcb3ed805d3b8832fff06fc1",
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@middy/core": "^2.5.
|
|
52
|
+
"@middy/core": "^2.5.7"
|
|
53
53
|
}
|
|
54
54
|
}
|