From a1b7d5995ead8fac1b27b2f1d2147606ade6a882 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sun, 29 Oct 2017 14:51:02 -0700 Subject: [PATCH] conditional response build --- src/httpresponse.rs | 9 +++++++++ 1 file changed, 9 insertions(+) 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");