1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #include <anna/core/functions.hpp>
11 #include <anna/http/Response.hpp>
16 void http::Response::setStatusCode(const int statusCode)
18 static struct { int statusCode; const char* reasonPhrase; } reasons [] = {
20 101, "Switching Protocols",
24 203, "Non-Authoritative Information",
27 206, "Partial Content",
28 300, "Multiple Choise",
29 301, "Moved Permanently",
34 307, "Temporary Redirect",
37 402, "Payment Required",
40 405, "Method Not Allowed",
41 406, "Not Acceptable",
42 407, "Proxy Authentication Required",
43 408, "Request Time-out",
46 411, "Length Required",
47 412, "Precondition Failed",
48 413, "Request Entity Too Large",
49 414, "Request-URI Too Large",
50 415, "Unsupported Media Type",
51 416, "Requested range not satisfiable",
52 417, "Expectation Failed",
53 500, "Internal Server Error",
54 501, "Not Implemented",
56 503, "Service Unavailable",
57 504, "Gateway Time-out",
58 505, "HTTP Version not supported",
62 if(a_statusCode == statusCode)
65 a_statusCode = statusCode;
67 for(int i = 0; reasons [i].statusCode != 0; i ++) {
68 if(statusCode < reasons [i].statusCode) {
69 a_reasonPhrase.clear();
73 if(statusCode == reasons [i].statusCode) {
74 a_reasonPhrase = reasons [i].reasonPhrase;
80 string http::Response::codeStartLine() const
81 throw(RuntimeException) {
82 string result(getVersion());
84 result += functions::asString(a_statusCode);
86 return result += a_reasonPhrase;
89 string http::Response::asString() const
91 string result("http::Response { Version: ");
92 result += getVersion();
93 result += " | StatusCode: ";
94 result += functions::asString(a_statusCode);
95 result += " | ReasonPhrase: ";
96 result += (a_reasonPhrase.empty()) ? "<null>" : a_reasonPhrase.c_str();
97 return result += " }";