mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-30 10:42:55 +01:00
do not consume response
This commit is contained in:
parent
6c195d8521
commit
c5fa6c1abe
@ -7,6 +7,13 @@
|
|||||||
|
|
||||||
* Added `Deref<Target = RequestHead>` for `ClientRequest`.
|
* Added `Deref<Target = RequestHead>` for `ClientRequest`.
|
||||||
|
|
||||||
|
* Export `MessageBody` type
|
||||||
|
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
* `ClientResponse::body()` does not consume response object.
|
||||||
|
|
||||||
|
|
||||||
## [0.1.0-alpha.2] - 2019-03-29
|
## [0.1.0-alpha.2] - 2019-03-29
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "awc"
|
name = "awc"
|
||||||
version = "0.1.0-alpha.2"
|
version = "0.1.0-alpha.3"
|
||||||
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
|
||||||
description = "Actix http client."
|
description = "Actix http client."
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -39,7 +39,7 @@ pub mod ws;
|
|||||||
|
|
||||||
pub use self::builder::ClientBuilder;
|
pub use self::builder::ClientBuilder;
|
||||||
pub use self::request::ClientRequest;
|
pub use self::request::ClientRequest;
|
||||||
pub use self::response::ClientResponse;
|
pub use self::response::{ClientResponse, MessageBody};
|
||||||
|
|
||||||
use self::connect::{Connect, ConnectorWrapper};
|
use self::connect::{Connect, ConnectorWrapper};
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ where
|
|||||||
S: Stream<Item = Bytes, Error = PayloadError> + 'static,
|
S: Stream<Item = Bytes, Error = PayloadError> + 'static,
|
||||||
{
|
{
|
||||||
/// Load http response's body.
|
/// Load http response's body.
|
||||||
pub fn body(self) -> MessageBody<S> {
|
pub fn body(&mut self) -> MessageBody<S> {
|
||||||
MessageBody::new(self)
|
MessageBody::new(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,7 +137,7 @@ impl<S> fmt::Debug for ClientResponse<S> {
|
|||||||
pub struct MessageBody<S> {
|
pub struct MessageBody<S> {
|
||||||
limit: usize,
|
limit: usize,
|
||||||
length: Option<usize>,
|
length: Option<usize>,
|
||||||
stream: Option<ClientResponse<S>>,
|
stream: Option<Payload<S>>,
|
||||||
err: Option<PayloadError>,
|
err: Option<PayloadError>,
|
||||||
fut: Option<Box<Future<Item = Bytes, Error = PayloadError>>>,
|
fut: Option<Box<Future<Item = Bytes, Error = PayloadError>>>,
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ where
|
|||||||
S: Stream<Item = Bytes, Error = PayloadError> + 'static,
|
S: Stream<Item = Bytes, Error = PayloadError> + 'static,
|
||||||
{
|
{
|
||||||
/// Create `MessageBody` for request.
|
/// Create `MessageBody` for request.
|
||||||
pub fn new(res: ClientResponse<S>) -> MessageBody<S> {
|
pub fn new(res: &mut ClientResponse<S>) -> MessageBody<S> {
|
||||||
let mut len = None;
|
let mut len = None;
|
||||||
if let Some(l) = res.headers().get(CONTENT_LENGTH) {
|
if let Some(l) = res.headers().get(CONTENT_LENGTH) {
|
||||||
if let Ok(s) = l.to_str() {
|
if let Ok(s) = l.to_str() {
|
||||||
@ -164,7 +164,7 @@ where
|
|||||||
MessageBody {
|
MessageBody {
|
||||||
limit: 262_144,
|
limit: 262_144,
|
||||||
length: len,
|
length: len,
|
||||||
stream: Some(res),
|
stream: Some(res.take_payload()),
|
||||||
fut: None,
|
fut: None,
|
||||||
err: None,
|
err: None,
|
||||||
}
|
}
|
||||||
@ -239,19 +239,20 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_body() {
|
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() {
|
match req.body().poll().err().unwrap() {
|
||||||
PayloadError::UnknownLength => (),
|
PayloadError::UnknownLength => (),
|
||||||
_ => unreachable!("error"),
|
_ => 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() {
|
match req.body().poll().err().unwrap() {
|
||||||
PayloadError::Overflow => (),
|
PayloadError::Overflow => (),
|
||||||
_ => unreachable!("error"),
|
_ => unreachable!("error"),
|
||||||
}
|
}
|
||||||
|
|
||||||
let req = TestResponse::default()
|
let mut req = TestResponse::default()
|
||||||
.set_payload(Bytes::from_static(b"test"))
|
.set_payload(Bytes::from_static(b"test"))
|
||||||
.finish();
|
.finish();
|
||||||
match req.body().poll().ok().unwrap() {
|
match req.body().poll().ok().unwrap() {
|
||||||
@ -259,7 +260,7 @@ mod tests {
|
|||||||
_ => unreachable!("error"),
|
_ => unreachable!("error"),
|
||||||
}
|
}
|
||||||
|
|
||||||
let req = TestResponse::default()
|
let mut req = TestResponse::default()
|
||||||
.set_payload(Bytes::from_static(b"11111111111111"))
|
.set_payload(Bytes::from_static(b"11111111111111"))
|
||||||
.finish();
|
.finish();
|
||||||
match req.body().limit(5).poll().err().unwrap() {
|
match req.body().limit(5).poll().err().unwrap() {
|
||||||
|
Loading…
Reference in New Issue
Block a user