diff --git a/src/httpresponse.rs b/src/httpresponse.rs index 6dc7ab7d8..dcc45bcd7 100644 --- a/src/httpresponse.rs +++ b/src/httpresponse.rs @@ -350,6 +350,15 @@ impl HttpResponseBuilder { self } + pub fn if_true(&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>(&mut self, body: B) -> Result { let mut parts = self.parts.take().expect("cannot reuse response builder");