forked from tomphttp/bare-server-node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheaderUtil.js
More file actions
34 lines (27 loc) · 762 Bytes
/
Copy pathheaderUtil.js
File metadata and controls
34 lines (27 loc) · 762 Bytes
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
export function objectFromRawHeaders(raw) {
const result = Object.setPrototypeOf({}, null);
for (let i = 0; i < raw.length; i += 2) {
let [header, value] = raw.slice(i, i + 2);
if (result[header] != void [])
result[header] = [].concat(result[header], value);
else result[header] = value;
}
return result;
}
export function rawHeaderNames(raw) {
const result = [];
for (let i = 0; i < raw.length; i += 2) {
if (!result.includes(i)) result.push(raw[i]);
}
return result;
}
export function mapHeadersFromArray(/*Array*/ from, /*Object*/ to) {
for (let header of from) {
if (to[header.toLowerCase()] != void []) {
const value = to[header.toLowerCase()];
delete to[header.toLowerCase()];
to[header] = value;
}
}
return to;
}