From bcd033699c5a4904967652de4980e4f35f17ee34 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 3 Sep 2015 17:15:21 +0200 Subject: [PATCH 14/16] BUG/MINOR: http: remove stupid HTTP_METH_NONE entry When converting the "method" fetch to a string, we used to get an empty string if the first character was not an upper case. This was caused by the lookup function which returns HTTP_METH_NONE when a lookup is not possible, and this method being mapped to an empty string in the array. This is a totally stupid mechanism, there's no reason for having the result depend on the first char. In fact the message parser already checks that the syntax matches an HTTP token so we can only land there with a valid token, hence only HTTP_METH_OTHER should be returned. This fix should be backported to all actively supported branches. (cherry picked from commit b7ce424be2bc9df73a3b971fa9dd6daea0332bf1) --- include/types/proto_http.h | 1 - src/proto_http.c | 11 ++++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/types/proto_http.h b/include/types/proto_http.h index a5a5d31..dbce972 100644 --- a/include/types/proto_http.h +++ b/include/types/proto_http.h @@ -219,7 +219,6 @@ enum { /* Known HTTP methods */ enum http_meth_t { - HTTP_METH_NONE = 0, HTTP_METH_OPTIONS, HTTP_METH_GET, HTTP_METH_HEAD, diff --git a/src/proto_http.c b/src/proto_http.c index 02dc42b..46694cb 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -361,12 +361,11 @@ const struct http_method_desc http_methods[26][3] = { [0] = { .meth = HTTP_METH_TRACE , .len=5, .text="TRACE" }, }, /* rest is empty like this : - * [1] = { .meth = HTTP_METH_NONE , .len=0, .text="" }, + * [0] = { .meth = HTTP_METH_OTHER , .len=0, .text="" }, */ }; const struct http_method_name http_known_methods[HTTP_METH_OTHER] = { - [HTTP_METH_NONE] = { "", 0 }, [HTTP_METH_OPTIONS] = { "OPTIONS", 7 }, [HTTP_METH_GET] = { "GET", 3 }, [HTTP_METH_HEAD] = { "HEAD", 4 }, @@ -793,8 +792,8 @@ struct chunk *http_error_message(struct session *s, int msgnum) } /* - * returns HTTP_METH_NONE if there is nothing valid to read (empty or non-text - * string), HTTP_METH_OTHER for unknown methods, or the identified method. + * returns a known method among HTTP_METH_* or HTTP_METH_OTHER for all unknown + * ones. */ enum http_meth_t find_http_meth(const char *str, const int len) { @@ -810,10 +809,8 @@ enum http_meth_t find_http_meth(const char *str, const int len) if (likely(memcmp(str, h->text, h->len) == 0)) return h->meth; }; - return HTTP_METH_OTHER; } - return HTTP_METH_NONE; - + return HTTP_METH_OTHER; } /* Parse the URI from the given transaction (which is assumed to be in request -- 2.4.6