From 17ecdd63d23f1b6ee424f67a0ad0852d9125f1af Mon Sep 17 00:00:00 2001 From: Luca Bruno Date: Wed, 13 Mar 2019 15:20:18 +0100 Subject: [PATCH] httpresponse: add constructor for HttpResponseBuilder (#697) --- src/httpresponse.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/httpresponse.rs b/src/httpresponse.rs index 226c847f..48f7b4c2 100644 --- a/src/httpresponse.rs +++ b/src/httpresponse.rs @@ -48,10 +48,10 @@ impl HttpResponse { self.0.as_mut() } - /// Create http response builder with specific status. + /// Create a new HTTP response builder with specific status. #[inline] pub fn build(status: StatusCode) -> HttpResponseBuilder { - HttpResponsePool::get(status) + HttpResponseBuilder::new(status) } /// Create http response builder @@ -346,6 +346,12 @@ pub struct HttpResponseBuilder { } impl HttpResponseBuilder { + /// Create a new HTTP response builder with specific status. + #[inline] + pub fn new(status: StatusCode) -> HttpResponseBuilder { + HttpResponsePool::get(status) + } + /// Set HTTP status code of this response. #[inline] pub fn status(&mut self, status: StatusCode) -> &mut Self { @@ -1177,6 +1183,14 @@ mod tests { assert_eq!((v.name(), v.value()), ("cookie3", "val300")); } + #[test] + fn test_builder_new() { + let resp = HttpResponseBuilder::new(StatusCode::BAD_REQUEST) + .finish(); + assert_eq!(resp.status(), StatusCode::BAD_REQUEST); + } + + #[test] fn test_basic_builder() { let resp = HttpResponse::Ok()