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); + } }