userver: userver/server/http/http_status.hpp Source File
Loading...
Searching...
No Matches
http_status.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/http/http_status.hpp
4/// @brief @copybrief server::http::HttpStatus
5
6#include <string_view>
7
8#include <fmt/core.h>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace server::http {
13
14/// @brief HTTP status codes
15enum class HttpStatus {
16 kContinue = 100,
17 kSwitchingProtocols = 101,
18 kProcessing = 102,
19 kOk = 200,
20 kCreated = 201,
21 kAccepted = 202,
22 kNonAuthoritativeInformation = 203,
23 kNoContent = 204,
24 kResetContent = 205,
25 kPartialContent = 206,
26 kMultiStatus = 207,
27 kAlreadyReported = 208,
28 kImUsed = 226,
29 kMultipleChoices = 300,
30 kMovedPermanently = 301,
31 kFound = 302,
32 kSeeOther = 303,
33 kNotModified = 304,
34 kUseProxy = 305,
35 kTemporaryRedirect = 307,
36 kPermanentRedirect = 308,
37 kBadRequest = 400,
38 kUnauthorized = 401,
39 kPaymentRequired = 402,
40 kForbidden = 403,
41 kNotFound = 404,
42 kMethodNotAllowed = 405,
43 kNotAcceptable = 406,
44 kProxyAuthenticationRequired = 407,
45 kRequestTimeout = 408,
46 kConflict = 409,
47 kGone = 410,
48 kLengthRequired = 411,
49 kPreconditionFailed = 412,
50 kPayloadTooLarge = 413,
51 kUriTooLong = 414,
52 kUnsupportedMediaType = 415,
53 kRangeNotSatisfiable = 416,
54 kExpectationFailed = 417,
55 kImATeapot = 418,
56 kMisdirectedRequest = 421,
57 kUnprocessableEntity = 422,
58 kLocked = 423,
59 kFailedDependency = 424,
60 kTooEarly = 425,
61 kUpgradeRequired = 426,
62 kPreconditionRequired = 428,
63 kTooManyRequests = 429,
64 kRequestHeaderFieldsTooLarge = 431,
65 kUnavailableForLegalReasons = 451,
66 kDeadlineExpired = 498, // userver-specific
67 kClientClosedRequest = 499, // nginx-specific
68 kInternalServerError = 500,
69 kNotImplemented = 501,
70 kBadGateway = 502,
71 kServiceUnavailable = 503,
72 kGatewayTimeout = 504,
73 kHttpVersionNotSupported = 505,
74 kVariantAlsoNegotiates = 506,
75 kInsufficientStorage = 507,
76 kLoopDetected = 508,
77 kNotExtended = 510,
78 kNetworkAuthenticationRequired = 511,
79};
80
81std::string_view HttpStatusString(HttpStatus status);
82
83std::string ToString(HttpStatus status);
84
85} // namespace server::http
86
87USERVER_NAMESPACE_END
88
89template <>
90struct fmt::formatter<USERVER_NAMESPACE::server::http::HttpStatus> {
91 constexpr static auto parse(format_parse_context& ctx) { return ctx.begin(); }
92
93 template <typename FormatContext>
94 auto format(USERVER_NAMESPACE::server::http::HttpStatus status,
95 FormatContext& ctx) const {
96 return fmt::format_to(
97 ctx.out(), "{} {}", static_cast<int>(status),
98 USERVER_NAMESPACE::server::http::HttpStatusString(status));
99 }
100};