userver: userver/http/status_code.hpp Source File
Loading...
Searching...
No Matches
status_code.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/http/status_code.hpp
4/// @brief @copybrief http::StatusCode
5
6#include <cstdint>
7#include <iosfwd>
8
9#include <fmt/format.h>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace http {
14
15/// https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
17 kInvalid = 0,
18
19 // 1xx informational response
20 kContinue = 100,
21 kSwitchingProtocols = 101,
22 kProcessing = 102,
23 kEarlyHints = 103,
24
25 // 2xx success
26 kOk = 200,
27 kCreated = 201,
28 kAccepted = 202,
29 kNonAuthoritativeInformation = 203,
30 kNoContent = 204,
31 kResetContent = 205,
32 kPartialContent = 206,
33 kMultiStatus = 207,
34 kAlreadyReported = 208,
35 kThisIsFine = 218,
36 kImUsed = 226,
37
38 // 3xx redirection
39 kMultipleChoices = 300,
40 kMovedPermanently = 301,
41 kFound = 302,
42 kSeeOther = 303,
43 kNotModified = 304,
44 kUseProxy = 305,
45 kSwitchProxy = 306,
46 kTemporaryRedirect = 307,
47 kPermanentRedirect = 308,
48
49 // 4xx client errors
50 kBadRequest = 400,
51 kUnauthorized = 401,
52 kPaymentRequired = 402,
53 kForbidden = 403,
54 kNotFound = 404,
55 kMethodNotAllowed = 405,
56 kNotAcceptable = 406,
57 kProxyAuthenticationRequired = 407,
58 kRequestTimeout = 408,
59 kConflict = 409,
60 kGone = 410,
61 kLengthRequired = 411,
62 kPreconditionFailed = 412,
63 kPayloadTooLarge = 413,
64 kUriTooLong = 414,
65 kUnsupportedMediaType = 415,
66 kRangeNotSatisfiable = 416,
67 kExpectationFailed = 417,
68 kImATeapot = 418,
69 kPageExpired = 419,
70 kMethodFailure = 420,
71 kMisdirectedRequest = 421,
72 kUnprocessableEntity = 422,
73 kLocked = 423,
74 kFailedDependency = 424,
75 kTooEarly = 425,
76 kUpgradeRequired = 426,
77 kPreconditionRequired = 428,
78 kTooManyRequests = 429,
79 kRequestHeaderFieldsTooLarge = 431,
80 kNginxNoResponse = 444,
81 kUnavailableForLegalReasons = 451,
82 kNginxRequestHeaderTooLarge = 494,
83 kNginxSSLCertificateError = 495,
84 kNginxSSLCertificateRequired = 496,
85 kNginxHTTPRequestSenttoHTTPSPort = 497,
86 kDeadlineExpired = 498, // userver-specific
87 kNginxClientClosedRequest = 499,
88
89 // 5xx server errors
90 kInternalServerError = 500,
91 kNotImplemented = 501,
92 kBadGateway = 502,
93 kServiceUnavailable = 503,
94 kGatewayTimeout = 504,
95 kHttpVersionNotSupported = 505,
96 kVariantAlsoNegotiates = 506,
97 kInsufficientStorage = 507,
98 kLoopDetected = 508,
99 kBandwidthLimitExceeded = 509,
100 kNotExtended = 510,
101 kNetworkAuthenticationRequired = 511,
102 kWebServerIsDown = 520,
103 kConnectionTimedOut = 522,
104 kOriginIsUnreachable = 523,
105 kTimeoutOccurred = 524,
106 kSslHandshakeFailed = 525,
107 kInvalidSslCertificate = 526,
108
109 // migration aliases
110 Invalid = kInvalid,
111 OK = kOk,
112 Created = kCreated,
113 NoContent = kNoContent,
114 BadRequest = kBadRequest,
115 NotFound = kNotFound,
116 Conflict = kConflict,
117 TooManyRequests = kTooManyRequests,
118 InternalServerError = kInternalServerError,
119 kClientClosedRequest = kNginxClientClosedRequest,
120};
121
122std::string_view StatusCodeString(StatusCode status);
123
124std::string ToString(StatusCode status);
125
126std::ostream& operator<<(std::ostream& os, StatusCode s);
127
128} // namespace http
129
130USERVER_NAMESPACE_END
131
132template <>
133struct fmt::formatter<USERVER_NAMESPACE::http::StatusCode> {
134 constexpr static auto parse(format_parse_context& ctx) { return ctx.begin(); }
135
136 template <typename FormatContext>
137 auto format(USERVER_NAMESPACE::http::StatusCode status,
138 FormatContext& ctx) const {
139 return fmt::format_to(ctx.out(), "{} {}", static_cast<int>(status),
140 USERVER_NAMESPACE::http::StatusCodeString(status));
141 }
142};