Sourcemeta Core 0.0.0
Loading...
Searching...
No Matches
http_status.h
1#ifndef SOURCEMETA_CORE_HTTP_STATUS_H_
2#define SOURCEMETA_CORE_HTTP_STATUS_H_
3
4#include <cstdint> // std::uint16_t
5#include <string_view> // std::string_view
6
7namespace sourcemeta::core {
8
20struct HTTPStatus {
22 std::uint16_t code;
24 std::string_view phrase;
26 std::string_view wire;
27
28 constexpr auto operator==(const HTTPStatus &) const -> bool = default;
29};
30
34 .code = 100, .phrase = "Continue", .wire = "100 Continue"};
35
39 .code = 101,
40 .phrase = "Switching Protocols",
41 .wire = "101 Switching Protocols"};
42
46 .code = 102, .phrase = "Processing", .wire = "102 Processing"};
47
51 .code = 103, .phrase = "Early Hints", .wire = "103 Early Hints"};
52
55inline constexpr HTTPStatus HTTP_STATUS_OK{
56 .code = 200, .phrase = "OK", .wire = "200 OK"};
57
61 .code = 201, .phrase = "Created", .wire = "201 Created"};
62
66 .code = 202, .phrase = "Accepted", .wire = "202 Accepted"};
67
71 .code = 203,
72 .phrase = "Non-Authoritative Information",
73 .wire = "203 Non-Authoritative Information"};
74
78 .code = 204, .phrase = "No Content", .wire = "204 No Content"};
79
83 .code = 205, .phrase = "Reset Content", .wire = "205 Reset Content"};
84
88 .code = 206, .phrase = "Partial Content", .wire = "206 Partial Content"};
89
93 .code = 207, .phrase = "Multi-Status", .wire = "207 Multi-Status"};
94
98 .code = 208, .phrase = "Already Reported", .wire = "208 Already Reported"};
99
103 .code = 226, .phrase = "IM Used", .wire = "226 IM Used"};
104
108 .code = 300, .phrase = "Multiple Choices", .wire = "300 Multiple Choices"};
109
113 .code = 301,
114 .phrase = "Moved Permanently",
115 .wire = "301 Moved Permanently"};
116
120 .code = 302, .phrase = "Found", .wire = "302 Found"};
121
125 .code = 303, .phrase = "See Other", .wire = "303 See Other"};
126
130 .code = 304, .phrase = "Not Modified", .wire = "304 Not Modified"};
131
135 .code = 305, .phrase = "Use Proxy", .wire = "305 Use Proxy"};
136
140 .code = 307,
141 .phrase = "Temporary Redirect",
142 .wire = "307 Temporary Redirect"};
143
147 .code = 308,
148 .phrase = "Permanent Redirect",
149 .wire = "308 Permanent Redirect"};
150
154 .code = 400, .phrase = "Bad Request", .wire = "400 Bad Request"};
155
159 .code = 401, .phrase = "Unauthorized", .wire = "401 Unauthorized"};
160
164 .code = 402, .phrase = "Payment Required", .wire = "402 Payment Required"};
165
169 .code = 403, .phrase = "Forbidden", .wire = "403 Forbidden"};
170
174 .code = 404, .phrase = "Not Found", .wire = "404 Not Found"};
175
179 .code = 405,
180 .phrase = "Method Not Allowed",
181 .wire = "405 Method Not Allowed"};
182
186 .code = 406, .phrase = "Not Acceptable", .wire = "406 Not Acceptable"};
187
191 .code = 407,
192 .phrase = "Proxy Authentication Required",
193 .wire = "407 Proxy Authentication Required"};
194
198 .code = 408, .phrase = "Request Timeout", .wire = "408 Request Timeout"};
199
203 .code = 409, .phrase = "Conflict", .wire = "409 Conflict"};
204
208 .code = 410, .phrase = "Gone", .wire = "410 Gone"};
209
213 .code = 411, .phrase = "Length Required", .wire = "411 Length Required"};
214
218 .code = 412,
219 .phrase = "Precondition Failed",
220 .wire = "412 Precondition Failed"};
221
226 .code = 413,
227 .phrase = "Content Too Large",
228 .wire = "413 Content Too Large"};
229
233 .code = 414, .phrase = "URI Too Long", .wire = "414 URI Too Long"};
234
238 .code = 415,
239 .phrase = "Unsupported Media Type",
240 .wire = "415 Unsupported Media Type"};
241
245 .code = 416,
246 .phrase = "Range Not Satisfiable",
247 .wire = "416 Range Not Satisfiable"};
248
252 .code = 417,
253 .phrase = "Expectation Failed",
254 .wire = "417 Expectation Failed"};
255
259 .code = 418, .phrase = "I'm a Teapot", .wire = "418 I'm a Teapot"};
260
264 .code = 421,
265 .phrase = "Misdirected Request",
266 .wire = "421 Misdirected Request"};
267
271 .code = 422,
272 .phrase = "Unprocessable Content",
273 .wire = "422 Unprocessable Content"};
274
278 .code = 423, .phrase = "Locked", .wire = "423 Locked"};
279
283 .code = 424,
284 .phrase = "Failed Dependency",
285 .wire = "424 Failed Dependency"};
286
290 .code = 425, .phrase = "Too Early", .wire = "425 Too Early"};
291
295 .code = 426, .phrase = "Upgrade Required", .wire = "426 Upgrade Required"};
296
300 .code = 428,
301 .phrase = "Precondition Required",
302 .wire = "428 Precondition Required"};
303
307 .code = 429,
308 .phrase = "Too Many Requests",
309 .wire = "429 Too Many Requests"};
310
314 .code = 431,
315 .phrase = "Request Header Fields Too Large",
316 .wire = "431 Request Header Fields Too Large"};
317
321 .code = 451,
322 .phrase = "Unavailable For Legal Reasons",
323 .wire = "451 Unavailable For Legal Reasons"};
324
328 .code = 500,
329 .phrase = "Internal Server Error",
330 .wire = "500 Internal Server Error"};
331
335 .code = 501, .phrase = "Not Implemented", .wire = "501 Not Implemented"};
336
340 .code = 502, .phrase = "Bad Gateway", .wire = "502 Bad Gateway"};
341
345 .code = 503,
346 .phrase = "Service Unavailable",
347 .wire = "503 Service Unavailable"};
348
352 .code = 504, .phrase = "Gateway Timeout", .wire = "504 Gateway Timeout"};
353
357 .code = 505,
358 .phrase = "HTTP Version Not Supported",
359 .wire = "505 HTTP Version Not Supported"};
360
364 .code = 506,
365 .phrase = "Variant Also Negotiates",
366 .wire = "506 Variant Also Negotiates"};
367
371 .code = 507,
372 .phrase = "Insufficient Storage",
373 .wire = "507 Insufficient Storage"};
374
378 .code = 508, .phrase = "Loop Detected", .wire = "508 Loop Detected"};
379
383 .code = 510, .phrase = "Not Extended", .wire = "510 Not Extended"};
384
388 .code = 511,
389 .phrase = "Network Authentication Required",
390 .wire = "511 Network Authentication Required"};
391
404inline constexpr auto http_status_from_code(const std::uint16_t code) noexcept
405 -> HTTPStatus {
406 switch (code) {
407 case 100:
409 case 101:
411 case 102:
413 case 103:
415 case 200:
416 return HTTP_STATUS_OK;
417 case 201:
418 return HTTP_STATUS_CREATED;
419 case 202:
421 case 203:
423 case 204:
425 case 205:
427 case 206:
429 case 207:
431 case 208:
433 case 226:
434 return HTTP_STATUS_IM_USED;
435 case 300:
437 case 301:
439 case 302:
440 return HTTP_STATUS_FOUND;
441 case 303:
443 case 304:
445 case 305:
447 case 307:
449 case 308:
451 case 400:
453 case 401:
455 case 402:
457 case 403:
459 case 404:
461 case 405:
463 case 406:
465 case 407:
467 case 408:
469 case 409:
471 case 410:
472 return HTTP_STATUS_GONE;
473 case 411:
475 case 412:
477 case 413:
479 case 414:
481 case 415:
483 case 416:
485 case 417:
487 case 418:
489 case 421:
491 case 422:
493 case 423:
494 return HTTP_STATUS_LOCKED;
495 case 424:
497 case 425:
499 case 426:
501 case 428:
503 case 429:
505 case 431:
507 case 451:
509 case 500:
511 case 501:
513 case 502:
515 case 503:
517 case 504:
519 case 505:
521 case 506:
523 case 507:
525 case 508:
527 case 510:
529 case 511:
531 default:
532 return HTTPStatus{.code = code, .phrase = {}, .wire = {}};
533 }
534}
535
536} // namespace sourcemeta::core
537
538#endif
std::uint16_t code
The numeric status code.
Definition http_status.h:22
std::string_view wire
The status code and reason phrase in their wire form.
Definition http_status.h:26
std::string_view phrase
The reason phrase.
Definition http_status.h:24
constexpr HTTPStatus HTTP_STATUS_CONTENT_TOO_LARGE
Definition http_status.h:225
constexpr HTTPStatus HTTP_STATUS_URI_TOO_LONG
Definition http_status.h:232
constexpr HTTPStatus HTTP_STATUS_UPGRADE_REQUIRED
Definition http_status.h:294
constexpr HTTPStatus HTTP_STATUS_IM_A_TEAPOT
Definition http_status.h:258
constexpr HTTPStatus HTTP_STATUS_ALREADY_REPORTED
Definition http_status.h:97
constexpr HTTPStatus HTTP_STATUS_FORBIDDEN
Definition http_status.h:168
constexpr HTTPStatus HTTP_STATUS_USE_PROXY
Definition http_status.h:134
constexpr HTTPStatus HTTP_STATUS_NOT_MODIFIED
Definition http_status.h:129
constexpr HTTPStatus HTTP_STATUS_EARLY_HINTS
Definition http_status.h:50
constexpr HTTPStatus HTTP_STATUS_REQUEST_TIMEOUT
Definition http_status.h:197
constexpr HTTPStatus HTTP_STATUS_INTERNAL_SERVER_ERROR
Definition http_status.h:327
constexpr HTTPStatus HTTP_STATUS_UNSUPPORTED_MEDIA_TYPE
Definition http_status.h:237
constexpr HTTPStatus HTTP_STATUS_SERVICE_UNAVAILABLE
Definition http_status.h:344
constexpr HTTPStatus HTTP_STATUS_RANGE_NOT_SATISFIABLE
Definition http_status.h:244
constexpr HTTPStatus HTTP_STATUS_LOOP_DETECTED
Definition http_status.h:377
constexpr HTTPStatus HTTP_STATUS_REQUEST_HEADER_FIELDS_TOO_LARGE
Definition http_status.h:313
constexpr auto http_status_from_code(const std::uint16_t code) noexcept -> HTTPStatus
Definition http_status.h:404
constexpr HTTPStatus HTTP_STATUS_LOCKED
Definition http_status.h:277
constexpr HTTPStatus HTTP_STATUS_UNPROCESSABLE_CONTENT
Definition http_status.h:270
constexpr HTTPStatus HTTP_STATUS_UNAUTHORIZED
Definition http_status.h:158
constexpr HTTPStatus HTTP_STATUS_TEMPORARY_REDIRECT
Definition http_status.h:139
constexpr HTTPStatus HTTP_STATUS_NOT_ACCEPTABLE
Definition http_status.h:185
constexpr HTTPStatus HTTP_STATUS_GONE
Definition http_status.h:207
constexpr HTTPStatus HTTP_STATUS_PARTIAL_CONTENT
Definition http_status.h:87
constexpr HTTPStatus HTTP_STATUS_BAD_REQUEST
Definition http_status.h:153
constexpr HTTPStatus HTTP_STATUS_VARIANT_ALSO_NEGOTIATES
Definition http_status.h:363
constexpr HTTPStatus HTTP_STATUS_NOT_FOUND
Definition http_status.h:173
constexpr HTTPStatus HTTP_STATUS_SEE_OTHER
Definition http_status.h:124
constexpr HTTPStatus HTTP_STATUS_MULTI_STATUS
Definition http_status.h:92
constexpr HTTPStatus HTTP_STATUS_MULTIPLE_CHOICES
Definition http_status.h:107
constexpr HTTPStatus HTTP_STATUS_MOVED_PERMANENTLY
Definition http_status.h:112
constexpr HTTPStatus HTTP_STATUS_SWITCHING_PROTOCOLS
Definition http_status.h:38
constexpr HTTPStatus HTTP_STATUS_METHOD_NOT_ALLOWED
Definition http_status.h:178
constexpr HTTPStatus HTTP_STATUS_OK
Definition http_status.h:55
constexpr HTTPStatus HTTP_STATUS_PAYMENT_REQUIRED
Definition http_status.h:163
constexpr HTTPStatus HTTP_STATUS_CONTINUE
Definition http_status.h:33
constexpr HTTPStatus HTTP_STATUS_RESET_CONTENT
Definition http_status.h:82
constexpr HTTPStatus HTTP_STATUS_UNAVAILABLE_FOR_LEGAL_REASONS
Definition http_status.h:320
constexpr HTTPStatus HTTP_STATUS_PROCESSING
Definition http_status.h:45
constexpr HTTPStatus HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED
Definition http_status.h:356
constexpr HTTPStatus HTTP_STATUS_BAD_GATEWAY
Definition http_status.h:339
constexpr HTTPStatus HTTP_STATUS_NON_AUTHORITATIVE_INFORMATION
Definition http_status.h:70
constexpr HTTPStatus HTTP_STATUS_TOO_MANY_REQUESTS
Definition http_status.h:306
constexpr HTTPStatus HTTP_STATUS_PRECONDITION_REQUIRED
Definition http_status.h:299
constexpr HTTPStatus HTTP_STATUS_IM_USED
Definition http_status.h:102
constexpr HTTPStatus HTTP_STATUS_NETWORK_AUTHENTICATION_REQUIRED
Definition http_status.h:387
constexpr HTTPStatus HTTP_STATUS_TOO_EARLY
Definition http_status.h:289
constexpr HTTPStatus HTTP_STATUS_PROXY_AUTHENTICATION_REQUIRED
Definition http_status.h:190
constexpr HTTPStatus HTTP_STATUS_NOT_EXTENDED
Definition http_status.h:382
constexpr HTTPStatus HTTP_STATUS_NOT_IMPLEMENTED
Definition http_status.h:334
constexpr HTTPStatus HTTP_STATUS_CREATED
Definition http_status.h:60
constexpr HTTPStatus HTTP_STATUS_FOUND
Definition http_status.h:119
constexpr HTTPStatus HTTP_STATUS_NO_CONTENT
Definition http_status.h:77
constexpr HTTPStatus HTTP_STATUS_MISDIRECTED_REQUEST
Definition http_status.h:263
constexpr HTTPStatus HTTP_STATUS_LENGTH_REQUIRED
Definition http_status.h:212
constexpr HTTPStatus HTTP_STATUS_CONFLICT
Definition http_status.h:202
constexpr HTTPStatus HTTP_STATUS_INSUFFICIENT_STORAGE
Definition http_status.h:370
constexpr HTTPStatus HTTP_STATUS_EXPECTATION_FAILED
Definition http_status.h:251
constexpr HTTPStatus HTTP_STATUS_FAILED_DEPENDENCY
Definition http_status.h:282
constexpr HTTPStatus HTTP_STATUS_PRECONDITION_FAILED
Definition http_status.h:217
constexpr HTTPStatus HTTP_STATUS_GATEWAY_TIMEOUT
Definition http_status.h:351
constexpr HTTPStatus HTTP_STATUS_PERMANENT_REDIRECT
Definition http_status.h:146
constexpr HTTPStatus HTTP_STATUS_ACCEPTED
Definition http_status.h:65
Definition http_status.h:20