make body return borrowed decoder

This commit is contained in:
Ashley Mannix
2017-08-19 16:32:00 +10:00
parent e2fa97254e
commit 2cb70c872a
7 changed files with 69 additions and 23 deletions

View File

@@ -9,6 +9,8 @@ extern crate libflate;
#[macro_use]
mod support;
use std::mem;
use reqwest::unstable::async::{Client, Decoder};
use futures::{Future, Stream};
use tokio_core::reactor::Core;
use std::io::Write;
@@ -59,12 +61,15 @@ fn test_gzip(response_size: usize, chunk_size: usize) {
let mut core = Core::new().unwrap();
let client = reqwest::unstable::async::Client::new(&core.handle()).unwrap();
let client = Client::new(&core.handle()).unwrap();
let res_future = client.get(&format!("http://{}/gzip", server.addr()))
.unwrap()
.send()
.and_then(|mut res| res.body().concat2())
.and_then(|mut res| {
let body = mem::replace(res.body_mut(), Decoder::empty());
body.concat2()
})
.and_then(|buf| {
let body = ::std::str::from_utf8(&buf).unwrap();