[]Struct rocket::http::Status

pub struct Status {
    pub code: u16,
    pub reason: &'static str,
}

Structure representing an HTTP status: an integer code and a reason phrase.

Usage

Status classes should rarely be created directly. Instead, an associated constant should be used; one is declared for every status defined in the HTTP standard.

Example

A status of 200 OK can be instantiated via the Ok constant:

use rocket::http::Status;

let ok = Status::Ok;

A status of 404 Not Found can be instantiated via the NotFound constant:

use rocket::http::Status;

let not_found = Status::NotFound;

The code and phrase can be retrieved directly:

use rocket::http::Status;

let not_found = Status::NotFound;

assert_eq!(not_found.code, 404);
assert_eq!(not_found.reason, "Not Found");
assert_eq!(not_found.to_string(), "404 Not Found".to_string());

Fields

The HTTP status code associated with this status.

The HTTP reason phrase associated with this status.

Methods

impl Status

Creates a new Status with code and reason. This should be used only to construct non-standard HTTP statuses. Use an associated constant for standard statuses.

Example

Create a custom 299 Somewhat Successful status:

use rocket::http::Status;

let custom = Status::new(299, "Somewhat Successful");
assert_eq!(custom.to_string(), "299 Somewhat Successful".to_string());

Returns the class of a given status.

Example

use rocket::http::{Status, StatusClass};

let processing = Status::Processing;
assert_eq!(processing.class(), StatusClass::Informational);

let ok = Status::Ok;
assert_eq!(ok.class(), StatusClass::Success);

let see_other = Status::SeeOther;
assert_eq!(see_other.class(), StatusClass::Redirection);

let not_found = Status::NotFound;
assert_eq!(not_found.class(), StatusClass::ClientError);

let internal_error = Status::InternalServerError;
assert_eq!(internal_error.class(), StatusClass::ServerError);

let custom = Status::new(600, "Bizarre");
assert_eq!(custom.class(), StatusClass::Unknown);

Status with code 100 and reason Continue .

Status with code 101 and reason Switching Protocols .

Status with code 102 and reason Processing .

Status with code 200 and reason OK .

Status with code 201 and reason Created .

Status with code 202 and reason Accepted .

Status with code 203 and reason Non-Authoritative Information .

Status with code 204 and reason No Content .

Status with code 205 and reason Reset Content .

Status with code 206 and reason Partial Content .

Status with code 207 and reason Multi-Status .

Status with code 208 and reason Already Reported .

Status with code 226 and reason IM Used .

Status with code 300 and reason Multiple Choices .

Status with code 301 and reason Moved Permanently .

Status with code 302 and reason Found .

Status with code 303 and reason See Other .

Status with code 304 and reason Not Modified .

Status with code 305 and reason Use Proxy .

Status with code 307 and reason Temporary Redirect .

Status with code 308 and reason Permanent Redirect .

Status with code 400 and reason Bad Request .

Status with code 401 and reason Unauthorized .

Status with code 402 and reason Payment Required .

Status with code 403 and reason Forbidden .

Status with code 404 and reason Not Found .

Status with code 405 and reason Method Not Allowed .

Status with code 406 and reason Not Acceptable .

Status with code 407 and reason Proxy Authentication Required .

Status with code 408 and reason Request Timeout .

Status with code 409 and reason Conflict .

Status with code 410 and reason Gone .

Status with code 411 and reason Length Required .

Status with code 412 and reason Precondition Failed .

Status with code 413 and reason Payload Too Large .

Status with code 414 and reason URI Too Long .

Status with code 415 and reason Unsupported Media Type .

Status with code 416 and reason Range Not Satisfiable .

Status with code 417 and reason Expectation Failed .

Status with code 418 and reason I'm a teapot .

Status with code 421 and reason Misdirected Request .

Status with code 422 and reason Unprocessable Entity .

Status with code 423 and reason Locked .

Status with code 424 and reason Failed Dependency .

Status with code 426 and reason Upgrade Required .

Status with code 428 and reason Precondition Required .

Status with code 429 and reason Too Many Requests .

Status with code 431 and reason Request Header Fields Too Large .

Status with code 451 and reason Unavailable For Legal Reasons .

Status with code 500 and reason Internal Server Error .

Status with code 501 and reason Not Implemented .

Status with code 502 and reason Bad Gateway .

Status with code 503 and reason Service Unavailable .

Status with code 504 and reason Gateway Timeout .

Status with code 505 and reason HTTP Version Not Supported .

Status with code 506 and reason Variant Also Negotiates .

Status with code 507 and reason Insufficient Storage .

Status with code 508 and reason Loop Detected .

Status with code 510 and reason Not Extended .

Status with code 511 and reason Network Authentication Required .

Returns a Status given a standard status code code. If code is not a known status code, None is returned.

Example

Create a Status from a known code:

use rocket::http::Status;

let not_found = Status::from_code(404);
assert_eq!(not_found, Some(Status::NotFound));

Create a Status from an unknown code:

use rocket::http::Status;

let not_found = Status::from_code(600);
assert!(not_found.is_none());

Trait Implementations

impl PartialEq<Status> for Status

impl Clone for Status

Performs copy-assignment from source. Read more

impl Display for Status

impl Hash for Status

Feeds a slice of this type into the given [Hasher]. Read more

impl Eq for Status

impl Debug for Status

impl Copy for Status

impl<'r> Responder<'r> for Status
[src]

The response generated by Status depends on the status code itself. The table below summarizes the functionality:

Status Code Range Response
[400, 599] Forwards to catcher for given status.
100, [200, 205] Empty with status of self.
All others. Invalid. Errors to 500 catcher.

In short, a client or server error status codes will forward to the corresponding error catcher, a successful status code less than 206 or 100 responds with any empty body and the given status code, and all other status code emit an error message and forward to the 500 (internal server error) catcher.

Auto Trait Implementations

impl Send for Status

impl Sync for Status

Blanket Implementations

impl<T> From for T
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Typeable for T where
    T: Any

Get the TypeId of this object.

impl<T> IntoCollection for T

impl<T, I> AsResult for T where
    I: Input, 

impl<Q, K> Equivalent for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]