@middy/http-header-normalizer 6.1.6 → 6.2.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/index.d.ts +9 -9
- package/index.js +84 -84
- package/package.json +67 -70
package/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import middy from
|
|
1
|
+
import type middy from "@middy/core";
|
|
2
2
|
|
|
3
3
|
interface Options {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
canonical?: boolean;
|
|
5
|
+
defaultHeaders?: Record<string, string>;
|
|
6
|
+
normalizeHeaderKey?: (key: string) => string;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
10
|
-
export
|
|
10
|
+
export type Event = {};
|
|
11
11
|
|
|
12
|
-
declare function httpHeaderNormalizer
|
|
13
|
-
|
|
14
|
-
): middy.MiddlewareObj<Event
|
|
12
|
+
declare function httpHeaderNormalizer(
|
|
13
|
+
options?: Options,
|
|
14
|
+
): middy.MiddlewareObj<Event>;
|
|
15
15
|
|
|
16
|
-
export default httpHeaderNormalizer
|
|
16
|
+
export default httpHeaderNormalizer;
|
package/index.js
CHANGED
|
@@ -1,104 +1,104 @@
|
|
|
1
1
|
const exceptionsList = [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
]
|
|
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
31
|
|
|
32
32
|
const exceptions = exceptionsList.reduce((acc, curr) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}, {})
|
|
33
|
+
acc[curr.toLowerCase()] = curr;
|
|
34
|
+
return acc;
|
|
35
|
+
}, {});
|
|
36
36
|
|
|
37
37
|
const normalizeHeaderKey = (key, canonical) => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
const lowerCaseKey = key.toLowerCase();
|
|
39
|
+
if (!canonical) {
|
|
40
|
+
return lowerCaseKey;
|
|
41
|
+
}
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
if (exceptions[lowerCaseKey]) {
|
|
44
|
+
return exceptions[lowerCaseKey];
|
|
45
|
+
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
47
|
+
return lowerCaseKey
|
|
48
|
+
.split("-")
|
|
49
|
+
.map((text) => (text[0] || "").toUpperCase() + text.substr(1))
|
|
50
|
+
.join("-");
|
|
51
|
+
};
|
|
52
52
|
|
|
53
53
|
const defaults = {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
54
|
+
canonical: false,
|
|
55
|
+
defaultHeaders: {},
|
|
56
|
+
normalizeHeaderKey,
|
|
57
|
+
};
|
|
58
58
|
|
|
59
59
|
const httpHeaderNormalizerMiddleware = (opts = {}) => {
|
|
60
|
-
|
|
60
|
+
const options = { ...defaults, ...opts };
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
62
|
+
const defaultHeaders = {};
|
|
63
|
+
const defaultMultiValueHeaders = {};
|
|
64
|
+
for (const key of Object.keys(options.defaultHeaders)) {
|
|
65
|
+
const newKey = options.normalizeHeaderKey(key, options.canonical);
|
|
66
|
+
const isArray = Array.isArray(options.defaultHeaders[key]);
|
|
67
|
+
defaultHeaders[newKey] = isArray
|
|
68
|
+
? options.defaultHeaders[key].join(",")
|
|
69
|
+
: options.defaultHeaders[key];
|
|
70
|
+
defaultMultiValueHeaders[newKey] = isArray
|
|
71
|
+
? options.defaultHeaders[key]
|
|
72
|
+
: options.defaultHeaders[key].split(",");
|
|
73
|
+
}
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
const httpHeaderNormalizerMiddlewareBefore = async (request) => {
|
|
76
|
+
if (request.event.headers) {
|
|
77
|
+
const headers = { ...defaultHeaders };
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
for (const key of Object.keys(request.event.headers)) {
|
|
80
|
+
headers[options.normalizeHeaderKey(key, options.canonical)] =
|
|
81
|
+
request.event.headers[key];
|
|
82
|
+
}
|
|
83
83
|
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
request.event.headers = headers;
|
|
85
|
+
}
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
if (request.event.multiValueHeaders) {
|
|
88
|
+
const headers = { ...defaultMultiValueHeaders };
|
|
89
89
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
for (const key of Object.keys(request.event.multiValueHeaders)) {
|
|
91
|
+
headers[options.normalizeHeaderKey(key, options.canonical)] =
|
|
92
|
+
request.event.multiValueHeaders[key];
|
|
93
|
+
}
|
|
94
94
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
request.event.multiValueHeaders = headers;
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
99
|
+
return {
|
|
100
|
+
before: httpHeaderNormalizerMiddlewareBefore,
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
103
|
|
|
104
|
-
export default httpHeaderNormalizerMiddleware
|
|
104
|
+
export default httpHeaderNormalizerMiddleware;
|
package/package.json
CHANGED
|
@@ -1,72 +1,69 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"devDependencies": {
|
|
70
|
-
"@middy/core": "6.1.6"
|
|
71
|
-
}
|
|
2
|
+
"name": "@middy/http-header-normalizer",
|
|
3
|
+
"version": "6.2.0",
|
|
4
|
+
"description": "Http header normalizer middleware for the middy framework",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"engines": {
|
|
7
|
+
"node": ">=20"
|
|
8
|
+
},
|
|
9
|
+
"engineStrict": true,
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"module": "./index.js",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./index.d.ts",
|
|
18
|
+
"default": "./index.js"
|
|
19
|
+
},
|
|
20
|
+
"require": {
|
|
21
|
+
"default": "./index.js"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"types": "index.d.ts",
|
|
26
|
+
"files": ["index.js", "index.d.ts"],
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "npm run test:unit && npm run test:fuzz",
|
|
29
|
+
"test:unit": "node --test",
|
|
30
|
+
"test:fuzz": "node --test index.fuzz.js",
|
|
31
|
+
"test:perf": "node --test index.perf.js"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"keywords": [
|
|
35
|
+
"Lambda",
|
|
36
|
+
"Middleware",
|
|
37
|
+
"Serverless",
|
|
38
|
+
"Framework",
|
|
39
|
+
"AWS",
|
|
40
|
+
"AWS Lambda",
|
|
41
|
+
"Middy",
|
|
42
|
+
"HTTP",
|
|
43
|
+
"API",
|
|
44
|
+
"Header",
|
|
45
|
+
"Headers",
|
|
46
|
+
"Header normalizer"
|
|
47
|
+
],
|
|
48
|
+
"author": {
|
|
49
|
+
"name": "Middy contributors",
|
|
50
|
+
"url": "https://github.com/middyjs/middy/graphs/contributors"
|
|
51
|
+
},
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "git+https://github.com/middyjs/middy.git",
|
|
55
|
+
"directory": "packages/http-header-normalizer"
|
|
56
|
+
},
|
|
57
|
+
"bugs": {
|
|
58
|
+
"url": "https://github.com/middyjs/middy/issues"
|
|
59
|
+
},
|
|
60
|
+
"homepage": "https://middy.js.org",
|
|
61
|
+
"funding": {
|
|
62
|
+
"type": "github",
|
|
63
|
+
"url": "https://github.com/sponsors/willfarrell"
|
|
64
|
+
},
|
|
65
|
+
"gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431",
|
|
66
|
+
"devDependencies": {
|
|
67
|
+
"@middy/core": "6.2.0"
|
|
68
|
+
}
|
|
72
69
|
}
|