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: https://github.com/nodejs/http-parser/pull/323
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
make-http-max-header-size-gyp-configurable
Pierce Lopez 9 years ago committed by Fedor Indutny
parent 0852bea482
commit 1b79abab34

@ -973,7 +973,7 @@ reexecute:
UPDATE_STATE(s_req_spaces_before_url); UPDATE_STATE(s_req_spaces_before_url);
} else if (ch == matcher[parser->index]) { } else if (ch == matcher[parser->index]) {
; /* nada */ ; /* nada */
} else if (IS_ALPHA(ch)) { } else if ((ch >= 'A' && ch <= 'Z') || ch == '-') {
switch (parser->method << 16 | parser->index << 8 | ch) { switch (parser->method << 16 | parser->index << 8 | ch) {
#define XX(meth, pos, ch, new_meth) \ #define XX(meth, pos, ch, new_meth) \
@ -982,31 +982,27 @@ reexecute:
XX(POST, 1, 'U', PUT) XX(POST, 1, 'U', PUT)
XX(POST, 1, 'A', PATCH) XX(POST, 1, 'A', PATCH)
XX(POST, 1, 'R', PROPFIND)
XX(PUT, 2, 'R', PURGE)
XX(CONNECT, 1, 'H', CHECKOUT) XX(CONNECT, 1, 'H', CHECKOUT)
XX(CONNECT, 2, 'P', COPY) XX(CONNECT, 2, 'P', COPY)
XX(MKCOL, 1, 'O', MOVE) XX(MKCOL, 1, 'O', MOVE)
XX(MKCOL, 1, 'E', MERGE) XX(MKCOL, 1, 'E', MERGE)
XX(MKCOL, 1, '-', MSEARCH)
XX(MKCOL, 2, 'A', MKACTIVITY) XX(MKCOL, 2, 'A', MKACTIVITY)
XX(MKCOL, 3, 'A', MKCALENDAR) XX(MKCOL, 3, 'A', MKCALENDAR)
XX(SUBSCRIBE, 1, 'E', SEARCH) XX(SUBSCRIBE, 1, 'E', SEARCH)
XX(REPORT, 2, 'B', REBIND) XX(REPORT, 2, 'B', REBIND)
XX(POST, 1, 'R', PROPFIND)
XX(PROPFIND, 4, 'P', PROPPATCH) XX(PROPFIND, 4, 'P', PROPPATCH)
XX(PUT, 2, 'R', PURGE)
XX(LOCK, 1, 'I', LINK) XX(LOCK, 1, 'I', LINK)
XX(UNLOCK, 2, 'S', UNSUBSCRIBE) XX(UNLOCK, 2, 'S', UNSUBSCRIBE)
XX(UNLOCK, 2, 'B', UNBIND) XX(UNLOCK, 2, 'B', UNBIND)
XX(UNLOCK, 3, 'I', UNLINK) XX(UNLOCK, 3, 'I', UNLINK)
#undef XX #undef XX
default: default:
SET_ERRNO(HPE_INVALID_METHOD); SET_ERRNO(HPE_INVALID_METHOD);
goto error; goto error;
} }
} else if (ch == '-' &&
parser->index == 1 &&
parser->method == HTTP_MKCOL) {
parser->method = HTTP_MSEARCH;
} else { } else {
SET_ERRNO(HPE_INVALID_METHOD); SET_ERRNO(HPE_INVALID_METHOD);
goto error; goto error;

Loading…
Cancel
Save