05ce28f
From 335850f6b868d3411968cbf5a4d59fe619dee36f Mon Sep 17 00:00:00 2001
05ce28f
From: Nathaniel McCallum <npmccallum@redhat.com>
05ce28f
Date: Thu, 6 Oct 2016 02:03:36 -0400
05ce28f
Subject: [PATCH] parser: HTTP_STATUS_MAP(XX) and enum http_status
05ce28f
05ce28f
This patch provides an enum for the standardized HTTP status codes.
05ce28f
Additionally, the HTTP_STATUS_MAP(XX) can be used for other purposes as
05ce28f
well, such as code-to-name lookups and code-based switch statements.
05ce28f
05ce28f
PR-URL: https://github.com/nodejs/http-parser/pull/337
05ce28f
Reviewed-By: Fedor Indutny <fedor@indutny.com>
05ce28f
Reviewed-By: Brian White <mscdex@mscdex.net>
05ce28f
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
05ce28f
---
05ce28f
 http_parser.h | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
05ce28f
 1 file changed, 70 insertions(+)
05ce28f
05ce28f
diff --git a/http_parser.h b/http_parser.h
05ce28f
index ea26394..45c72a0 100644
05ce28f
--- a/http_parser.h
05ce28f
+++ b/http_parser.h
05ce28f
@@ -90,6 +90,76 @@ typedef int (*http_data_cb) (http_parser*, const char *at, size_t length);
05ce28f
 typedef int (*http_cb) (http_parser*);
05ce28f
 
05ce28f
 
05ce28f
+/* Status Codes */
05ce28f
+#define HTTP_STATUS_MAP(XX)                                                 \
05ce28f
+  XX(100, CONTINUE,                        Continue)                        \
05ce28f
+  XX(101, SWITCHING_PROTOCOLS,             Switching Protocols)             \
05ce28f
+  XX(102, PROCESSING,                      Processing)                      \
05ce28f
+  XX(200, OK,                              OK)                              \
05ce28f
+  XX(201, CREATED,                         Created)                         \
05ce28f
+  XX(202, ACCEPTED,                        Accepted)                        \
05ce28f
+  XX(203, NON_AUTHORITATIVE_INFORMATION,   Non-Authoritative Information)   \
05ce28f
+  XX(204, NO_CONTENT,                      No Content)                      \
05ce28f
+  XX(205, RESET_CONTENT,                   Reset Content)                   \
05ce28f
+  XX(206, PARTIAL_CONTENT,                 Partial Content)                 \
05ce28f
+  XX(207, MULTI_STATUS,                    Multi-Status)                    \
05ce28f
+  XX(208, ALREADY_REPORTED,                Already Reported)                \
05ce28f
+  XX(226, IM_USED,                         IM Used)                         \
05ce28f
+  XX(300, MULTIPLE_CHOICES,                Multiple Choices)                \
05ce28f
+  XX(301, MOVED_PERMANENTLY,               Moved Permanently)               \
05ce28f
+  XX(302, FOUND,                           Found)                           \
05ce28f
+  XX(303, SEE_OTHER,                       See Other)                       \
05ce28f
+  XX(304, NOT_MODIFIED,                    Not Modified)                    \
05ce28f
+  XX(305, USE_PROXY,                       Use Proxy)                       \
05ce28f
+  XX(307, TEMPORARY_REDIRECT,              Temporary Redirect)              \
05ce28f
+  XX(308, PERMANENT_REDIRECT,              Permanent Redirect)              \
05ce28f
+  XX(400, BAD_REQUEST,                     Bad Request)                     \
05ce28f
+  XX(401, UNAUTHORIZED,                    Unauthorized)                    \
05ce28f
+  XX(402, PAYMENT_REQUIRED,                Payment Required)                \
05ce28f
+  XX(403, FORBIDDEN,                       Forbidden)                       \
05ce28f
+  XX(404, NOT_FOUND,                       Not Found)                       \
05ce28f
+  XX(405, METHOD_NOT_ALLOWED,              Method Not Allowed)              \
05ce28f
+  XX(406, NOT_ACCEPTABLE,                  Not Acceptable)                  \
05ce28f
+  XX(407, PROXY_AUTHENTICATION_REQUIRED,   Proxy Authentication Required)   \
05ce28f
+  XX(408, REQUEST_TIMEOUT,                 Request Timeout)                 \
05ce28f
+  XX(409, CONFLICT,                        Conflict)                        \
05ce28f
+  XX(410, GONE,                            Gone)                            \
05ce28f
+  XX(411, LENGTH_REQUIRED,                 Length Required)                 \
05ce28f
+  XX(412, PRECONDITION_FAILED,             Precondition Failed)             \
05ce28f
+  XX(413, PAYLOAD_TOO_LARGE,               Payload Too Large)               \
05ce28f
+  XX(414, URI_TOO_LONG,                    URI Too Long)                    \
05ce28f
+  XX(415, UNSUPPORTED_MEDIA_TYPE,          Unsupported Media Type)          \
05ce28f
+  XX(416, RANGE_NOT_SATISFIABLE,           Range Not Satisfiable)           \
05ce28f
+  XX(417, EXPECTATION_FAILED,              Expectation Failed)              \
05ce28f
+  XX(421, MISDIRECTED_REQUEST,             Misdirected Request)             \
05ce28f
+  XX(422, UNPROCESSABLE_ENTITY,            Unprocessable Entity)            \
05ce28f
+  XX(423, LOCKED,                          Locked)                          \
05ce28f
+  XX(424, FAILED_DEPENDENCY,               Failed Dependency)               \
05ce28f
+  XX(426, UPGRADE_REQUIRED,                Upgrade Required)                \
05ce28f
+  XX(428, PRECONDITION_REQUIRED,           Precondition Required)           \
05ce28f
+  XX(429, TOO_MANY_REQUESTS,               Too Many Requests)               \
05ce28f
+  XX(431, REQUEST_HEADER_FIELDS_TOO_LARGE, Request Header Fields Too Large) \
05ce28f
+  XX(451, UNAVAILABLE_FOR_LEGAL_REASONS,   Unavailable For Legal Reasons)   \
05ce28f
+  XX(500, INTERNAL_SERVER_ERROR,           Internal Server Error)           \
05ce28f
+  XX(501, NOT_IMPLEMENTED,                 Not Implemented)                 \
05ce28f
+  XX(502, BAD_GATEWAY,                     Bad Gateway)                     \
05ce28f
+  XX(503, SERVICE_UNAVAILABLE,             Service Unavailable)             \
05ce28f
+  XX(504, GATEWAY_TIMEOUT,                 Gateway Timeout)                 \
05ce28f
+  XX(505, HTTP_VERSION_NOT_SUPPORTED,      HTTP Version Not Supported)      \
05ce28f
+  XX(506, VARIANT_ALSO_NEGOTIATES,         Variant Also Negotiates)         \
05ce28f
+  XX(507, INSUFFICIENT_STORAGE,            Insufficient Storage)            \
05ce28f
+  XX(508, LOOP_DETECTED,                   Loop Detected)                   \
05ce28f
+  XX(510, NOT_EXTENDED,                    Not Extended)                    \
05ce28f
+  XX(511, NETWORK_AUTHENTICATION_REQUIRED, Network Authentication Required) \
05ce28f
+
05ce28f
+enum http_status
05ce28f
+  {
05ce28f
+#define XX(num, name, string) HTTP_STATUS_##name = num,
05ce28f
+  HTTP_STATUS_MAP(XX)
05ce28f
+#undef XX
05ce28f
+  };
05ce28f
+
05ce28f
+
05ce28f
 /* Request Methods */
05ce28f
 #define HTTP_METHOD_MAP(XX)         \
05ce28f
   XX(0,  DELETE,      DELETE)       \