Struct poem::http::StatusCode[][src]

pub struct StatusCode(_);
Expand description

An HTTP status code (status-code in RFC 7230 et al.).

Constants are provided for known status codes, including those in the IANA HTTP Status Code Registry.

Status code values in the range 100-999 (inclusive) are supported by this type. Values in the range 100-599 are semantically classified by the most significant digit. See StatusCode::is_success, etc. Values above 599 are unclassified but allowed for legacy compatibility, though their use is discouraged. Applications may interpret such values as protocol errors.

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

Implementations

Converts a u16 to a status code.

The function validates the correctness of the supplied u16. It must be greater or equal to 100 and less than 1000.

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 and HTTP/3.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.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

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

Performs the conversion.

Performs the conversion.

The associated error which can be returned from parsing.

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

Feeds this value into the given Hasher. Read more

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

Consume itself and return Response.

Wrap an impl IntoResponse to add a header. Read more

Wrap an impl IntoResponse to set a status code. Read more

Wrap an impl IntoResponse to set a body. Read more

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

Restrict a value to a certain interval. Read more

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

This method tests for !=.

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

This method tests for !=.

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts self into T using Into<T>. Read more

Converts self into a target type. Read more

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

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Performs the conversion.

Attaches the provided Context to this type, returning a WithContext wrapper. Read more

Attaches the current Context to this type, returning a WithContext wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Pipes by value. This is generally the method you want to use. Read more

Borrows self and passes that borrow into the pipe function. Read more

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Pipes a value into a function that cannot ordinarily be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a dereference into a function that cannot normally be called in suffix position. Read more

Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more

Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more

Pipes a mutable reference into a function that cannot ordinarily be called in suffix position. Read more

Should always be Self

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

Mutable access to the AsMut<R> view of a value. Read more

Immutable access to the Deref::Target of a value. Read more

Mutable access to the Deref::Target of a value. Read more

Calls .tap() only in debug builds, and is erased in release builds.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

Provides immutable access for inspection. Read more

Calls tap in debug builds, and does nothing in release builds.

Provides mutable access for modification. Read more

Calls tap_mut in debug builds, and does nothing in release builds.

Provides immutable access to the reference for inspection.

Calls tap_ref in debug builds, and does nothing in release builds.

Provides mutable access to the reference for modification.

Calls tap_ref_mut in debug builds, and does nothing in release builds.

Provides immutable access to the borrow for inspection. Read more

Calls tap_borrow in debug builds, and does nothing in release builds.

Provides mutable access to the borrow for modification.

Calls tap_borrow_mut in debug builds, and does nothing in release builds. Read more

Immutably dereferences self for inspection.

Calls tap_deref in debug builds, and does nothing in release builds.

Mutably dereferences self for modification.

Calls tap_deref_mut in debug builds, and does nothing in release builds. Read more

The resulting type after obtaining ownership.

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

Converts the given value to a String. Read more

Attempts to convert self into T using TryInto<T>. Read more

Attempts to convert self into a target type. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more