Skip to content
This repository was archived by the owner on Nov 6, 2022. It is now read-only.

Commit 1b79aba

Browse files
ploxilnindutny
authored andcommitted
simplify parsing M-SEARCH method, group P methods
can use same switch-lookup for '-' char case move PROPFIND and PURGE to be next to the other P methods change IS_ALPHA(ch) to A <= ch <= Z (very slight optimization, only uppercase will match in switch) PR-URL: #323 Reviewed-By: Fedor Indutny <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0852bea commit 1b79aba

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

http_parser.c

+4-8
Original file line numberDiff line numberDiff line change
@@ -973,7 +973,7 @@ size_t http_parser_execute (http_parser *parser,
973973
UPDATE_STATE(s_req_spaces_before_url);
974974
} else if (ch == matcher[parser->index]) {
975975
; /* nada */
976-
} else if (IS_ALPHA(ch)) {
976+
} else if ((ch >= 'A' && ch <= 'Z') || ch == '-') {
977977

978978
switch (parser->method << 16 | parser->index << 8 | ch) {
979979
#define XX(meth, pos, ch, new_meth) \
@@ -982,31 +982,27 @@ size_t http_parser_execute (http_parser *parser,
982982

983983
XX(POST, 1, 'U', PUT)
984984
XX(POST, 1, 'A', PATCH)
985+
XX(POST, 1, 'R', PROPFIND)
986+
XX(PUT, 2, 'R', PURGE)
985987
XX(CONNECT, 1, 'H', CHECKOUT)
986988
XX(CONNECT, 2, 'P', COPY)
987989
XX(MKCOL, 1, 'O', MOVE)
988990
XX(MKCOL, 1, 'E', MERGE)
991+
XX(MKCOL, 1, '-', MSEARCH)
989992
XX(MKCOL, 2, 'A', MKACTIVITY)
990993
XX(MKCOL, 3, 'A', MKCALENDAR)
991994
XX(SUBSCRIBE, 1, 'E', SEARCH)
992995
XX(REPORT, 2, 'B', REBIND)
993-
XX(POST, 1, 'R', PROPFIND)
994996
XX(PROPFIND, 4, 'P', PROPPATCH)
995-
XX(PUT, 2, 'R', PURGE)
996997
XX(LOCK, 1, 'I', LINK)
997998
XX(UNLOCK, 2, 'S', UNSUBSCRIBE)
998999
XX(UNLOCK, 2, 'B', UNBIND)
9991000
XX(UNLOCK, 3, 'I', UNLINK)
10001001
#undef XX
1001-
10021002
default:
10031003
SET_ERRNO(HPE_INVALID_METHOD);
10041004
goto error;
10051005
}
1006-
} else if (ch == '-' &&
1007-
parser->index == 1 &&
1008-
parser->method == HTTP_MKCOL) {
1009-
parser->method = HTTP_MSEARCH;
10101006
} else {
10111007
SET_ERRNO(HPE_INVALID_METHOD);
10121008
goto error;

0 commit comments

Comments
 (0)