mirror of
https://github.com/actix/actix-web.git
synced 2024-12-29 19:40:34 +00:00
conditional response build
This commit is contained in:
parent
ce34eab832
commit
a1b7d5995e
1 changed files with 9 additions and 0 deletions
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue