1 | "use strict";
|
2 |
|
3 | module.exports = function getHeaders(request) {
|
4 | if (!request || !request.header) return {};
|
5 |
|
6 | const reqHeader = request.header;
|
7 |
|
8 | const headers = {};
|
9 | for (const name in reqHeader) {
|
10 | const lowerName = name.toLowerCase();
|
11 | let val = reqHeader[name];
|
12 | if (lowerName === "cookie") val = cleanCookie(val);
|
13 | headers[lowerName] = val;
|
14 | }
|
15 |
|
16 | return headers;
|
17 | };
|
18 |
|
19 | function cleanCookie(cookie) {
|
20 | if (!cookie) return "";
|
21 | if (!/;$/.test(cookie)) return `${cookie};`;
|
22 | return cookie;
|
23 | }
|