From b16419348e0fc85dc82455e0dfedc80106bf3791 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 30 Mar 2018 14:30:24 -0700 Subject: [PATCH] add from HttpRequest to a HttpRequestBuilder --- src/httpresponse.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/httpresponse.rs b/src/httpresponse.rs index df2271002..31235aab6 100644 --- a/src/httpresponse.rs +++ b/src/httpresponse.rs @@ -87,6 +87,20 @@ impl HttpResponse { resp } + /// Convert `HttpResponse` to a `HttpResponseBuilder` + #[inline] + pub fn into_builder(mut self) -> HttpResponseBuilder { + let response = self.0.take(); + let pool = Some(Rc::clone(&self.1)); + + HttpResponseBuilder { + response, + pool, + err: None, + cookies: None, // TODO: convert set-cookie headers + } + } + /// The source `error` for this response #[inline] pub fn error(&self) -> Option<&Error> { @@ -1074,4 +1088,14 @@ mod tests { assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.body().binary().unwrap(), &Binary::from(BytesMut::from("test"))); } + + #[test] + fn test_into_builder() { + let resp: HttpResponse = "test".into(); + assert_eq!(resp.status(), StatusCode::OK); + + let mut builder = resp.into_builder(); + let resp = builder.status(StatusCode::BAD_REQUEST).finish().unwrap(); + assert_eq!(resp.status(), StatusCode::BAD_REQUEST); + } }