CLEANUP: http: avoid duplicating literals in find_http_meth()

The function does the inverse of http_known_methods[], better rely on
that array with its indices, that makes the code clearer. Note that
we purposely don't use a loop because the compiler is able to build
an evaluation tree of the size checks and content checks that's very
efficient for the most common methods. Moving a few unimportant
entries even simplified the output code a little bit (they're now
groupped by size without changing anything for the first ones).
This commit is contained in:
Willy Tarreau 2024-01-10 11:28:28 +01:00
parent 19def65228
commit 59c01f1091
1 changed files with 9 additions and 9 deletions

View File

@ -352,15 +352,15 @@ enum http_meth_t find_http_meth(const char *str, const int len)
{
const struct ist m = ist2(str, len);
if (isteq(m, ist("GET"))) return HTTP_METH_GET;
else if (isteq(m, ist("HEAD"))) return HTTP_METH_HEAD;
else if (isteq(m, ist("POST"))) return HTTP_METH_POST;
else if (isteq(m, ist("CONNECT"))) return HTTP_METH_CONNECT;
else if (isteq(m, ist("PUT"))) return HTTP_METH_PUT;
else if (isteq(m, ist("OPTIONS"))) return HTTP_METH_OPTIONS;
else if (isteq(m, ist("DELETE"))) return HTTP_METH_DELETE;
else if (isteq(m, ist("TRACE"))) return HTTP_METH_TRACE;
else return HTTP_METH_OTHER;
if (isteq(m, http_known_methods[HTTP_METH_GET])) return HTTP_METH_GET;
else if (isteq(m, http_known_methods[HTTP_METH_PUT])) return HTTP_METH_PUT;
else if (isteq(m, http_known_methods[HTTP_METH_HEAD])) return HTTP_METH_HEAD;
else if (isteq(m, http_known_methods[HTTP_METH_POST])) return HTTP_METH_POST;
else if (isteq(m, http_known_methods[HTTP_METH_TRACE])) return HTTP_METH_TRACE;
else if (isteq(m, http_known_methods[HTTP_METH_DELETE])) return HTTP_METH_DELETE;
else if (isteq(m, http_known_methods[HTTP_METH_CONNECT])) return HTTP_METH_CONNECT;
else if (isteq(m, http_known_methods[HTTP_METH_OPTIONS])) return HTTP_METH_OPTIONS;
else return HTTP_METH_OTHER;
}
/* This function returns HTTP_ERR_<num> (enum) matching http status code.