mirror of https://github.com/rwf2/Rocket.git
Add a 'status::NotFound' responder.
This commit is contained in:
parent
a61977befc
commit
462f1f9298
|
@ -48,6 +48,8 @@ This release includes the following new features:
|
|||
* Log coloring is disabled when `stdout` is not a TTY.
|
||||
* [`FromForm`] is implemented for `Option<T: FromForm>`, `Result<T: FromForm,
|
||||
T::Error>`.
|
||||
* The [`NotFound`] responder was added for simple **404** response
|
||||
construction.
|
||||
|
||||
[Fairings]: #FIXME
|
||||
[Native TLS support]: #FIXME
|
||||
|
@ -73,6 +75,7 @@ This release includes the following new features:
|
|||
[`Config::get_datetime()`]: https://api.rocket.rs/rocket/struct.Config.html#method.get_datetime
|
||||
[`LenientForm`]: https://api.rocket.rs/rocket/request/struct.LenientForm.html
|
||||
[configuration parameters]: https://api.rocket.rs/rocket/config/index.html#environment-variables
|
||||
[`NotFound`]: https://api.rocket.rs/rocket/response/status/struct.NotFound.html
|
||||
|
||||
## Breaking Changes
|
||||
|
||||
|
|
|
@ -155,6 +155,30 @@ impl Responder<'static> for Reset {
|
|||
}
|
||||
}
|
||||
|
||||
/// Sets the status of the response to 404 (Not Found).
|
||||
///
|
||||
/// The remainder of the response is delegated to the wrapped `Responder`.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use rocket::response::status;
|
||||
///
|
||||
/// # #[allow(unused_variables)]
|
||||
/// let response = status::NotFound("Sorry, I couldn't find it!");
|
||||
/// ```
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct NotFound<R>(pub R);
|
||||
|
||||
/// Sets the status code of the response to 404 Not Found.
|
||||
impl<'r, R: Responder<'r>> Responder<'r> for NotFound<R> {
|
||||
fn respond_to(self, req: &Request) -> Result<Response<'r>, Status> {
|
||||
Response::build_from(self.0.respond_to(req)?)
|
||||
.status(Status::NotFound)
|
||||
.ok()
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a response with the given status code and underyling responder.
|
||||
///
|
||||
/// # Example
|
||||
|
|
Loading…
Reference in New Issue