[][src]Struct hyper::StatusCode

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]

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());

Converts a &u8 to a status code

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);

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");

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"));

Check if status is within 100-199.

Check if status is within 200-299.

Check if status is within 300-399.

Check if status is within 400-499.

Check if status is within 500-599.

impl StatusCode
[src]

100 Continue [RFC7231, Section 6.2.1]

101 Switching Protocols [RFC7231, Section 6.2.2]

102 Processing [RFC2518]

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]

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]

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]

Trait Implementations

impl Clone for StatusCode
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Display for StatusCode
[src]

Formats the status code, including the canonical reason.

Example

assert_eq!(format!("{}", StatusCode::OK), "200 OK");

Formats the value using the given formatter. Read more

impl Copy for StatusCode
[src]

impl Ord for StatusCode
[src]

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

impl Default for StatusCode
[src]

Returns the "default value" for a type. Read more

impl Eq for StatusCode
[src]

impl Debug for StatusCode
[src]

Formats the value using the given formatter. Read more

impl PartialOrd<StatusCode> for StatusCode
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<'a> HttpTryFrom<&'a str> for StatusCode
[src]

Associated error with the conversion this implementation represents.

impl HttpTryFrom<u16> for StatusCode
[src]

Associated error with the conversion this implementation represents.

impl<'a> HttpTryFrom<&'a [u8]> for StatusCode
[src]

Associated error with the conversion this implementation represents.

impl<'a> HttpTryFrom<&'a StatusCode> for StatusCode
[src]

Associated error with the conversion this implementation represents.

impl HttpTryFrom<StatusCode> for StatusCode
[src]

Associated error with the conversion this implementation represents.

impl<'a> From<&'a StatusCode> for StatusCode
[src]

Performs the conversion.

impl Hash for StatusCode
[src]

Feeds this value into the given [Hasher]. Read more

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

impl PartialEq<u16> for StatusCode
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<StatusCode> for StatusCode
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl FromStr for StatusCode
[src]

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Auto Trait Implementations

impl Send for StatusCode

impl Sync for StatusCode

Blanket Implementations

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

Performs the conversion.

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

Converts the given value to a String. Read more

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

Creates owned data from borrowed data, usually by cloning. Read more

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

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T> From for T
[src]

Performs the conversion.

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.

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

Performs the conversion.

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

Immutably borrows from an owned value. Read more

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

Mutably borrows from an owned value. Read more

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.

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

Performs the conversion.

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

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

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

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

Compare self to key and return true if they are equal.

impl<T> Erased for T