StatusCode
Include fastly/http/status_code.h to use this class.
Constructor
Overload 1 of 2
fastly::http::StatusCode::StatusCode() = defaultOverload 2 of 2
Creates a new StatusCode. Panics if the code is out of range.
Parameters
- code: uint16_t
Constants
100 Continue RFC9110, Section 15.2.1
101 Switching Protocols RFC9110, Section 15.2.2
102 Processing RFC2518, Section 10.1
200 OK RFC9110, Section 15.3.1
201 Created RFC9110, Section 15.3.2
202 Accepted RFC9110, Section 15.3.3
203 Non-Authoritative Information RFC9110, Section 15.3.4
204 No Content RFC9110, Section 15.3.5
205 Reset Content RFC9110, Section 15.3.6
206 Partial Content RFC9110, Section 15.3.7
207 Multi-Status RFC4918, Section 11.1
208 Already Reported RFC5842, Section 7.1
226 IM Used RFC3229, Section 10.4.1
300 Multiple Choices RFC9110, Section 15.4.1
301 Moved Permanently RFC9110, Section 15.4.2
302 Found RFC9110, Section 15.4.3
303 See Other RFC9110, Section 15.4.4
304 Not Modified RFC9110, Section 15.4.5
305 Use Proxy RFC9110, Section 15.4.6
307 Temporary Redirect RFC9110, Section 15.4.7
308 Permanent Redirect RFC9110, Section 15.4.8
400 Bad Request RFC9110, Section 15.5.1
401 Unauthorized RFC9110, Section 15.5.2
402 Payment Required RFC9110, Section 15.5.3
403 Forbidden RFC9110, Section 15.5.4
404 Not Found RFC9110, Section 15.5.5
405 Method Not Allowed RFC9110, Section 15.5.6
406 Not Acceptable RFC9110, Section 15.5.7
407 Proxy Authentication Required RFC9110, Section 15.5.8
408 Request Timeout RFC9110, Section 15.5.9
409 Conflict RFC9110, Section 15.5.10
410 Gone RFC9110, Section 15.5.11
411 Length Required RFC9110, Section 15.5.12
412 Precondition Failed RFC9110, Section 15.5.13
413 Payload Too Large RFC9110, Section 15.5.14
414 URI Too Long RFC9110, Section 15.5.15
415 Unsupported Media Type RFC9110, Section 15.5.16
416 Range Not Satisfiable RFC9110, Section 15.5.17
417 Expectation Failed RFC9110, Section 15.5.18
418 I'm a teapot [curiously not registered by IANA but RFC2324, Section 2.3.2]
421 Misdirected Request RFC9110, Section 15.5.20
422 Unprocessable Entity RFC9110, Section 15.5.21
423 Locked RFC4918, Section 11.3
424 Failed Dependency RFC4918, Section 11.4
425 Too early RFC8470, Section 5.2
426 Upgrade Required RFC9110, Section 15.5.22
428 Precondition Required RFC6585, Section 3
429 Too Many Requests RFC6585, Section 4
431 Request Header Fields Too Large RFC6585, Section 5
451 Unavailable For Legal Reasons RFC7725, Section 3
500 Internal Server Error RFC9110, Section 15.6.1
501 Not Implemented RFC9110, Section 15.6.2
502 Bad Gateway RFC9110, Section 15.6.3
503 Service Unavailable RFC9110, Section 15.6.4
504 Gateway Timeout RFC9110, Section 15.6.5
505 HTTP Version Not Supported RFC9110, Section 15.6.6
506 Variant Also Negotiates RFC2295, Section 8.1
507 Insufficient Storage RFC4918, Section 11.5
508 Loop Detected RFC5842, Section 7.2
510 Not Extended RFC2774, Section 7
511 Network Authentication Required RFC6585, Section 6
Methods
canonical_reason
View sourcetl::expected<std::optional<std::string>, fastly::FastlyError> fastly::http::StatusCode::canonical_reason()Get the standardised reason-phrase for this status code.
This is mostly here for servers writing responses, but could potentially have application at other times.
The reason phrase is defined as being exclusively for human readers. You should avoid deriving any meaning from it at all costs.
Bear in mind also that in HTTP/2.0 and HTTP/3.0 the reason phrase is abolished from transmission, and so this canonical reason phrase really is the only reason phrase you’ll find.
Example
Returns
auto status{fastly::http::StatusCode::OK};assert(status.canonical_reason() == std::optional("OK"s)));from_code
View sourceConverts a uint16_t to a status code, returning it wrapped in an std::optional.
The method validates the correctness of the supplied uint16_t. It must be greater or equal to 100 and less than 1000, or this method will return std::nullopt.
Parameters
- code: uint16_t
Returns
is_client_error
View sourcebool fastly::http::StatusCode::is_client_error()Check if status is within 400-499.
Returns
is_informational
View sourcebool fastly::http::StatusCode::is_informational()Check if status is within 100-199.
Returns
is_redirection
View sourcebool fastly::http::StatusCode::is_redirection()Check if status is within 300-399.
Returns
is_server_error
View sourcebool fastly::http::StatusCode::is_server_error()Check if status is within 500-599.
Returns
is_success
View sourcebool fastly::http::StatusCode::is_success()Check if status is within 200-299.
Returns
operator bool
View sourceexplicit fastly::http::StatusCode::operator bool() const = deleteoperator!=
View sourceconstexpr constexpr bool fastly::http::StatusCode::operator!=(StatusCode a) constParameters
- a: StatusCode
Returns
operator==
View sourceconstexpr constexpr bool fastly::http::StatusCode::operator==(StatusCode a) constParameters
- a: StatusCode
Returns