Enum hyper::status::StatusClass [-]  [+] [src]

pub enum StatusClass {
    Informational,
    Success,
    Redirection,
    ClientError,
    ServerError,
}

The class of an HTTP Status-Code.

RFC 2616, section 6.1.1 (Status Code and Reason Phrase):

The first digit of the Status-Code defines the class of response. The last two digits do not have any categorization role.

...

HTTP status codes are extensible. HTTP applications are not required to understand the meaning of all registered status codes, though such understanding is obviously desirable. However, applications MUST understand the class of any status code, as indicated by the first digit, and treat any unrecognized response as being equivalent to the x00 status code of that class, with the exception that an unrecognized response MUST NOT be cached. For example, if an unrecognized status code of 431 is received by the client, it can safely assume that there was something wrong with its request and treat the response as if it had received a 400 status code. In such cases, user agents SHOULD present to the user the entity returned with the response, since that entity is likely to include human- readable information which will explain the unusual status.

This can be used in cases where a status code’s meaning is unknown, also, to get the appropriate category of status.

For HTTP/2.0, the 1xx Informational class is invalid.

Variants

Informational

1xx: Informational - Request received, continuing process

Success

2xx: Success - The action was successfully received, understood, and accepted

Redirection

3xx: Redirection - Further action must be taken in order to complete the request

ClientError

4xx: Client Error - The request contains bad syntax or cannot be fulfilled

ServerError

5xx: Server Error - The server failed to fulfill an apparently valid request

Methods

impl StatusClass

fn default_code(&self) -> StatusCode

Get the default status code for the class.

This produces the x00 status code; thus, for ClientError (4xx), for example, this will produce BadRequest (400):

assert_eq!(ClientError.default_code(), BadRequest);

The use for this is outlined in RFC 2616, section 6.1.1 (Status Code and Reason Phrase):

HTTP status codes are extensible. HTTP applications are not required to understand the meaning of all registered status codes, though such understanding is obviously desirable. However, applications MUST understand the class of any status code, as indicated by the first digit, and treat any unrecognized response as being equivalent to the x00 status code of that class, with the exception that an unrecognized response MUST NOT be cached. For example, if an unrecognized status code of 431 is received by the client, it can safely assume that there was something wrong with its request and treat the response as if it had received a 400 status code. In such cases, user agents SHOULD present to the user the entity returned with the response, since that entity is likely to include human- readable information which will explain the unusual status.

This is demonstrated thusly (I’ll use 432 rather than 431 as 431 is now in use):

// Suppose we have received this status code.
let status = Code432;

// Uh oh! Don’t know what to do with it.
// Let’s fall back to the default:
let status = status.class().default_code();

// And look! That is 400 Bad Request.
assert_eq!(status, BadRequest);
// So now let’s treat it as that.

Trait Implementations

impl ToPrimitive for StatusClass

fn to_i64(&self) -> Option<i64>

fn to_u64(&self) -> Option<u64>

fn to_int(&self) -> Option<isize>

fn to_i8(&self) -> Option<i8>

fn to_i16(&self) -> Option<i16>

fn to_i32(&self) -> Option<i32>

fn to_uint(&self) -> Option<usize>

fn to_u8(&self) -> Option<u8>

fn to_u16(&self) -> Option<u16>

fn to_u32(&self) -> Option<u32>

fn to_f32(&self) -> Option<f32>

fn to_f64(&self) -> Option<f64>

Derived Implementations

impl Copy for StatusClass

impl Ord for StatusClass

fn cmp(&self, __arg_0: &StatusClass) -> Ordering

impl PartialOrd for StatusClass

fn partial_cmp(&self, __arg_0: &StatusClass) -> Option<Ordering>

fn lt(&self, __arg_0: &StatusClass) -> bool

fn le(&self, __arg_0: &StatusClass) -> bool

fn gt(&self, __arg_0: &StatusClass) -> bool

fn ge(&self, __arg_0: &StatusClass) -> bool

impl Eq for StatusClass

fn assert_receiver_is_total_eq(&self)

impl PartialEq for StatusClass

fn eq(&self, __arg_0: &StatusClass) -> bool

fn ne(&self, __arg_0: &StatusClass) -> bool

impl Clone for StatusClass

fn clone(&self) -> StatusClass

fn clone_from(&mut self, source: &Self)