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

Commit

Permalink
simplify parsing M-SEARCH method, group P methods
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
ploxiln authored and indutny committed Jun 14, 2017
1 parent 0852bea commit 1b79aba
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions http_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ size_t http_parser_execute (http_parser *parser,
UPDATE_STATE(s_req_spaces_before_url);
} else if (ch == matcher[parser->index]) {
; /* nada */
} else if (IS_ALPHA(ch)) {
} else if ((ch >= 'A' && ch <= 'Z') || ch == '-') {

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

XX(POST, 1, 'U', PUT)
XX(POST, 1, 'A', PATCH)
XX(POST, 1, 'R', PROPFIND)
XX(PUT, 2, 'R', PURGE)
XX(CONNECT, 1, 'H', CHECKOUT)
XX(CONNECT, 2, 'P', COPY)
XX(MKCOL, 1, 'O', MOVE)
XX(MKCOL, 1, 'E', MERGE)
XX(MKCOL, 1, '-', MSEARCH)
XX(MKCOL, 2, 'A', MKACTIVITY)
XX(MKCOL, 3, 'A', MKCALENDAR)
XX(SUBSCRIBE, 1, 'E', SEARCH)
XX(REPORT, 2, 'B', REBIND)
XX(POST, 1, 'R', PROPFIND)
XX(PROPFIND, 4, 'P', PROPPATCH)
XX(PUT, 2, 'R', PURGE)
XX(LOCK, 1, 'I', LINK)
XX(UNLOCK, 2, 'S', UNSUBSCRIBE)
XX(UNLOCK, 2, 'B', UNBIND)
XX(UNLOCK, 3, 'I', UNLINK)
#undef XX

default:
SET_ERRNO(HPE_INVALID_METHOD);
goto error;
}
} else if (ch == '-' &&
parser->index == 1 &&
parser->method == HTTP_MKCOL) {
parser->method = HTTP_MSEARCH;
} else {
SET_ERRNO(HPE_INVALID_METHOD);
goto error;
Expand Down

0 comments on commit 1b79aba

Please sign in to comment.