You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.8 KiB

  1. From bcd033699c5a4904967652de4980e4f35f17ee34 Mon Sep 17 00:00:00 2001
  2. From: Willy Tarreau <w@1wt.eu>
  3. Date: Thu, 3 Sep 2015 17:15:21 +0200
  4. Subject: [PATCH 14/16] BUG/MINOR: http: remove stupid HTTP_METH_NONE entry
  5. When converting the "method" fetch to a string, we used to get an empty
  6. string if the first character was not an upper case. This was caused by
  7. the lookup function which returns HTTP_METH_NONE when a lookup is not
  8. possible, and this method being mapped to an empty string in the array.
  9. This is a totally stupid mechanism, there's no reason for having the
  10. result depend on the first char. In fact the message parser already
  11. checks that the syntax matches an HTTP token so we can only land there
  12. with a valid token, hence only HTTP_METH_OTHER should be returned.
  13. This fix should be backported to all actively supported branches.
  14. (cherry picked from commit b7ce424be2bc9df73a3b971fa9dd6daea0332bf1)
  15. ---
  16. include/types/proto_http.h | 1 -
  17. src/proto_http.c | 11 ++++-------
  18. 2 files changed, 4 insertions(+), 8 deletions(-)
  19. diff --git a/include/types/proto_http.h b/include/types/proto_http.h
  20. index a5a5d31..dbce972 100644
  21. --- a/include/types/proto_http.h
  22. +++ b/include/types/proto_http.h
  23. @@ -219,7 +219,6 @@ enum {
  24. /* Known HTTP methods */
  25. enum http_meth_t {
  26. - HTTP_METH_NONE = 0,
  27. HTTP_METH_OPTIONS,
  28. HTTP_METH_GET,
  29. HTTP_METH_HEAD,
  30. diff --git a/src/proto_http.c b/src/proto_http.c
  31. index 02dc42b..46694cb 100644
  32. --- a/src/proto_http.c
  33. +++ b/src/proto_http.c
  34. @@ -361,12 +361,11 @@ const struct http_method_desc http_methods[26][3] = {
  35. [0] = { .meth = HTTP_METH_TRACE , .len=5, .text="TRACE" },
  36. },
  37. /* rest is empty like this :
  38. - * [1] = { .meth = HTTP_METH_NONE , .len=0, .text="" },
  39. + * [0] = { .meth = HTTP_METH_OTHER , .len=0, .text="" },
  40. */
  41. };
  42. const struct http_method_name http_known_methods[HTTP_METH_OTHER] = {
  43. - [HTTP_METH_NONE] = { "", 0 },
  44. [HTTP_METH_OPTIONS] = { "OPTIONS", 7 },
  45. [HTTP_METH_GET] = { "GET", 3 },
  46. [HTTP_METH_HEAD] = { "HEAD", 4 },
  47. @@ -793,8 +792,8 @@ struct chunk *http_error_message(struct session *s, int msgnum)
  48. }
  49. /*
  50. - * returns HTTP_METH_NONE if there is nothing valid to read (empty or non-text
  51. - * string), HTTP_METH_OTHER for unknown methods, or the identified method.
  52. + * returns a known method among HTTP_METH_* or HTTP_METH_OTHER for all unknown
  53. + * ones.
  54. */
  55. enum http_meth_t find_http_meth(const char *str, const int len)
  56. {
  57. @@ -810,10 +809,8 @@ enum http_meth_t find_http_meth(const char *str, const int len)
  58. if (likely(memcmp(str, h->text, h->len) == 0))
  59. return h->meth;
  60. };
  61. - return HTTP_METH_OTHER;
  62. }
  63. - return HTTP_METH_NONE;
  64. -
  65. + return HTTP_METH_OTHER;
  66. }
  67. /* Parse the URI from the given transaction (which is assumed to be in request
  68. --
  69. 2.4.6