libutil++  1.9.3
 All Classes Functions Variables
Code.h
1 /*
2 ** libutil++
3 ** $Id: Code.h 1769 2016-11-22 22:22:20Z sella $
4 ** Copyright (c) 2011-2016 Digital Genesis, LLC. All Rights Reserved.
5 ** Released under the LGPL Version 2.1 License.
6 ** http://www.digitalgenesis.com
7 */
8 
9 #ifndef __libutilxx__sella__server__Code_H__
10 #define __libutilxx__sella__server__Code_H__
11 
12 #include "../../common.h"
13 #include "../util/String.h"
14 
15 #include <string>
16 
17 namespace sella {
18  namespace server {
19  class Code;
20  }
21 }
22 
24  public:
25 
26  enum Codes : int {
27  Continue = 100,
28  OK = 200, Created = 201, NoContent = 204,
29  BadRequest = 400, Unauthorized = 401, Forbidden = 403, NotFound = 404, MethodNotAllowed = 405, Gone = 410, RequestEntityTooLarge = 413,
30  InternalServerError = 500, NotImplemented = 501, ServiceUnavailable = 503
31  };
32 
33  static std::string statusCodeDisplayString(int code) throw () {
34  return sella::util::String::sprintf("%d ", code).append(statusCodeString(code));
35  }
36 
37  static std::string statusCodeString(int code) throw () {
38  switch (code) {
39  case 100:
40  return std::string("Continue");
41 
42  case 101:
43  return std::string("Switching Protocols");
44 
45  case 200:
46  return std::string("OK");
47 
48  case 201:
49  return std::string("Created");
50 
51  case 202:
52  return std::string("Accepted");
53 
54  case 203:
55  return std::string("Non-Authoritative Information");
56 
57  case 204:
58  return std::string("No Content");
59 
60  case 205:
61  return std::string("Reset Content");
62 
63  case 206:
64  return std::string("Partial Content");
65 
66  case 300:
67  return std::string("Multiple Choices");
68 
69  case 301:
70  return std::string("Moved Permanently");
71 
72  case 302:
73  return std::string("Found");
74 
75  case 303:
76  return std::string("See Other");
77 
78  case 304:
79  return std::string("Not Modified");
80 
81  case 305:
82  return std::string("Use Proxy");
83 
84  case 307:
85  return std::string("Temporary Redirect");
86 
87  case 400:
88  return std::string("Bad Request");
89 
90  case 401:
91  return std::string("Unauthorized");
92 
93  case 402:
94  return std::string("Payment Required");
95 
96  case 403:
97  return std::string("Forbidden");
98 
99  case 404:
100  return std::string("Not Found");
101 
102  case 405:
103  return std::string("Method Not Allowed");
104 
105  case 406:
106  return std::string("Not Acceptable");
107 
108  case 407:
109  return std::string("Proxy Authentication Required");
110 
111  case 408:
112  return std::string("Request Time-out");
113 
114  case 409:
115  return std::string("Conflict");
116 
117  case 410:
118  return std::string("Gone");
119 
120  case 411:
121  return std::string("Length Required");
122 
123  case 412:
124  return std::string("Precondition Failed");
125 
126  case 413:
127  return std::string("Request Entity Too Large");
128 
129  case 414:
130  return std::string("Request-URI Too Large");
131 
132  case 415:
133  return std::string("Unsupported Media Type");
134 
135  case 416:
136  return std::string("Requested range not satisfiable");
137 
138  case 417:
139  return std::string("Expectation Failed");
140 
141  case 421:
142  return std::string("Misdirected Request");
143 
144  case 422:
145  return std::string("Unprocessable Entity");
146 
147  case 423:
148  return std::string("Locked");
149 
150  case 424:
151  return std::string("Failed Dependency");
152 
153  case 426:
154  return std::string("Upgrade Required");
155 
156  case 428:
157  return std::string("Precondition Required");
158 
159  case 429:
160  return std::string("Too Many Requests");
161 
162  case 431:
163  return std::string("Request Header Fields Too Large");
164 
165  case 451:
166  return std::string("Unavailable For Legal Reasons");
167 
168  case 498:
169  return std::string("Invalid Token");
170 
171  case 499:
172  return std::string("Token Required");
173 
174  case 500:
175  return std::string("Internal Server Error");
176 
177  case 501:
178  return std::string("Not Implemented");
179 
180  case 502:
181  return std::string("Bad Gateway");
182 
183  case 503:
184  return std::string("Service Unavailable");
185 
186  case 504:
187  return std::string("Gateway Time-out");
188 
189  case 505:
190  return std::string("HTTP Version not supported");
191 
192  case 506:
193  return std::string("Variant Also Negotiates");
194 
195  case 507:
196  return std::string("Insufficient Storage");
197 
198  case 508:
199  return std::string("Loop Detected");
200 
201  case 509:
202  return std::string("Bandwidth Limit Exceeded");
203 
204  case 510:
205  return std::string("Not Extended");
206 
207  case 511:
208  return std::string("Network Authentication Required");
209 
210  case 599:
211  return std::string("Network connect timeout error");
212  }
213 
214  if (code >= 500 && code < 600) {
215  return sella::util::String::sprintf("Server Error", code);
216  } else if (code >= 400) {
217  return sella::util::String::sprintf("Client Error", code);
218  } else if (code >= 300) {
219  return sella::util::String::sprintf("Redirection", code);
220  } else if (code >= 200) {
221  return sella::util::String::sprintf("Successful", code);
222  } else if (code >= 100) {
223  return sella::util::String::sprintf("Informational", code);
224  }
225 
226  return sella::util::String::sprintf("Unknown", code);
227  }
228 };
229 
230 #endif
231 
232 /*
233 ** vim: noet ts=3 sw=3
234 */