Enum websocket::result::StatusCode [−][src]
An HTTP status code (status-code
in RFC 7230 et al.).
This enum contains all common status codes and an Unregistered
extension variant. It allows status codes in the range [0, 65535], as any
u16
integer may be used as a status code for XHR requests. It is
recommended to only use values between [100, 599], since only these are
defined as valid status codes with a status class by HTTP.
If you encounter a status code that you do not know how to deal with, you
should treat it as the x00
status code—e.g. for code 123, treat it as
100 (Continue). This can be achieved with
self.class().default_code()
:
let status = StatusCode::Unregistered(123); assert_eq!(status.class().default_code(), StatusCode::Continue);
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).
Variants
100 Continue [RFC7231, Section 6.2.1]
101 Switching Protocols [RFC7231, Section 6.2.2]
102 Processing [RFC2518]
200 OK [RFC7231, Section 6.3.1]
201 Created [RFC7231, Section 6.3.2]
202 Accepted [RFC7231, Section 6.3.3]
203 Non-Authoritative Information [RFC7231, Section 6.3.4]
204 No Content [RFC7231, Section 6.3.5]
205 Reset Content [RFC7231, Section 6.3.6]
206 Partial Content [RFC7233, Section 4.1]
207 Multi-Status [RFC4918]
208 Already Reported [RFC5842]
226 IM Used [RFC3229]
300 Multiple Choices [RFC7231, Section 6.4.1]
301 Moved Permanently [RFC7231, Section 6.4.2]
302 Found [RFC7231, Section 6.4.3]
303 See Other [RFC7231, Section 6.4.4]
304 Not Modified [RFC7232, Section 4.1]
305 Use Proxy [RFC7231, Section 6.4.5]
307 Temporary Redirect [RFC7231, Section 6.4.7]
308 Permanent Redirect [RFC7238]
400 Bad Request [RFC7231, Section 6.5.1]
401 Unauthorized [RFC7235, Section 3.1]
402 Payment Required [RFC7231, Section 6.5.2]
403 Forbidden [RFC7231, Section 6.5.3]
404 Not Found [RFC7231, Section 6.5.4]
405 Method Not Allowed [RFC7231, Section 6.5.5]
406 Not Acceptable [RFC7231, Section 6.5.6]
407 Proxy Authentication Required [RFC7235, Section 3.2]
408 Request Timeout [RFC7231, Section 6.5.7]
409 Conflict [RFC7231, Section 6.5.8]
410 Gone [RFC7231, Section 6.5.9]
411 Length Required [RFC7231, Section 6.5.10]
412 Precondition Failed [RFC7232, Section 4.2]
413 Payload Too Large [RFC7231, Section 6.5.11]
414 URI Too Long [RFC7231, Section 6.5.12]
415 Unsupported Media Type [RFC7231, Section 6.5.13]
416 Range Not Satisfiable [RFC7233, Section 4.4]
417 Expectation Failed [RFC7231, Section 6.5.14]
418 I’m a teapot [curiously, not registered by IANA, but RFC2324]
421 Misdirected Request RFC7540, Section 9.1.2
422 Unprocessable Entity [RFC4918]
423 Locked [RFC4918]
424 Failed Dependency [RFC4918]
426 Upgrade Required [RFC7231, Section 6.5.15]
428 Precondition Required [RFC6585]
429 Too Many Requests [RFC6585]
431 Request Header Fields Too Large [RFC6585]
451 Unavailable For Legal Reasons [RFC7725]
500 Internal Server Error [RFC7231, Section 6.6.1]
501 Not Implemented [RFC7231, Section 6.6.2]
502 Bad Gateway [RFC7231, Section 6.6.3]
503 Service Unavailable [RFC7231, Section 6.6.4]
504 Gateway Timeout [RFC7231, Section 6.6.5]
505 HTTP Version Not Supported [RFC7231, Section 6.6.6]
506 Variant Also Negotiates [RFC2295]
507 Insufficient Storage [RFC4918]
508 Loop Detected [RFC5842]
510 Not Extended [RFC2774]
511 Network Authentication Required [RFC6585]
Unregistered(u16)
A status code not in the IANA HTTP status code registry or very well known
Implementations
impl StatusCode
[src]
pub fn canonical_reason(&self) -> Option<&'static str>
[src]
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.
pub fn class(&self) -> StatusClass
[src]
Determine the class of a status code, based on its first digit.
pub fn is_informational(&self) -> bool
[src]
Check if class is Informational.
pub fn is_success(&self) -> bool
[src]
Check if class is Success.
pub fn is_redirection(&self) -> bool
[src]
Check if class is Redirection.
pub fn is_client_error(&self) -> bool
[src]
Check if class is ClientError.
pub fn is_server_error(&self) -> bool
[src]
Check if class is ServerError.
pub fn is_strange_status(&self) -> bool
[src]
Check if class is NoClass
Trait Implementations
impl Clone for StatusCode
[src]
pub fn clone(&self) -> StatusCode
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for StatusCode
[src]
impl Debug for StatusCode
[src]
impl Display for StatusCode
[src]
Formats the status code, including the canonical reason.
assert_eq!(format!("{}", ImATeapot), "418 I'm a teapot"); assert_eq!(format!("{}", Unregistered(123)), "123 <unknown status code>");
impl Eq for StatusCode
[src]
impl Hash for StatusCode
[src]
pub fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
[src]
__H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for StatusCode
[src]
pub fn cmp(&self, other: &StatusCode) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<StatusCode> for StatusCode
[src]
pub fn eq(&self, other: &StatusCode) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl PartialOrd<StatusCode> for StatusCode
[src]
pub fn partial_cmp(&self, other: &StatusCode) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
Auto Trait Implementations
impl RefUnwindSafe for StatusCode
impl Send for StatusCode
impl Sync for StatusCode
impl Unpin for StatusCode
impl UnwindSafe for StatusCode
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Typeable for T where
T: Any,
T: Any,