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.
We share the same method value with http-parser. This commit also returns 501 for unknown request method on HTTP/2 and SPDY frontend.
- Loading branch information
1 parent
f9c60d5
commit 41dd5f6
Showing
15 changed files
with
420 additions
and
107 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
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,53 @@ | ||
#!/usr/bin/env python | ||
from __future__ import unicode_literals | ||
from io import StringIO | ||
|
||
from gentokenlookup import gentokenlookup | ||
|
||
# copied from http-parser/http_parser.h, and stripped trailing spaces | ||
# and backslashes. | ||
SRC = ''' | ||
XX(0, DELETE, DELETE) | ||
XX(1, GET, GET) | ||
XX(2, HEAD, HEAD) | ||
XX(3, POST, POST) | ||
XX(4, PUT, PUT) | ||
/* pathological */ | ||
XX(5, CONNECT, CONNECT) | ||
XX(6, OPTIONS, OPTIONS) | ||
XX(7, TRACE, TRACE) | ||
/* webdav */ | ||
XX(8, COPY, COPY) | ||
XX(9, LOCK, LOCK) | ||
XX(10, MKCOL, MKCOL) | ||
XX(11, MOVE, MOVE) | ||
XX(12, PROPFIND, PROPFIND) | ||
XX(13, PROPPATCH, PROPPATCH) | ||
XX(14, SEARCH, SEARCH) | ||
XX(15, UNLOCK, UNLOCK) | ||
/* subversion */ | ||
XX(16, REPORT, REPORT) | ||
XX(17, MKACTIVITY, MKACTIVITY) | ||
XX(18, CHECKOUT, CHECKOUT) | ||
XX(19, MERGE, MERGE) | ||
/* upnp */ | ||
XX(20, MSEARCH, M-SEARCH) | ||
XX(21, NOTIFY, NOTIFY) | ||
XX(22, SUBSCRIBE, SUBSCRIBE) | ||
XX(23, UNSUBSCRIBE, UNSUBSCRIBE) | ||
/* RFC-5789 */ | ||
XX(24, PATCH, PATCH) | ||
XX(25, PURGE, PURGE) | ||
/* CalDAV */ | ||
XX(26, MKCALENDAR, MKCALENDAR) | ||
''' | ||
|
||
if __name__ == '__main__': | ||
methods = [] | ||
for line in StringIO(SRC): | ||
line = line.strip() | ||
if not line.startswith('XX'): | ||
continue | ||
_, m, _ = line.split(',', 2) | ||
methods.append(m.strip()) | ||
gentokenlookup(methods, 'HTTP') |
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,69 @@ | ||
#!/usr/bin/env python | ||
|
||
def to_enum_hd(k, prefix): | ||
res = prefix + '_' | ||
for c in k.upper(): | ||
if c == ':' or 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(tokens, prefix): | ||
print '''\ | ||
enum {''' | ||
for k in sorted(tokens): | ||
print '''\ | ||
{},'''.format(to_enum_hd(k, prefix)) | ||
print '''\ | ||
{}_MAXIDX, | ||
}};'''.format(prefix) | ||
|
||
def gen_index_header(tokens, prefix): | ||
print '''\ | ||
int lookup_token(const uint8_t *name, size_t namelen) { | ||
switch (namelen) {''' | ||
b = build_header(tokens) | ||
for size in sorted(b.keys()): | ||
ents = b[size] | ||
print '''\ | ||
case {}:'''.format(size) | ||
print '''\ | ||
switch (name[{}]) {{'''.format(size - 1) | ||
for c in sorted(ents.keys()): | ||
headers = sorted(ents[c]) | ||
print '''\ | ||
case '{}':'''.format(c) | ||
for k in headers: | ||
print '''\ | ||
if (util::streq_l("{}", name, {})) {{ | ||
return {}; | ||
}}'''.format(k[:-1], size - 1, to_enum_hd(k, prefix)) | ||
print '''\ | ||
break;''' | ||
print '''\ | ||
} | ||
break;''' | ||
print '''\ | ||
} | ||
return -1; | ||
}''' | ||
|
||
def gentokenlookup(tokens, prefix): | ||
gen_enum(tokens, prefix) | ||
print '' | ||
gen_index_header(tokens, prefix) |
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.