1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-12 10:19:36 +00: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");