Skip to content

Commit

Permalink
update client example
Browse files Browse the repository at this point in the history
  • Loading branch information
fafhrd91 committed Apr 11, 2019
1 parent 0eed9e5 commit 6420a2f
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions examples/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use actix_http::Error;
use actix_rt::System;
use bytes::BytesMut;
use futures::{future::lazy, Future, Stream};
use futures::{future::lazy, Future};

fn main() -> Result<(), Error> {
std::env::set_var("RUST_LOG", "actix_http=trace");
Expand All @@ -13,17 +12,14 @@ fn main() -> Result<(), Error> {
.header("User-Agent", "Actix-web")
.send() // <- Send http request
.from_err()
.and_then(|response| {
.and_then(|mut response| {
// <- server http response
println!("Response: {:?}", response);

// read response body
response
.body()
.from_err()
.fold(BytesMut::new(), move |mut acc, chunk| {
acc.extend_from_slice(&chunk);
Ok::<_, Error>(acc)
})
.map(|body| println!("Downloaded: {:?} bytes", body.len()))
})
}))
Expand Down

0 comments on commit 6420a2f

Please sign in to comment.