-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmatchKnownFields3.js
More file actions
102 lines (91 loc) · 2.53 KB
/
matchKnownFields3.js
File metadata and controls
102 lines (91 loc) · 2.53 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict';
const benchmark = require('../2-benchmark.js');
const HTTP_HDR_TO_LOWER = {
'Content-Type': 'content-type',
'Content-Length': 'content-length',
'User-Agent': 'user-agent',
'Referer': 'referer',
'Host': 'host',
'Authorization': 'authorization',
'Proxy-Authorization': 'proxy-authorization',
'If-Modified-Since': 'if-modified-since',
'If-Unmodified-Since': 'if-unmodified-since',
'From': 'from',
'Location': 'location',
'Max-Forwards': 'max-forwards',
'Retry-After': 'retry-after',
'ETag': 'etag',
'Last-Modified': 'last-modified',
'Server': 'server',
'Age': 'age',
'Expires': 'expires'
};
{
let key, value;
for (key in HTTP_HDR_TO_LOWER) {
value = HTTP_HDR_TO_LOWER[key];
HTTP_HDR_TO_LOWER[value] = value;
}
}
HTTP_HDR_TO_LOWER['Set-Cookie'] = '\u0001';
HTTP_HDR_TO_LOWER['set-Cookie'] = '\u0001';
HTTP_HDR_TO_LOWER['Cookie'] = '\u0002cookie';
HTTP_HDR_TO_LOWER['cookie'] = '\u0002cookie';
const HTTP_HDR_TO_LOWER_0 = {
'Transfer-Encoding': 'transfer-encoding',
'Date': 'date',
'Connection': 'connection',
'Cache-Control': 'cache-control',
'Vary': 'vary',
'Content-Encoding': 'content-encoding',
'Origin': 'origin',
'Upgrade': 'upgrade',
'Expect': 'expect',
'If-Match': 'if-match',
'If-None-Match': 'if-none-match',
'Accept': 'accept',
'Accept-Encoding': 'accept-encoding',
'Accept-Language': 'accept-language',
'X-Forwarded-For': 'x-forwarded-for',
'X-Forwarded-Host': 'x-forwarded-host',
'X-Forwarded-Proto': 'x-forwarded-proto'
};
{
let key, value, data;
for (key in HTTP_HDR_TO_LOWER_0) {
value = HTTP_HDR_TO_LOWER_0[key];
data = '\u0000' + value;
HTTP_HDR_TO_LOWER[key] = data;
HTTP_HDR_TO_LOWER[value] = data;
}
}
const httpHdrToLowerMap = new Map();
{
let key, value;
for (key in HTTP_HDR_TO_LOWER) {
value = HTTP_HDR_TO_LOWER[key];
httpHdrToLowerMap.set(key, value);
}
}
function matchKnownFields3(field) {
let toLower;
toLower = httpHdrToLowerMap.get(field);
if (toLower) return toLower;
field = field.toLowerCase();
toLower = httpHdrToLowerMap.get(field);
if (toLower) return toLower;
return '\u0000' + field;
}
function testMatchKnownFields3() {
return [
matchKnownFields3('Authorization'),
matchKnownFields3('if-unmodified-since'),
matchKnownFields3('Content-Type'),
matchKnownFields3('last-modified'),
matchKnownFields3('X-Forwarded-For'),
matchKnownFields3('accept'),
matchKnownFields3('Cache-Control'),
matchKnownFields3('cookie')
];
}
benchmark.do(10000000, [testMatchKnownFields3]);