cherry-pick.v2.7.1-1-g335850f.parser-http-status-map-xx-and-enum-http-status.patch 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. Subject: Parser: HTTP_STATUS_MAP(XX) and enum http_status
  2. Origin: v2.7.1-1-g335850f
  3. Upstream-Author: Nathaniel McCallum <npmccallum@redhat.com>
  4. Date: Thu Oct 6 02:03:36 2016 -0400
  5. This patch provides an enum for the standardized HTTP status codes.
  6. Additionally, the HTTP_STATUS_MAP(XX) can be used for other purposes as
  7. well, such as code-to-name lookups and code-based switch statements.
  8. PR-URL: https://github.com/nodejs/http-parser/pull/337
  9. Reviewed-By: Fedor Indutny <fedor@indutny.com>
  10. Reviewed-By: Brian White <mscdex@mscdex.net>
  11. Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  12. --- a/http_parser.h
  13. +++ b/http_parser.h
  14. @@ -90,6 +90,76 @@
  15. typedef int (*http_cb) (http_parser*);
  16. +/* Status Codes */
  17. +#define HTTP_STATUS_MAP(XX) \
  18. + XX(100, CONTINUE, Continue) \
  19. + XX(101, SWITCHING_PROTOCOLS, Switching Protocols) \
  20. + XX(102, PROCESSING, Processing) \
  21. + XX(200, OK, OK) \
  22. + XX(201, CREATED, Created) \
  23. + XX(202, ACCEPTED, Accepted) \
  24. + XX(203, NON_AUTHORITATIVE_INFORMATION, Non-Authoritative Information) \
  25. + XX(204, NO_CONTENT, No Content) \
  26. + XX(205, RESET_CONTENT, Reset Content) \
  27. + XX(206, PARTIAL_CONTENT, Partial Content) \
  28. + XX(207, MULTI_STATUS, Multi-Status) \
  29. + XX(208, ALREADY_REPORTED, Already Reported) \
  30. + XX(226, IM_USED, IM Used) \
  31. + XX(300, MULTIPLE_CHOICES, Multiple Choices) \
  32. + XX(301, MOVED_PERMANENTLY, Moved Permanently) \
  33. + XX(302, FOUND, Found) \
  34. + XX(303, SEE_OTHER, See Other) \
  35. + XX(304, NOT_MODIFIED, Not Modified) \
  36. + XX(305, USE_PROXY, Use Proxy) \
  37. + XX(307, TEMPORARY_REDIRECT, Temporary Redirect) \
  38. + XX(308, PERMANENT_REDIRECT, Permanent Redirect) \
  39. + XX(400, BAD_REQUEST, Bad Request) \
  40. + XX(401, UNAUTHORIZED, Unauthorized) \
  41. + XX(402, PAYMENT_REQUIRED, Payment Required) \
  42. + XX(403, FORBIDDEN, Forbidden) \
  43. + XX(404, NOT_FOUND, Not Found) \
  44. + XX(405, METHOD_NOT_ALLOWED, Method Not Allowed) \
  45. + XX(406, NOT_ACCEPTABLE, Not Acceptable) \
  46. + XX(407, PROXY_AUTHENTICATION_REQUIRED, Proxy Authentication Required) \
  47. + XX(408, REQUEST_TIMEOUT, Request Timeout) \
  48. + XX(409, CONFLICT, Conflict) \
  49. + XX(410, GONE, Gone) \
  50. + XX(411, LENGTH_REQUIRED, Length Required) \
  51. + XX(412, PRECONDITION_FAILED, Precondition Failed) \
  52. + XX(413, PAYLOAD_TOO_LARGE, Payload Too Large) \
  53. + XX(414, URI_TOO_LONG, URI Too Long) \
  54. + XX(415, UNSUPPORTED_MEDIA_TYPE, Unsupported Media Type) \
  55. + XX(416, RANGE_NOT_SATISFIABLE, Range Not Satisfiable) \
  56. + XX(417, EXPECTATION_FAILED, Expectation Failed) \
  57. + XX(421, MISDIRECTED_REQUEST, Misdirected Request) \
  58. + XX(422, UNPROCESSABLE_ENTITY, Unprocessable Entity) \
  59. + XX(423, LOCKED, Locked) \
  60. + XX(424, FAILED_DEPENDENCY, Failed Dependency) \
  61. + XX(426, UPGRADE_REQUIRED, Upgrade Required) \
  62. + XX(428, PRECONDITION_REQUIRED, Precondition Required) \
  63. + XX(429, TOO_MANY_REQUESTS, Too Many Requests) \
  64. + XX(431, REQUEST_HEADER_FIELDS_TOO_LARGE, Request Header Fields Too Large) \
  65. + XX(451, UNAVAILABLE_FOR_LEGAL_REASONS, Unavailable For Legal Reasons) \
  66. + XX(500, INTERNAL_SERVER_ERROR, Internal Server Error) \
  67. + XX(501, NOT_IMPLEMENTED, Not Implemented) \
  68. + XX(502, BAD_GATEWAY, Bad Gateway) \
  69. + XX(503, SERVICE_UNAVAILABLE, Service Unavailable) \
  70. + XX(504, GATEWAY_TIMEOUT, Gateway Timeout) \
  71. + XX(505, HTTP_VERSION_NOT_SUPPORTED, HTTP Version Not Supported) \
  72. + XX(506, VARIANT_ALSO_NEGOTIATES, Variant Also Negotiates) \
  73. + XX(507, INSUFFICIENT_STORAGE, Insufficient Storage) \
  74. + XX(508, LOOP_DETECTED, Loop Detected) \
  75. + XX(510, NOT_EXTENDED, Not Extended) \
  76. + XX(511, NETWORK_AUTHENTICATION_REQUIRED, Network Authentication Required) \
  77. +
  78. +enum http_status
  79. + {
  80. +#define XX(num, name, string) HTTP_STATUS_##name = num,
  81. + HTTP_STATUS_MAP(XX)
  82. +#undef XX
  83. + };
  84. +
  85. +
  86. /* Request Methods */
  87. #define HTTP_METHOD_MAP(XX) \
  88. XX(0, DELETE, DELETE) \