1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #include <anna/core/functions.hpp>
39 #include <anna/http/Response.hpp>
44 void http::Response::setStatusCode(const int statusCode)
46 static struct { int statusCode; const char* reasonPhrase; } reasons [] = {
48 101, "Switching Protocols",
52 203, "Non-Authoritative Information",
55 206, "Partial Content",
56 300, "Multiple Choise",
57 301, "Moved Permanently",
62 307, "Temporary Redirect",
65 402, "Payment Required",
68 405, "Method Not Allowed",
69 406, "Not Acceptable",
70 407, "Proxy Authentication Required",
71 408, "Request Time-out",
74 411, "Length Required",
75 412, "Precondition Failed",
76 413, "Request Entity Too Large",
77 414, "Request-URI Too Large",
78 415, "Unsupported Media Type",
79 416, "Requested range not satisfiable",
80 417, "Expectation Failed",
81 500, "Internal Server Error",
82 501, "Not Implemented",
84 503, "Service Unavailable",
85 504, "Gateway Time-out",
86 505, "HTTP Version not supported",
90 if(a_statusCode == statusCode)
93 a_statusCode = statusCode;
95 for(int i = 0; reasons [i].statusCode != 0; i ++) {
96 if(statusCode < reasons [i].statusCode) {
97 a_reasonPhrase.clear();
101 if(statusCode == reasons [i].statusCode) {
102 a_reasonPhrase = reasons [i].reasonPhrase;
108 string http::Response::codeStartLine() const
109 throw(RuntimeException) {
110 string result(getVersion());
112 result += functions::asString(a_statusCode);
114 return result += a_reasonPhrase;
117 string http::Response::asString() const
119 string result("http::Response { Version: ");
120 result += getVersion();
121 result += " | StatusCode: ";
122 result += functions::asString(a_statusCode);
123 result += " | ReasonPhrase: ";
124 result += (a_reasonPhrase.empty()) ? "<null>" : a_reasonPhrase.c_str();
125 return result += " }";