1 //
2 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/boostorg/beast
8 //
9 
10 #ifndef BOOST_BEAST_HTTP_STATUS_HPP
11 #define BOOST_BEAST_HTTP_STATUS_HPP
12 
13 #include <boost/beast/core/detail/config.hpp>
14 #include <boost/beast/core/string.hpp>
15 #include <iosfwd>
16 
17 namespace boost {
18 namespace beast {
19 namespace http {
20 
21 enum class status : unsigned
22 {
23     /** An unknown status-code.
24 
25         This value indicates that the value for the status code
26         is not in the list of commonly recognized status codes.
27         Callers interested in the exactly value should use the
28         interface which provides the raw integer.
29     */
30     unknown = 0,
31 
32     continue_                           = 100,
33 
34     /** Switching Protocols
35 
36         This status indicates that a request to switch to a new
37         protocol was accepted and applied by the server. A successful
38         response to a WebSocket Upgrade HTTP request will have this
39         code.
40     */
41     switching_protocols                 = 101,
42 
43     processing                          = 102,
44 
45     ok                                  = 200,
46     created                             = 201,
47     accepted                            = 202,
48     non_authoritative_information       = 203,
49     no_content                          = 204,
50     reset_content                       = 205,
51     partial_content                     = 206,
52     multi_status                        = 207,
53     already_reported                    = 208,
54     im_used                             = 226,
55 
56     multiple_choices                    = 300,
57     moved_permanently                   = 301,
58     found                               = 302,
59     see_other                           = 303,
60     not_modified                        = 304,
61     use_proxy                           = 305,
62     temporary_redirect                  = 307,
63     permanent_redirect                  = 308,
64 
65     bad_request                         = 400,
66     unauthorized                        = 401,
67     payment_required                    = 402,
68     forbidden                           = 403,
69     not_found                           = 404,
70     method_not_allowed                  = 405,
71     not_acceptable                      = 406,
72     proxy_authentication_required       = 407,
73     request_timeout                     = 408,
74     conflict                            = 409,
75     gone                                = 410,
76     length_required                     = 411,
77     precondition_failed                 = 412,
78     payload_too_large                   = 413,
79     uri_too_long                        = 414,
80     unsupported_media_type              = 415,
81     range_not_satisfiable               = 416,
82     expectation_failed                  = 417,
83     misdirected_request                 = 421,
84     unprocessable_entity                = 422,
85     locked                              = 423,
86     failed_dependency                   = 424,
87     upgrade_required                    = 426,
88     precondition_required               = 428,
89     too_many_requests                   = 429,
90     request_header_fields_too_large     = 431,
91     connection_closed_without_response  = 444,
92     unavailable_for_legal_reasons       = 451,
93     client_closed_request               = 499,
94 
95     internal_server_error               = 500,
96     not_implemented                     = 501,
97     bad_gateway                         = 502,
98     service_unavailable                 = 503,
99     gateway_timeout                     = 504,
100     http_version_not_supported          = 505,
101     variant_also_negotiates             = 506,
102     insufficient_storage                = 507,
103     loop_detected                       = 508,
104     not_extended                        = 510,
105     network_authentication_required     = 511,
106     network_connect_timeout_error       = 599
107 };
108 
109 /** Represents the class of a status-code.
110 */
111 enum class status_class : unsigned
112 {
113     /// Unknown status-class
114     unknown = 0,
115 
116     /// The request was received, continuing processing.
117     informational = 1,
118 
119     /// The request was successfully received, understood, and accepted.
120     successful = 2,
121 
122     /// Further action needs to be taken in order to complete the request.
123     redirection = 3,
124 
125     /// The request contains bad syntax or cannot be fulfilled.
126     client_error = 4,
127 
128     /// The server failed to fulfill an apparently valid request.
129     server_error = 5,
130 };
131 
132 /** Converts the integer to a known status-code.
133 
134     If the integer does not match a known status code,
135     @ref status::unknown is returned.
136 */
137 BOOST_BEAST_DECL
138 status
139 int_to_status(unsigned v);
140 
141 /** Convert an integer to a status_class.
142 
143     @param v The integer representing a status code.
144 
145     @return The status class. If the integer does not match
146     a known status class, @ref status_class::unknown is returned.
147 */
148 BOOST_BEAST_DECL
149 status_class
150 to_status_class(unsigned v);
151 
152 /** Convert a status_code to a status_class.
153 
154     @param v The status code to convert.
155 
156     @return The status class.
157 */
158 BOOST_BEAST_DECL
159 status_class
160 to_status_class(status v);
161 
162 /** Returns the obsolete reason-phrase text for a status code.
163 
164     @param v The status code to use.
165 */
166 BOOST_BEAST_DECL
167 string_view
168 obsolete_reason(status v);
169 
170 /// Outputs the standard reason phrase of a status code to a stream.
171 BOOST_BEAST_DECL
172 std::ostream&
173 operator<<(std::ostream&, status);
174 
175 } // http
176 } // beast
177 } // boost
178 
179 #ifdef BOOST_BEAST_HEADER_ONLY
180 #include <boost/beast/http/impl/status.ipp>
181 #endif
182 
183 #endif
184