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.
|
* Log coloring is disabled when `stdout` is not a TTY.
|
||||||
* [`FromForm`] is implemented for `Option<T: FromForm>`, `Result<T: FromForm,
|
* [`FromForm`] is implemented for `Option<T: FromForm>`, `Result<T: FromForm,
|
||||||
T::Error>`.
|
T::Error>`.
|
||||||
|
* The [`NotFound`] responder was added for simple **404** response
|
||||||
|
construction.
|
||||||
|
|
||||||
[Fairings]: #FIXME
|
[Fairings]: #FIXME
|
||||||
[Native TLS support]: #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
|
[`Config::get_datetime()`]: https://api.rocket.rs/rocket/struct.Config.html#method.get_datetime
|
||||||
[`LenientForm`]: https://api.rocket.rs/rocket/request/struct.LenientForm.html
|
[`LenientForm`]: https://api.rocket.rs/rocket/request/struct.LenientForm.html
|
||||||
[configuration parameters]: https://api.rocket.rs/rocket/config/index.html#environment-variables
|
[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
|
## 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.
|
/// Creates a response with the given status code and underyling responder.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
|
|
Loading…
Reference in New Issue