diff --git a/awc/CHANGES.md b/awc/CHANGES.md index 6e4720359..9ca5b22d1 100644 --- a/awc/CHANGES.md +++ b/awc/CHANGES.md @@ -7,6 +7,13 @@ * Added `Deref` for `ClientRequest`. +* Export `MessageBody` type + + +### Changed + +* `ClientResponse::body()` does not consume response object. + ## [0.1.0-alpha.2] - 2019-03-29 diff --git a/awc/Cargo.toml b/awc/Cargo.toml index c2cc9e7f0..ef9143ec2 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "awc" -version = "0.1.0-alpha.2" +version = "0.1.0-alpha.3" authors = ["Nikolay Kim "] description = "Actix http client." readme = "README.md" diff --git a/awc/src/lib.rs b/awc/src/lib.rs index ff1fb3fef..e2c04dbb8 100644 --- a/awc/src/lib.rs +++ b/awc/src/lib.rs @@ -39,7 +39,7 @@ pub mod ws; pub use self::builder::ClientBuilder; pub use self::request::ClientRequest; -pub use self::response::ClientResponse; +pub use self::response::{ClientResponse, MessageBody}; use self::connect::{Connect, ConnectorWrapper}; diff --git a/awc/src/response.rs b/awc/src/response.rs index 038a9a330..2548d7197 100644 --- a/awc/src/response.rs +++ b/awc/src/response.rs @@ -105,7 +105,7 @@ where S: Stream + 'static, { /// Load http response's body. - pub fn body(self) -> MessageBody { + pub fn body(&mut self) -> MessageBody { MessageBody::new(self) } } @@ -137,7 +137,7 @@ impl fmt::Debug for ClientResponse { pub struct MessageBody { limit: usize, length: Option, - stream: Option>, + stream: Option>, err: Option, fut: Option>>, } @@ -147,7 +147,7 @@ where S: Stream + 'static, { /// Create `MessageBody` for request. - pub fn new(res: ClientResponse) -> MessageBody { + pub fn new(res: &mut ClientResponse) -> MessageBody { let mut len = None; if let Some(l) = res.headers().get(CONTENT_LENGTH) { if let Ok(s) = l.to_str() { @@ -164,7 +164,7 @@ where MessageBody { limit: 262_144, length: len, - stream: Some(res), + stream: Some(res.take_payload()), fut: None, err: None, } @@ -239,19 +239,20 @@ mod tests { #[test] fn test_body() { - let req = TestResponse::with_header(header::CONTENT_LENGTH, "xxxx").finish(); + let mut req = TestResponse::with_header(header::CONTENT_LENGTH, "xxxx").finish(); match req.body().poll().err().unwrap() { PayloadError::UnknownLength => (), _ => unreachable!("error"), } - let req = TestResponse::with_header(header::CONTENT_LENGTH, "1000000").finish(); + let mut req = + TestResponse::with_header(header::CONTENT_LENGTH, "1000000").finish(); match req.body().poll().err().unwrap() { PayloadError::Overflow => (), _ => unreachable!("error"), } - let req = TestResponse::default() + let mut req = TestResponse::default() .set_payload(Bytes::from_static(b"test")) .finish(); match req.body().poll().ok().unwrap() { @@ -259,7 +260,7 @@ mod tests { _ => unreachable!("error"), } - let req = TestResponse::default() + let mut req = TestResponse::default() .set_payload(Bytes::from_static(b"11111111111111")) .finish(); match req.body().limit(5).poll().err().unwrap() {