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.
This commit is contained in:
Willy Tarreau 2015-09-03 17:15:21 +02:00
parent 42148735bc
commit b7ce424be2
2 changed files with 4 additions and 8 deletions

View File

@ -212,7 +212,6 @@ struct stream;
/* Known HTTP methods */ /* Known HTTP methods */
enum http_meth_t { enum http_meth_t {
HTTP_METH_NONE = 0,
HTTP_METH_OPTIONS, HTTP_METH_OPTIONS,
HTTP_METH_GET, HTTP_METH_GET,
HTTP_METH_HEAD, HTTP_METH_HEAD,

View File

@ -466,12 +466,11 @@ const struct http_method_desc http_methods[26][3] = {
[0] = { .meth = HTTP_METH_TRACE , .len=5, .text="TRACE" }, [0] = { .meth = HTTP_METH_TRACE , .len=5, .text="TRACE" },
}, },
/* rest is empty like this : /* 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] = { const struct http_method_name http_known_methods[HTTP_METH_OTHER] = {
[HTTP_METH_NONE] = { "", 0 },
[HTTP_METH_OPTIONS] = { "OPTIONS", 7 }, [HTTP_METH_OPTIONS] = { "OPTIONS", 7 },
[HTTP_METH_GET] = { "GET", 3 }, [HTTP_METH_GET] = { "GET", 3 },
[HTTP_METH_HEAD] = { "HEAD", 4 }, [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 * returns a known method among HTTP_METH_* or HTTP_METH_OTHER for all unknown
* string), HTTP_METH_OTHER for unknown methods, or the identified method. * ones.
*/ */
enum http_meth_t find_http_meth(const char *str, const int len) 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)) if (likely(memcmp(str, h->text, h->len) == 0))
return h->meth; 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 /* Parse the URI from the given transaction (which is assumed to be in request