1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-27 17:22:57 +01:00

conditional response build

This commit is contained in:
Nikolay Kim 2017-10-29 14:51:02 -07:00
parent ce34eab832
commit a1b7d5995e

View File

@ -350,6 +350,15 @@ impl HttpResponseBuilder {
self
}
pub fn if_true<F>(&mut self, value: bool, f: F) -> &mut Self
where F: Fn(&mut HttpResponseBuilder) + 'static
{
if value {
f(self);
}
self
}
/// Set a body
pub fn body<B: Into<Body>>(&mut self, body: B) -> Result<HttpResponse, HttpError> {
let mut parts = self.parts.take().expect("cannot reuse response builder");