1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 09:42:40 +01:00

add from HttpRequest to a HttpRequestBuilder

This commit is contained in:
Nikolay Kim 2018-03-30 14:30:24 -07:00
parent 3ccaa04575
commit b16419348e

View File

@ -87,6 +87,20 @@ impl HttpResponse {
resp 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 /// The source `error` for this response
#[inline] #[inline]
pub fn error(&self) -> Option<&Error> { pub fn error(&self) -> Option<&Error> {
@ -1074,4 +1088,14 @@ mod tests {
assert_eq!(resp.status(), StatusCode::OK); assert_eq!(resp.status(), StatusCode::OK);
assert_eq!(resp.body().binary().unwrap(), &Binary::from(BytesMut::from("test"))); 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);
}
} }