Struct Status
pub struct Status {
pub code: u16,
pub reason: &'static str,
}
Expand description
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§
§code: u16
The HTTP status code associated with this status.
reason: &'static str
The HTTP reason phrase associated with this status.
Implementations§
§impl Status
impl Status
pub const SwitchingProtocols: Status = _
pub const SwitchingProtocols: Status = _
Status
with code
101
and reason
Switching Protocols
.
pub const Processing: Status = _
pub const Processing: Status = _
Status
with code
102
and reason
Processing
.
pub const NonAuthoritativeInformation: Status = _
pub const NonAuthoritativeInformation: Status = _
Status
with code
203
and reason
Non-Authoritative Information
.
pub const ResetContent: Status = _
pub const ResetContent: Status = _
Status
with code
205
and reason
Reset Content
.
pub const PartialContent: Status = _
pub const PartialContent: Status = _
Status
with code
206
and reason
Partial Content
.
pub const MultiStatus: Status = _
pub const MultiStatus: Status = _
Status
with code
207
and reason
Multi-Status
.
pub const AlreadyReported: Status = _
pub const AlreadyReported: Status = _
Status
with code
208
and reason
Already Reported
.
pub const MultipleChoices: Status = _
pub const MultipleChoices: Status = _
Status
with code
300
and reason
Multiple Choices
.
pub const MovedPermanently: Status = _
pub const MovedPermanently: Status = _
Status
with code
301
and reason
Moved Permanently
.
pub const NotModified: Status = _
pub const NotModified: Status = _
Status
with code
304
and reason
Not Modified
.
pub const TemporaryRedirect: Status = _
pub const TemporaryRedirect: Status = _
Status
with code
307
and reason
Temporary Redirect
.
pub const PermanentRedirect: Status = _
pub const PermanentRedirect: Status = _
Status
with code
308
and reason
Permanent Redirect
.
pub const BadRequest: Status = _
pub const BadRequest: Status = _
Status
with code
400
and reason
Bad Request
.
Status
with code
401
and reason
Unauthorized
.
pub const PaymentRequired: Status = _
pub const PaymentRequired: Status = _
Status
with code
402
and reason
Payment Required
.
pub const MethodNotAllowed: Status = _
pub const MethodNotAllowed: Status = _
Status
with code
405
and reason
Method Not Allowed
.
pub const NotAcceptable: Status = _
pub const NotAcceptable: Status = _
Status
with code
406
and reason
Not Acceptable
.
pub const ProxyAuthenticationRequired: Status = _
pub const ProxyAuthenticationRequired: Status = _
Status
with code
407
and reason
Proxy Authentication Required
.
pub const RequestTimeout: Status = _
pub const RequestTimeout: Status = _
Status
with code
408
and reason
Request Timeout
.
pub const LengthRequired: Status = _
pub const LengthRequired: Status = _
Status
with code
411
and reason
Length Required
.
pub const PreconditionFailed: Status = _
pub const PreconditionFailed: Status = _
Status
with code
412
and reason
Precondition Failed
.
pub const PayloadTooLarge: Status = _
pub const PayloadTooLarge: Status = _
Status
with code
413
and reason
Payload Too Large
.
pub const UriTooLong: Status = _
pub const UriTooLong: Status = _
Status
with code
414
and reason
URI Too Long
.
pub const UnsupportedMediaType: Status = _
pub const UnsupportedMediaType: Status = _
Status
with code
415
and reason
Unsupported Media Type
.
pub const RangeNotSatisfiable: Status = _
pub const RangeNotSatisfiable: Status = _
Status
with code
416
and reason
Range Not Satisfiable
.
pub const ExpectationFailed: Status = _
pub const ExpectationFailed: Status = _
Status
with code
417
and reason
Expectation Failed
.
pub const MisdirectedRequest: Status = _
pub const MisdirectedRequest: Status = _
Status
with code
421
and reason
Misdirected Request
.
pub const UnprocessableEntity: Status = _
pub const UnprocessableEntity: Status = _
Status
with code
422
and reason
Unprocessable Entity
.
pub const FailedDependency: Status = _
pub const FailedDependency: Status = _
Status
with code
424
and reason
Failed Dependency
.
pub const UpgradeRequired: Status = _
pub const UpgradeRequired: Status = _
Status
with code
426
and reason
Upgrade Required
.
pub const PreconditionRequired: Status = _
pub const PreconditionRequired: Status = _
Status
with code
428
and reason
Precondition Required
.
pub const TooManyRequests: Status = _
pub const TooManyRequests: Status = _
Status
with code
429
and reason
Too Many Requests
.
pub const RequestHeaderFieldsTooLarge: Status = _
pub const RequestHeaderFieldsTooLarge: Status = _
Status
with code
431
and reason
Request Header Fields Too Large
.
Status
with code
451
and reason
Unavailable For Legal Reasons
.
pub const InternalServerError: Status = _
pub const InternalServerError: Status = _
Status
with code
500
and reason
Internal Server Error
.
pub const NotImplemented: Status = _
pub const NotImplemented: Status = _
Status
with code
501
and reason
Not Implemented
.
pub const BadGateway: Status = _
pub const BadGateway: Status = _
Status
with code
502
and reason
Bad Gateway
.
Status
with code
503
and reason
Service Unavailable
.
pub const GatewayTimeout: Status = _
pub const GatewayTimeout: Status = _
Status
with code
504
and reason
Gateway Timeout
.
pub const HttpVersionNotSupported: Status = _
pub const HttpVersionNotSupported: Status = _
Status
with code
505
and reason
HTTP Version Not Supported
.
pub const VariantAlsoNegotiates: Status = _
pub const VariantAlsoNegotiates: Status = _
Status
with code
506
and reason
Variant Also Negotiates
.
pub const InsufficientStorage: Status = _
pub const InsufficientStorage: Status = _
Status
with code
507
and reason
Insufficient Storage
.
pub const LoopDetected: Status = _
pub const LoopDetected: Status = _
Status
with code
508
and reason
Loop Detected
.
pub const NotExtended: Status = _
pub const NotExtended: Status = _
Status
with code
510
and reason
Not Extended
.
pub const NetworkAuthenticationRequired: Status = _
pub const NetworkAuthenticationRequired: Status = _
Status
with code
511
and reason
Network Authentication Required
.
pub fn new(code: u16, reason: &'static str) -> Status
pub fn new(code: u16, reason: &'static str) -> 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());
pub fn class(&self) -> StatusClass
pub fn class(&self) -> StatusClass
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);
pub fn from_code(code: u16) -> Option<Status>
pub fn from_code(code: u16) -> Option<Status>
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§
Source§impl<'r> Responder<'r> for Status
impl<'r> Responder<'r> for Status
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.
impl Copy for Status
impl Eq for Status
impl StructuralPartialEq for Status
Auto Trait Implementations§
impl Freeze for Status
impl RefUnwindSafe for Status
impl Send for Status
impl Sync for Status
impl Unpin for Status
impl UnwindSafe for Status
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.