summaryrefslogtreecommitdiffstats
path: root/net/http
diff options
context:
space:
mode:
authortyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-07 12:51:38 +0000
committertyoshino@chromium.org <tyoshino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-06-07 12:51:38 +0000
commitff51404a38c4ff7e9ff98135facfd2701e3e9f09 (patch)
tree6364f224182701ffb0ef85d6f4cfa83340a1cf47 /net/http
parenta765cc1a419696309423c3e6389bc6572530d617 (diff)
downloadchromium_src-ff51404a38c4ff7e9ff98135facfd2701e3e9f09.zip
chromium_src-ff51404a38c4ff7e9ff98135facfd2701e3e9f09.tar.gz
chromium_src-ff51404a38c4ff7e9ff98135facfd2701e3e9f09.tar.bz2
Factor out HTTP status code and reason phrase in Blob and Stream infrastructure into net/.
TEST= out/Debug/content_unittests --gtest_filter='*Stream*' out/Debug/content_unittests --gtest_filter='*Blob*' out/Debug/net_unittests Review URL: https://chromiumcodereview.appspot.com/16120005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204797 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/http')
-rw-r--r--net/http/http_status_code.cc36
-rw-r--r--net/http/http_status_code.h12
2 files changed, 48 insertions, 0 deletions
diff --git a/net/http/http_status_code.cc b/net/http/http_status_code.cc
new file mode 100644
index 0000000..462202b
--- /dev/null
+++ b/net/http/http_status_code.cc
@@ -0,0 +1,36 @@
+// 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 "base/logging.h"
+
+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";
+ default:
+ NOTREACHED();
+ }
+
+ return "";
+}
+
+} // namespace net
diff --git a/net/http/http_status_code.h b/net/http/http_status_code.h
index 0ae47d6..8780c71 100644
--- a/net/http/http_status_code.h
+++ b/net/http/http_status_code.h
@@ -5,6 +5,8 @@
#ifndef NET_HTTP_HTTP_STATUS_CODE_H_
#define NET_HTTP_HTTP_STATUS_CODE_H_
+#include "net/base/net_export.h"
+
namespace net {
// HTTP status codes.
@@ -62,6 +64,16 @@ enum HttpStatusCode {
HTTP_VERSION_NOT_SUPPORTED = 505,
};
+// Returns the corresponding HTTP status description to use in the Reason-Phrase
+// field in an HTTP response for given |code|. It's based on the IANA HTTP
+// 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.
+NET_EXPORT const char* GetHttpReasonPhrase(HttpStatusCode code);
+
} // namespace net
#endif // NET_HTTP_HTTP_STATUS_CODE_H_