Struct actix_web::http::StatusCode [−][src]
pub struct StatusCode(_);
An HTTP status code (status-code
in RFC 7230 et al.).
This type contains constants for all common status codes. It allows status codes in the range [100, 599].
IANA maintain the Hypertext Transfer Protocol (HTTP) Status Code Registry which is the source for this enum (with one exception, 418 I'm a teapot, which is inexplicably not in the register).
Examples
use http::StatusCode; assert_eq!(StatusCode::from_u16(200).unwrap(), StatusCode::OK); assert_eq!(StatusCode::NOT_FOUND.as_u16(), 404); assert!(StatusCode::OK.is_success());
Methods
impl StatusCode
[src]
impl StatusCode
pub fn from_u16(src: u16) -> Result<StatusCode, InvalidStatusCode>
[src]
pub fn from_u16(src: u16) -> Result<StatusCode, InvalidStatusCode>
Converts a u16 to a status code.
The function validates the correctness of the supplied u16. It must be greater or equal to 100 but less than 600.
Example
use http::StatusCode; let ok = StatusCode::from_u16(200).unwrap(); assert_eq!(ok, StatusCode::OK); let err = StatusCode::from_u16(99); assert!(err.is_err());
pub fn from_bytes(src: &[u8]) -> Result<StatusCode, InvalidStatusCode>
[src]
pub fn from_bytes(src: &[u8]) -> Result<StatusCode, InvalidStatusCode>
Converts a &u8 to a status code
pub fn as_u16(&self) -> u16
[src]
pub fn as_u16(&self) -> u16
Returns the u16
corresponding to this StatusCode
.
Note
This is the same as the From<StatusCode>
implementation, but
included as an inherent method because that implementation doesn't
appear in rustdocs, as well as a way to force the type instead of
relying on inference.
Example
let status = http::StatusCode::OK; assert_eq!(status.as_u16(), 200);
pub fn as_str(&self) -> &str
[src]
pub fn as_str(&self) -> &str
Returns a &str representation of the StatusCode
The return value only includes a numerical representation of the status code. The canonical reason is not included.
Example
let status = http::StatusCode::OK; assert_eq!(status.as_str(), "200");
pub fn canonical_reason(&self) -> Option<&'static str>
[src]
pub fn canonical_reason(&self) -> Option<&'static str>
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 the reason phrase is abolished from transmission, and so this canonical reason phrase really is the only reason phrase you’ll find.
Example
let status = http::StatusCode::OK; assert_eq!(status.canonical_reason(), Some("OK"));
pub fn is_informational(&self) -> bool
[src]
pub fn is_informational(&self) -> bool
Check if status is within 100-199.
pub fn is_success(&self) -> bool
[src]
pub fn is_success(&self) -> bool
Check if status is within 200-299.
pub fn is_redirection(&self) -> bool
[src]
pub fn is_redirection(&self) -> bool
Check if status is within 300-399.
pub fn is_client_error(&self) -> bool
[src]
pub fn is_client_error(&self) -> bool
Check if status is within 400-499.
pub fn is_server_error(&self) -> bool
[src]
pub fn is_server_error(&self) -> bool
Check if status is within 500-599.
impl StatusCode
[src]
impl StatusCode
pub const CONTINUE: StatusCode
CONTINUE: StatusCode = StatusCode(100)
100 Continue [RFC7231, Section 6.2.1]
pub const SWITCHING_PROTOCOLS: StatusCode
SWITCHING_PROTOCOLS: StatusCode = StatusCode(101)
101 Switching Protocols [RFC7231, Section 6.2.2]
pub const PROCESSING: StatusCode
PROCESSING: StatusCode = StatusCode(102)
102 Processing [RFC2518]
pub const OK: StatusCode
OK: StatusCode = StatusCode(200)
200 OK [RFC7231, Section 6.3.1]
pub const CREATED: StatusCode
CREATED: StatusCode = StatusCode(201)
201 Created [RFC7231, Section 6.3.2]
pub const ACCEPTED: StatusCode
ACCEPTED: StatusCode = StatusCode(202)
202 Accepted [RFC7231, Section 6.3.3]
pub const NON_AUTHORITATIVE_INFORMATION: StatusCode
NON_AUTHORITATIVE_INFORMATION: StatusCode = StatusCode(203)
203 Non-Authoritative Information [RFC7231, Section 6.3.4]
pub const NO_CONTENT: StatusCode
NO_CONTENT: StatusCode = StatusCode(204)
204 No Content [RFC7231, Section 6.3.5]
pub const RESET_CONTENT: StatusCode
RESET_CONTENT: StatusCode = StatusCode(205)
205 Reset Content [RFC7231, Section 6.3.6]
pub const PARTIAL_CONTENT: StatusCode
PARTIAL_CONTENT: StatusCode = StatusCode(206)
206 Partial Content [RFC7233, Section 4.1]
pub const MULTI_STATUS: StatusCode
MULTI_STATUS: StatusCode = StatusCode(207)
207 Multi-Status [RFC4918]
pub const ALREADY_REPORTED: StatusCode
ALREADY_REPORTED: StatusCode = StatusCode(208)
208 Already Reported [RFC5842]
pub const IM_USED: StatusCode
IM_USED: StatusCode = StatusCode(226)
226 IM Used [RFC3229]
pub const MULTIPLE_CHOICES: StatusCode
MULTIPLE_CHOICES: StatusCode = StatusCode(300)
300 Multiple Choices [RFC7231, Section 6.4.1]
pub const MOVED_PERMANENTLY: StatusCode
MOVED_PERMANENTLY: StatusCode = StatusCode(301)
301 Moved Permanently [RFC7231, Section 6.4.2]
pub const FOUND: StatusCode
FOUND: StatusCode = StatusCode(302)
302 Found [RFC7231, Section 6.4.3]
pub const SEE_OTHER: StatusCode
SEE_OTHER: StatusCode = StatusCode(303)
303 See Other [RFC7231, Section 6.4.4]
pub const NOT_MODIFIED: StatusCode
NOT_MODIFIED: StatusCode = StatusCode(304)
304 Not Modified [RFC7232, Section 4.1]
pub const USE_PROXY: StatusCode
USE_PROXY: StatusCode = StatusCode(305)
305 Use Proxy [RFC7231, Section 6.4.5]
pub const TEMPORARY_REDIRECT: StatusCode
TEMPORARY_REDIRECT: StatusCode = StatusCode(307)
307 Temporary Redirect [RFC7231, Section 6.4.7]
pub const PERMANENT_REDIRECT: StatusCode
PERMANENT_REDIRECT: StatusCode = StatusCode(308)
308 Permanent Redirect [RFC7238]
pub const BAD_REQUEST: StatusCode
BAD_REQUEST: StatusCode = StatusCode(400)
400 Bad Request [RFC7231, Section 6.5.1]
pub const UNAUTHORIZED: StatusCode
UNAUTHORIZED: StatusCode = StatusCode(401)
401 Unauthorized [RFC7235, Section 3.1]
pub const PAYMENT_REQUIRED: StatusCode
PAYMENT_REQUIRED: StatusCode = StatusCode(402)
402 Payment Required [RFC7231, Section 6.5.2]
pub const FORBIDDEN: StatusCode
FORBIDDEN: StatusCode = StatusCode(403)
403 Forbidden [RFC7231, Section 6.5.3]
pub const NOT_FOUND: StatusCode
NOT_FOUND: StatusCode = StatusCode(404)
404 Not Found [RFC7231, Section 6.5.4]
pub const METHOD_NOT_ALLOWED: StatusCode
METHOD_NOT_ALLOWED: StatusCode = StatusCode(405)
405 Method Not Allowed [RFC7231, Section 6.5.5]
pub const NOT_ACCEPTABLE: StatusCode
NOT_ACCEPTABLE: StatusCode = StatusCode(406)
406 Not Acceptable [RFC7231, Section 6.5.6]
pub const PROXY_AUTHENTICATION_REQUIRED: StatusCode
PROXY_AUTHENTICATION_REQUIRED: StatusCode = StatusCode(407)
407 Proxy Authentication Required [RFC7235, Section 3.2]
pub const REQUEST_TIMEOUT: StatusCode
REQUEST_TIMEOUT: StatusCode = StatusCode(408)
408 Request Timeout [RFC7231, Section 6.5.7]
pub const CONFLICT: StatusCode
CONFLICT: StatusCode = StatusCode(409)
409 Conflict [RFC7231, Section 6.5.8]
pub const GONE: StatusCode
GONE: StatusCode = StatusCode(410)
410 Gone [RFC7231, Section 6.5.9]
pub const LENGTH_REQUIRED: StatusCode
LENGTH_REQUIRED: StatusCode = StatusCode(411)
411 Length Required [RFC7231, Section 6.5.10]
pub const PRECONDITION_FAILED: StatusCode
PRECONDITION_FAILED: StatusCode = StatusCode(412)
412 Precondition Failed [RFC7232, Section 4.2]
pub const PAYLOAD_TOO_LARGE: StatusCode
PAYLOAD_TOO_LARGE: StatusCode = StatusCode(413)
413 Payload Too Large [RFC7231, Section 6.5.11]
pub const URI_TOO_LONG: StatusCode
URI_TOO_LONG: StatusCode = StatusCode(414)
414 URI Too Long [RFC7231, Section 6.5.12]
pub const UNSUPPORTED_MEDIA_TYPE: StatusCode
UNSUPPORTED_MEDIA_TYPE: StatusCode = StatusCode(415)
415 Unsupported Media Type [RFC7231, Section 6.5.13]
pub const RANGE_NOT_SATISFIABLE: StatusCode
RANGE_NOT_SATISFIABLE: StatusCode = StatusCode(416)
416 Range Not Satisfiable [RFC7233, Section 4.4]
pub const EXPECTATION_FAILED: StatusCode
EXPECTATION_FAILED: StatusCode = StatusCode(417)
417 Expectation Failed [RFC7231, Section 6.5.14]
pub const IM_A_TEAPOT: StatusCode
IM_A_TEAPOT: StatusCode = StatusCode(418)
418 I'm a teapot [curiously not registered by IANA but RFC2324]
pub const MISDIRECTED_REQUEST: StatusCode
MISDIRECTED_REQUEST: StatusCode = StatusCode(421)
421 Misdirected Request RFC7540, Section 9.1.2
pub const UNPROCESSABLE_ENTITY: StatusCode
UNPROCESSABLE_ENTITY: StatusCode = StatusCode(422)
422 Unprocessable Entity [RFC4918]
pub const LOCKED: StatusCode
LOCKED: StatusCode = StatusCode(423)
423 Locked [RFC4918]
pub const FAILED_DEPENDENCY: StatusCode
FAILED_DEPENDENCY: StatusCode = StatusCode(424)
424 Failed Dependency [RFC4918]
pub const UPGRADE_REQUIRED: StatusCode
UPGRADE_REQUIRED: StatusCode = StatusCode(426)
426 Upgrade Required [RFC7231, Section 6.5.15]
pub const PRECONDITION_REQUIRED: StatusCode
PRECONDITION_REQUIRED: StatusCode = StatusCode(428)
428 Precondition Required [RFC6585]
pub const TOO_MANY_REQUESTS: StatusCode
TOO_MANY_REQUESTS: StatusCode = StatusCode(429)
429 Too Many Requests [RFC6585]
pub const REQUEST_HEADER_FIELDS_TOO_LARGE: StatusCode
REQUEST_HEADER_FIELDS_TOO_LARGE: StatusCode = StatusCode(431)
431 Request Header Fields Too Large [RFC6585]
pub const UNAVAILABLE_FOR_LEGAL_REASONS: StatusCode
UNAVAILABLE_FOR_LEGAL_REASONS: StatusCode = StatusCode(451)
451 Unavailable For Legal Reasons [RFC7725]
pub const INTERNAL_SERVER_ERROR: StatusCode
INTERNAL_SERVER_ERROR: StatusCode = StatusCode(500)
500 Internal Server Error [RFC7231, Section 6.6.1]
pub const NOT_IMPLEMENTED: StatusCode
NOT_IMPLEMENTED: StatusCode = StatusCode(501)
501 Not Implemented [RFC7231, Section 6.6.2]
pub const BAD_GATEWAY: StatusCode
BAD_GATEWAY: StatusCode = StatusCode(502)
502 Bad Gateway [RFC7231, Section 6.6.3]
pub const SERVICE_UNAVAILABLE: StatusCode
SERVICE_UNAVAILABLE: StatusCode = StatusCode(503)
503 Service Unavailable [RFC7231, Section 6.6.4]
pub const GATEWAY_TIMEOUT: StatusCode
GATEWAY_TIMEOUT: StatusCode = StatusCode(504)
504 Gateway Timeout [RFC7231, Section 6.6.5]
pub const HTTP_VERSION_NOT_SUPPORTED: StatusCode
HTTP_VERSION_NOT_SUPPORTED: StatusCode = StatusCode(505)
505 HTTP Version Not Supported [RFC7231, Section 6.6.6]
pub const VARIANT_ALSO_NEGOTIATES: StatusCode
VARIANT_ALSO_NEGOTIATES: StatusCode = StatusCode(506)
506 Variant Also Negotiates [RFC2295]
pub const INSUFFICIENT_STORAGE: StatusCode
INSUFFICIENT_STORAGE: StatusCode = StatusCode(507)
507 Insufficient Storage [RFC4918]
pub const LOOP_DETECTED: StatusCode
LOOP_DETECTED: StatusCode = StatusCode(508)
508 Loop Detected [RFC5842]
pub const NOT_EXTENDED: StatusCode
NOT_EXTENDED: StatusCode = StatusCode(510)
510 Not Extended [RFC2774]
pub const NETWORK_AUTHENTICATION_REQUIRED: StatusCode
NETWORK_AUTHENTICATION_REQUIRED: StatusCode = StatusCode(511)
511 Network Authentication Required [RFC6585]
Trait Implementations
impl Default for StatusCode
[src]
impl Default for StatusCode
fn default() -> StatusCode
[src]
fn default() -> StatusCode
Returns the "default value" for a type. Read more
impl Eq for StatusCode
[src]
impl Eq for StatusCode
impl PartialEq<StatusCode> for StatusCode
[src]
impl PartialEq<StatusCode> for StatusCode
fn eq(&self, other: &StatusCode) -> bool
[src]
fn eq(&self, other: &StatusCode) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &StatusCode) -> bool
[src]
fn ne(&self, other: &StatusCode) -> bool
This method tests for !=
.
impl PartialEq<StatusCode> for u16
[src]
impl PartialEq<StatusCode> for u16
fn eq(&self, other: &StatusCode) -> bool
[src]
fn eq(&self, other: &StatusCode) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl PartialEq<u16> for StatusCode
[src]
impl PartialEq<u16> for StatusCode
fn eq(&self, other: &u16) -> bool
[src]
fn eq(&self, other: &u16) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl Hash for StatusCode
[src]
impl Hash for StatusCode
fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
[src]
fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl FromStr for StatusCode
[src]
impl FromStr for StatusCode
type Err = InvalidStatusCode
The associated error which can be returned from parsing.
fn from_str(s: &str) -> Result<StatusCode, InvalidStatusCode>
[src]
fn from_str(s: &str) -> Result<StatusCode, InvalidStatusCode>
Parses a string s
to return a value of this type. Read more
impl Ord for StatusCode
[src]
impl Ord for StatusCode
fn cmp(&self, other: &StatusCode) -> Ordering
[src]
fn cmp(&self, other: &StatusCode) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl PartialOrd<StatusCode> for StatusCode
[src]
impl PartialOrd<StatusCode> for StatusCode
fn partial_cmp(&self, other: &StatusCode) -> Option<Ordering>
[src]
fn partial_cmp(&self, other: &StatusCode) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
fn lt(&self, other: &StatusCode) -> bool
[src]
fn lt(&self, other: &StatusCode) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &StatusCode) -> bool
[src]
fn le(&self, other: &StatusCode) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
fn gt(&self, other: &StatusCode) -> bool
[src]
fn gt(&self, other: &StatusCode) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &StatusCode) -> bool
[src]
fn ge(&self, other: &StatusCode) -> bool
This method tests greater than or equal to (for self
and other
) and is used by the >=
operator. Read more
impl Display for StatusCode
[src]
impl Display for StatusCode
Formats the status code, including the canonical reason.
Example
assert_eq!(format!("{}", StatusCode::OK), "200 OK");
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
[src]
fn fmt(&self, f: &mut Formatter) -> Result<(), Error>
Formats the value using the given formatter. Read more
impl From<StatusCode> for u16
[src]
impl From<StatusCode> for u16
fn from(status: StatusCode) -> u16
[src]
fn from(status: StatusCode) -> u16
Performs the conversion.
impl Copy for StatusCode
[src]
impl Copy for StatusCode
impl Clone for StatusCode
[src]
impl Clone for StatusCode
fn clone(&self) -> StatusCode
[src]
fn clone(&self) -> StatusCode
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl HttpTryFrom<StatusCode> for StatusCode
[src]
impl HttpTryFrom<StatusCode> for StatusCode
type Error = Error
Associated error with the conversion this implementation represents.
fn try_from(
t: StatusCode
) -> Result<StatusCode, <StatusCode as HttpTryFrom<StatusCode>>::Error>
[src]
fn try_from(
t: StatusCode
) -> Result<StatusCode, <StatusCode as HttpTryFrom<StatusCode>>::Error>
impl<'a> HttpTryFrom<&'a [u8]> for StatusCode
[src]
impl<'a> HttpTryFrom<&'a [u8]> for StatusCode
type Error = InvalidStatusCode
Associated error with the conversion this implementation represents.
fn try_from(
t: &'a [u8]
) -> Result<StatusCode, <StatusCode as HttpTryFrom<&'a [u8]>>::Error>
[src]
fn try_from(
t: &'a [u8]
) -> Result<StatusCode, <StatusCode as HttpTryFrom<&'a [u8]>>::Error>
impl<'a> HttpTryFrom<&'a str> for StatusCode
[src]
impl<'a> HttpTryFrom<&'a str> for StatusCode
type Error = InvalidStatusCode
Associated error with the conversion this implementation represents.
fn try_from(
t: &'a str
) -> Result<StatusCode, <StatusCode as HttpTryFrom<&'a str>>::Error>
[src]
fn try_from(
t: &'a str
) -> Result<StatusCode, <StatusCode as HttpTryFrom<&'a str>>::Error>
impl HttpTryFrom<u16> for StatusCode
[src]
impl HttpTryFrom<u16> for StatusCode
type Error = InvalidStatusCode
Associated error with the conversion this implementation represents.
fn try_from(
t: u16
) -> Result<StatusCode, <StatusCode as HttpTryFrom<u16>>::Error>
[src]
fn try_from(
t: u16
) -> Result<StatusCode, <StatusCode as HttpTryFrom<u16>>::Error>
impl Debug for StatusCode
[src]
impl Debug for StatusCode
Auto Trait Implementations
impl Send for StatusCode
impl Send for StatusCode
impl Sync for StatusCode
impl Sync for StatusCode