2015-01-02 16:12:26 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
HEADERS = [
|
|
|
|
':authority',
|
|
|
|
':method',
|
|
|
|
':path',
|
|
|
|
':scheme',
|
2015-01-04 15:22:39 +01:00
|
|
|
':status',
|
|
|
|
':host', # for spdy
|
2015-01-02 16:12:26 +01:00
|
|
|
'expect',
|
|
|
|
'host',
|
|
|
|
'if-modified-since',
|
2015-01-04 15:22:39 +01:00
|
|
|
"te",
|
|
|
|
"cookie",
|
|
|
|
"http2-settings",
|
|
|
|
"server",
|
|
|
|
"via",
|
|
|
|
"x-forwarded-for",
|
|
|
|
"x-forwarded-proto",
|
|
|
|
"alt-svc",
|
|
|
|
"content-length",
|
|
|
|
"location",
|
|
|
|
# disallowed h1 headers
|
|
|
|
'connection',
|
2015-01-02 16:12:26 +01:00
|
|
|
'keep-alive',
|
|
|
|
'proxy-connection',
|
|
|
|
'transfer-encoding',
|
|
|
|
'upgrade'
|
|
|
|
]
|
|
|
|
|
|
|
|
def to_enum_hd(k):
|
|
|
|
res = 'HD_'
|
|
|
|
for c in k.upper():
|
2015-01-04 15:22:39 +01:00
|
|
|
if c == ':' or c == '-':
|
2015-01-02 16:12:26 +01:00
|
|
|
res += '_'
|
|
|
|
continue
|
|
|
|
res += c
|
|
|
|
return res
|
|
|
|
|
|
|
|
def build_header(headers):
|
|
|
|
res = {}
|
|
|
|
for k in headers:
|
|
|
|
size = len(k)
|
|
|
|
if size not in res:
|
|
|
|
res[size] = {}
|
|
|
|
ent = res[size]
|
|
|
|
c = k[-1]
|
|
|
|
if c not in ent:
|
|
|
|
ent[c] = []
|
|
|
|
ent[c].append(k)
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
def gen_enum():
|
|
|
|
print '''\
|
|
|
|
enum {'''
|
|
|
|
for k in sorted(HEADERS):
|
|
|
|
print '''\
|
|
|
|
{},'''.format(to_enum_hd(k))
|
|
|
|
print '''\
|
|
|
|
HD_MAXIDX,
|
|
|
|
};'''
|
|
|
|
|
|
|
|
def gen_index_header():
|
|
|
|
print '''\
|
2015-01-04 15:22:39 +01:00
|
|
|
int lookup_token(const uint8_t *name, size_t namelen) {
|
2015-01-03 13:56:59 +01:00
|
|
|
switch (namelen) {'''
|
2015-01-02 16:12:26 +01:00
|
|
|
b = build_header(HEADERS)
|
|
|
|
for size in sorted(b.keys()):
|
|
|
|
ents = b[size]
|
|
|
|
print '''\
|
|
|
|
case {}:'''.format(size)
|
|
|
|
print '''\
|
2015-01-03 13:56:59 +01:00
|
|
|
switch (util::lowcase(name[namelen - 1])) {'''
|
2015-01-02 16:12:26 +01:00
|
|
|
for c in sorted(ents.keys()):
|
|
|
|
headers = sorted(ents[c])
|
|
|
|
print '''\
|
|
|
|
case '{}':'''.format(c)
|
|
|
|
for k in headers:
|
|
|
|
print '''\
|
2015-01-03 13:56:59 +01:00
|
|
|
if (util::streq("{}", name, {})) {{
|
2015-01-04 15:22:39 +01:00
|
|
|
return {};
|
2015-01-02 16:12:26 +01:00
|
|
|
}}'''.format(k[:-1], size - 1, to_enum_hd(k))
|
|
|
|
print '''\
|
|
|
|
break;'''
|
|
|
|
print '''\
|
|
|
|
}
|
|
|
|
break;'''
|
|
|
|
print '''\
|
|
|
|
}
|
2015-01-04 15:22:39 +01:00
|
|
|
return -1;
|
2015-01-02 16:12:26 +01:00
|
|
|
}'''
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
gen_enum()
|
|
|
|
print ''
|
|
|
|
gen_index_header()
|