summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-10 13:18:49 +0000
committertyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-10 13:18:49 +0000
commit6d19b3c794ae1aec96b81e100545669b3bf738eb (patch)
tree9c1aeddc31db89172063047074be96a406d8d167
parent5c2f1afed3ed0c311ad9988b958f11bdbaca09dc (diff)
downloadchromium_src-6d19b3c794ae1aec96b81e100545669b3bf738eb.zip
chromium_src-6d19b3c794ae1aec96b81e100545669b3bf738eb.tar.gz
chromium_src-6d19b3c794ae1aec96b81e100545669b3bf738eb.tar.bz2
Generate constants for HTTP status codes and reason phrases using macro.
Review URL: https://chromiumcodereview.appspot.com/16622002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@205202 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--net/http/http_status_code.cc21
-rw-r--r--net/http/http_status_code.h58
-rw-r--r--net/http/http_status_code_list.h66
-rw-r--r--net/http/http_status_code_unittest.cc20
-rw-r--r--net/net.gyp1
5 files changed, 98 insertions, 68 deletions
diff --git a/net/http/http_status_code.cc b/net/http/http_status_code.cc
index 462202b..80d0265e 100644
--- a/net/http/http_status_code.cc
+++ b/net/http/http_status_code.cc
@@ -10,22 +10,11 @@ namespace net {
const char* GetHttpReasonPhrase(HttpStatusCode code) {
switch (code) {
- case HTTP_CONTINUE:
- return "Continue";
- case HTTP_OK:
- return "OK";
- case HTTP_PARTIAL_CONTENT:
- return "Partial Content";
- case HTTP_FORBIDDEN:
- return "Forbidden";
- case HTTP_NOT_FOUND:
- return "Not Found";
- case HTTP_METHOD_NOT_ALLOWED:
- return "Method Not Allowed";
- case HTTP_REQUESTED_RANGE_NOT_SATISFIABLE:
- return "Range Not Satisfiable";
- case HTTP_INTERNAL_SERVER_ERROR:
- return "Internal Server Error";
+
+#define HTTP_STATUS(label, code, reason) case HTTP_ ## label: return reason;
+#include "net/http/http_status_code_list.h"
+#undef HTTP_STATUS
+
default:
NOTREACHED();
}
diff --git a/net/http/http_status_code.h b/net/http/http_status_code.h
index 8780c71..a4b398b 100644
--- a/net/http/http_status_code.h
+++ b/net/http/http_status_code.h
@@ -10,58 +10,12 @@
namespace net {
// HTTP status codes.
-// Taken from RFC 2616 Section 10.
enum HttpStatusCode {
- // Informational 1xx
- HTTP_CONTINUE = 100,
- HTTP_SWITCHING_PROTOCOLS = 101,
- // Successful 2xx
- HTTP_OK = 200,
- HTTP_CREATED = 201,
- HTTP_ACCEPTED = 202,
- HTTP_NON_AUTHORITATIVE_INFORMATION = 203,
- HTTP_NO_CONTENT = 204,
- HTTP_RESET_CONTENT = 205,
- HTTP_PARTIAL_CONTENT = 206,
+#define HTTP_STATUS(label, code, reason) HTTP_ ## label = code,
+#include "net/http/http_status_code_list.h"
+#undef HTTP_STATUS
- // Redirection 3xx
- HTTP_MULTIPLE_CHOICES = 300,
- HTTP_MOVED_PERMANENTLY = 301,
- HTTP_FOUND = 302,
- HTTP_SEE_OTHER = 303,
- HTTP_NOT_MODIFIED = 304,
- HTTP_USE_PROXY = 305,
- // 306 is no longer used.
- HTTP_TEMPORARY_REDIRECT = 307,
-
- // Client error 4xx
- HTTP_BAD_REQUEST = 400,
- HTTP_UNAUTHORIZED = 401,
- HTTP_PAYMENT_REQUIRED = 402,
- HTTP_FORBIDDEN = 403,
- HTTP_NOT_FOUND = 404,
- HTTP_METHOD_NOT_ALLOWED = 405,
- HTTP_NOT_ACCEPTABLE = 406,
- HTTP_PROXY_AUTHENTICATION_REQUIRED = 407,
- HTTP_REQUEST_TIMEOUT = 408,
- HTTP_CONFLICT = 409,
- HTTP_GONE = 410,
- HTTP_LENGTH_REQUIRED = 411,
- HTTP_PRECONDITION_FAILED = 412,
- HTTP_REQUEST_ENTITY_TOO_LARGE = 413,
- HTTP_REQUEST_URI_TOO_LONG = 414,
- HTTP_UNSUPPORTED_MEDIA_TYPE = 415,
- HTTP_REQUESTED_RANGE_NOT_SATISFIABLE = 416,
- HTTP_EXPECTATION_FAILED = 417,
-
- // Server error 5xx
- HTTP_INTERNAL_SERVER_ERROR = 500,
- HTTP_NOT_IMPLEMENTED = 501,
- HTTP_BAD_GATEWAY = 502,
- HTTP_SERVICE_UNAVAILABLE = 503,
- HTTP_GATEWAY_TIMEOUT = 504,
- HTTP_VERSION_NOT_SUPPORTED = 505,
};
// Returns the corresponding HTTP status description to use in the Reason-Phrase
@@ -69,9 +23,9 @@ enum HttpStatusCode {
// Status Code Registry.
// http://www.iana.org/assignments/http-status-codes/http-status-codes.xml
//
-// This function doesn't cover all codes defined above. It returns an empty
-// string (or crash in debug build) for status codes which are not yet covered
-// or just invalid. Please extend it when needed.
+// This function may not cover all codes defined in the IANA registry. It
+// returns an empty string (or crash in debug build) for status codes which are
+// not yet covered or just invalid. Please extend it when needed.
NET_EXPORT const char* GetHttpReasonPhrase(HttpStatusCode code);
} // namespace net
diff --git a/net/http/http_status_code_list.h b/net/http/http_status_code_list.h
new file mode 100644
index 0000000..30c6206
--- /dev/null
+++ b/net/http/http_status_code_list.h
@@ -0,0 +1,66 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file intentionally does not have header guards, it's included
+// inside a macro to generate enum.
+//
+// This file contains the list of HTTP status codes. Taken from IANA HTTP Status
+// Code Registry.
+// http://www.iana.org/assignments/http-status-codes/http-status-codes.xml
+
+#ifndef HTTP_STATUS
+#error "HTTP_STATUS should be defined before including this file"
+#endif
+
+// Informational 1xx
+HTTP_STATUS(CONTINUE, 100, "Continue")
+HTTP_STATUS(SWITCHING_PROTOCOLS, 101, "Switching Protocols")
+
+// Successful 2xx
+HTTP_STATUS(OK, 200, "OK")
+HTTP_STATUS(CREATED, 201, "Created")
+HTTP_STATUS(ACCEPTED, 202, "Accepted")
+HTTP_STATUS(NON_AUTHORITATIVE_INFORMATION, 203, "Non-Authoritative Information")
+HTTP_STATUS(NO_CONTENT, 204, "No Content")
+HTTP_STATUS(RESET_CONTENT, 205, "Reset Content")
+HTTP_STATUS(PARTIAL_CONTENT, 206, "Partial Content")
+
+// Redirection 3xx
+HTTP_STATUS(MULTIPLE_CHOICES, 300, "Multiple Choices")
+HTTP_STATUS(MOVED_PERMANENTLY, 301, "Moved Permanently")
+HTTP_STATUS(FOUND, 302, "Found")
+HTTP_STATUS(SEE_OTHER, 303, "See Other")
+HTTP_STATUS(NOT_MODIFIED, 304, "Not Modified")
+HTTP_STATUS(USE_PROXY, 305, "Use Proxy")
+// 306 is no longer used.
+HTTP_STATUS(TEMPORARY_REDIRECT, 307, "Temporary Redirect")
+
+// Client error 4xx
+HTTP_STATUS(BAD_REQUEST, 400, "Bad Request")
+HTTP_STATUS(UNAUTHORIZED, 401, "Unauthorized")
+HTTP_STATUS(PAYMENT_REQUIRED, 402, "Payment Required")
+HTTP_STATUS(FORBIDDEN, 403, "Forbidden")
+HTTP_STATUS(NOT_FOUND, 404, "Not Found")
+HTTP_STATUS(METHOD_NOT_ALLOWED, 405, "Method Not Allowed")
+HTTP_STATUS(NOT_ACCEPTABLE, 406, "Not Acceptable")
+HTTP_STATUS(PROXY_AUTHENTICATION_REQUIRED, 407, "Proxy Authentication Required")
+HTTP_STATUS(REQUEST_TIMEOUT, 408, "Request Timeout")
+HTTP_STATUS(CONFLICT, 409, "Conflict")
+HTTP_STATUS(GONE, 410, "Gone")
+HTTP_STATUS(LENGTH_REQUIRED, 411, "Length Required")
+HTTP_STATUS(PRECONDITION_FAILED, 412, "Precondition Failed")
+HTTP_STATUS(REQUEST_ENTITY_TOO_LARGE, 413, "Request Entity Too Large")
+HTTP_STATUS(REQUEST_URI_TOO_LONG, 414, "Request-URI Too Long")
+HTTP_STATUS(UNSUPPORTED_MEDIA_TYPE, 415, "Unsupported Media Type")
+HTTP_STATUS(REQUESTED_RANGE_NOT_SATISFIABLE, 416,
+ "Requested Range Not Satisfiable")
+HTTP_STATUS(EXPECTATION_FAILED, 417, "Expectation Failed")
+
+// Server error 5xx
+HTTP_STATUS(INTERNAL_SERVER_ERROR, 500, "Internal Server Error")
+HTTP_STATUS(NOT_IMPLEMENTED, 501, "Not Implemented")
+HTTP_STATUS(BAD_GATEWAY, 502, "Bad Gateway")
+HTTP_STATUS(SERVICE_UNAVAILABLE, 503, "Service Unavailable")
+HTTP_STATUS(GATEWAY_TIMEOUT, 504, "Gateway Timeout")
+HTTP_STATUS(VERSION_NOT_SUPPORTED, 505, "HTTP Version Not Supported")
diff --git a/net/http/http_status_code_unittest.cc b/net/http/http_status_code_unittest.cc
new file mode 100644
index 0000000..962b89d
--- /dev/null
+++ b/net/http/http_status_code_unittest.cc
@@ -0,0 +1,20 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/http/http_status_code.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace net {
+
+namespace {
+
+TEST(HttpStatusCode, OK) {
+ EXPECT_EQ(200, HTTP_OK);
+ EXPECT_STREQ("OK", GetHttpReasonPhrase(HTTP_OK));
+}
+
+} // namespace
+
+} // namespace net
diff --git a/net/net.gyp b/net/net.gyp
index f8c3d30..0265d31 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -1593,6 +1593,7 @@
'http/http_response_headers_unittest.cc',
'http/http_security_headers_unittest.cc',
'http/http_server_properties_impl_unittest.cc',
+ 'http/http_status_code_unittest.cc',
'http/http_stream_factory_impl_unittest.cc',
'http/http_stream_parser_unittest.cc',
'http/http_transaction_unittest.cc',