Struct actix_web::StatusCode [] [src]

pub struct StatusCode(_);

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

This type contains constructor functions for all common status codes. 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.

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]

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

[src]

Converts a &[u8] to a status code

[src]

Returns the u16 corresponding to this StatusCode.

Example

let status = http::StatusCode::OK;
assert_eq!(status.as_u16(), 200);

[src]

Check if status is within 100-199.

[src]

Check if status is within 200-299.

[src]

Check if status is within 300-399.

[src]

Check if status is within 400-499.

[src]

Check if status is within 500-599.

impl StatusCode
[src]

CONTINUE: StatusCode = StatusCode(100)

SWITCHING_PROTOCOLS: StatusCode = StatusCode(101)

PROCESSING: StatusCode = StatusCode(102)

OK: StatusCode = StatusCode(200)

CREATED: StatusCode = StatusCode(201)

ACCEPTED: StatusCode = StatusCode(202)

NON_AUTHORITATIVE_INFORMATION: StatusCode = StatusCode(203)

NO_CONTENT: StatusCode = StatusCode(204)

RESET_CONTENT: StatusCode = StatusCode(205)

PARTIAL_CONTENT: StatusCode = StatusCode(206)

MULTI_STATUS: StatusCode = StatusCode(207)

ALREADY_REPORTED: StatusCode = StatusCode(208)

IM_USED: StatusCode = StatusCode(226)

MULTIPLE_CHOICES: StatusCode = StatusCode(300)

MOVED_PERMANENTLY: StatusCode = StatusCode(301)

FOUND: StatusCode = StatusCode(302)

SEE_OTHER: StatusCode = StatusCode(303)

NOT_MODIFIED: StatusCode = StatusCode(304)

USE_PROXY: StatusCode = StatusCode(305)

TEMPORARY_REDIRECT: StatusCode = StatusCode(307)

PERMANENT_REDIRECT: StatusCode = StatusCode(308)

BAD_REQUEST: StatusCode = StatusCode(400)

UNAUTHORIZED: StatusCode = StatusCode(401)

PAYMENT_REQUIRED: StatusCode = StatusCode(402)

FORBIDDEN: StatusCode = StatusCode(403)

NOT_FOUND: StatusCode = StatusCode(404)

METHOD_NOT_ALLOWED: StatusCode = StatusCode(405)

NOT_ACCEPTABLE: StatusCode = StatusCode(406)

PROXY_AUTHENTICATION_REQUIRED: StatusCode = StatusCode(407)

REQUEST_TIMEOUT: StatusCode = StatusCode(408)

CONFLICT: StatusCode = StatusCode(409)

GONE: StatusCode = StatusCode(410)

LENGTH_REQUIRED: StatusCode = StatusCode(411)

PRECONDITION_FAILED: StatusCode = StatusCode(412)

PAYLOAD_TOO_LARGE: StatusCode = StatusCode(413)

URI_TOO_LONG: StatusCode = StatusCode(414)

UNSUPPORTED_MEDIA_TYPE: StatusCode = StatusCode(415)

RANGE_NOT_SATISFIABLE: StatusCode = StatusCode(416)

EXPECTATION_FAILED: StatusCode = StatusCode(417)

IM_A_TEAPOT: StatusCode = StatusCode(418)

MISDIRECTED_REQUEST: StatusCode = StatusCode(421)

UNPROCESSABLE_ENTITY: StatusCode = StatusCode(422)

LOCKED: StatusCode = StatusCode(423)

FAILED_DEPENDENCY: StatusCode = StatusCode(424)

UPGRADE_REQUIRED: StatusCode = StatusCode(426)

PRECONDITION_REQUIRED: StatusCode = StatusCode(428)

TOO_MANY_REQUESTS: StatusCode = StatusCode(429)

REQUEST_HEADER_FIELDS_TOO_LARGE: StatusCode = StatusCode(431)
UNAVAILABLE_FOR_LEGAL_REASONS: StatusCode = StatusCode(451)

INTERNAL_SERVER_ERROR: StatusCode = StatusCode(500)

NOT_IMPLEMENTED: StatusCode = StatusCode(501)

BAD_GATEWAY: StatusCode = StatusCode(502)

SERVICE_UNAVAILABLE: StatusCode = StatusCode(503)

GATEWAY_TIMEOUT: StatusCode = StatusCode(504)

HTTP_VERSION_NOT_SUPPORTED: StatusCode = StatusCode(505)

VARIANT_ALSO_NEGOTIATES: StatusCode = StatusCode(506)

INSUFFICIENT_STORAGE: StatusCode = StatusCode(507)

LOOP_DETECTED: StatusCode = StatusCode(508)

NOT_EXTENDED: StatusCode = StatusCode(510)

NETWORK_AUTHENTICATION_REQUIRED: StatusCode = StatusCode(511)

[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.

impl StatusCode
[src]

[src]

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.

Trait Implementations

impl Ord for StatusCode
[src]

[src]

impl Copy for StatusCode
[src]

impl Hash for StatusCode
[src]

[src]

impl Clone for StatusCode
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl PartialEq<StatusCode> for StatusCode
[src]

[src]

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

[src]

This method tests for !=.

impl FromStr for StatusCode
[src]

impl Debug for StatusCode
[src]

[src]

Formats the value using the given formatter.

impl Default for StatusCode
[src]

[src]

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

impl Eq for StatusCode
[src]

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

Associated error with the conversion this implementation represents.

[src]

impl HttpTryFrom<StatusCode> for StatusCode
[src]

Associated error with the conversion this implementation represents.

[src]

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

Associated error with the conversion this implementation represents.

[src]

impl HttpTryFrom<u16> for StatusCode
[src]

Associated error with the conversion this implementation represents.

[src]

impl Display for StatusCode
[src]

Formats the status code, including the canonical reason.

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

[src]

Formats the value using the given formatter. Read more

impl PartialOrd<StatusCode> for StatusCode
[src]

[src]

[src]

[src]

[src]

[src]