From: Willy Tarreau Date: Thu, 3 Sep 2015 15:15:21 +0000 (+0200) Subject: BUG/MINOR: http: remove stupid HTTP_METH_NONE entry X-Git-Tag: v1.6-dev5~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b7ce424be2bc9df73a3b971fa9dd6daea0332bf1;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/include/types/sample.h b/include/types/sample.h index 1ec9eedf26..83b7a9b6b6 100644 --- a/include/types/sample.h +++ b/include/types/sample.h @@ -212,7 +212,6 @@ struct stream; /* 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 bb1ef698a3..eb3582bd77 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -466,12 +466,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 }, @@ -962,8 +961,8 @@ struct chunk *http_error_message(struct stream *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) { @@ -979,10 +978,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