mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 07:53:00 +01:00
update client example
This commit is contained in:
parent
0eed9e5257
commit
6420a2fe1f
@ -1,7 +1,6 @@
|
|||||||
use actix_http::Error;
|
use actix_http::Error;
|
||||||
use actix_rt::System;
|
use actix_rt::System;
|
||||||
use bytes::BytesMut;
|
use futures::{future::lazy, Future};
|
||||||
use futures::{future::lazy, Future, Stream};
|
|
||||||
|
|
||||||
fn main() -> Result<(), Error> {
|
fn main() -> Result<(), Error> {
|
||||||
std::env::set_var("RUST_LOG", "actix_http=trace");
|
std::env::set_var("RUST_LOG", "actix_http=trace");
|
||||||
@ -13,17 +12,14 @@ fn main() -> Result<(), Error> {
|
|||||||
.header("User-Agent", "Actix-web")
|
.header("User-Agent", "Actix-web")
|
||||||
.send() // <- Send http request
|
.send() // <- Send http request
|
||||||
.from_err()
|
.from_err()
|
||||||
.and_then(|response| {
|
.and_then(|mut response| {
|
||||||
// <- server http response
|
// <- server http response
|
||||||
println!("Response: {:?}", response);
|
println!("Response: {:?}", response);
|
||||||
|
|
||||||
// read response body
|
// read response body
|
||||||
response
|
response
|
||||||
|
.body()
|
||||||
.from_err()
|
.from_err()
|
||||||
.fold(BytesMut::new(), move |mut acc, chunk| {
|
|
||||||
acc.extend_from_slice(&chunk);
|
|
||||||
Ok::<_, Error>(acc)
|
|
||||||
})
|
|
||||||
.map(|body| println!("Downloaded: {:?} bytes", body.len()))
|
.map(|body| println!("Downloaded: {:?} bytes", body.len()))
|
||||||
})
|
})
|
||||||
}))
|
}))
|
||||||
|
Loading…
Reference in New Issue
Block a user