forked from nghttp2/nghttp2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nghttpd: Use faster request header handling
- Loading branch information
1 parent
aaf0dc8
commit 8e3406a
Showing
5 changed files
with
353 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
#!/usr/bin/env python | ||
|
||
HEADERS = [ | ||
':authority', | ||
':method', | ||
':path', | ||
':scheme', | ||
# disallowed h1 headers | ||
'connection', | ||
'expect', | ||
'host', | ||
'if-modified-since', | ||
'keep-alive', | ||
'proxy-connection', | ||
'te', | ||
'transfer-encoding', | ||
'upgrade' | ||
] | ||
|
||
def to_enum_hd(k): | ||
res = 'HD_' | ||
for c in k.upper(): | ||
if c == ':': | ||
continue | ||
if c == '-': | ||
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 '''\ | ||
void index_header(int *hdidx, const uint8_t *s, size_t len, size_t idx) { | ||
switch (len) {''' | ||
b = build_header(HEADERS) | ||
for size in sorted(b.keys()): | ||
ents = b[size] | ||
print '''\ | ||
case {}:'''.format(size) | ||
print '''\ | ||
switch (util::lowcase(s[len - 1])) {''' | ||
for c in sorted(ents.keys()): | ||
headers = sorted(ents[c]) | ||
print '''\ | ||
case '{}':'''.format(c) | ||
for k in headers: | ||
print '''\ | ||
if (util::strieq("{}", s, {})) {{ | ||
hdidx[{}] = idx; | ||
return; | ||
}}'''.format(k[:-1], size - 1, to_enum_hd(k)) | ||
print '''\ | ||
break;''' | ||
print '''\ | ||
} | ||
break;''' | ||
print '''\ | ||
} | ||
}''' | ||
|
||
if __name__ == '__main__': | ||
gen_enum() | ||
print '' | ||
gen_index_header() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.