mirror of
https://github.com/fafhrd91/actix-web
synced 2024-11-24 00:21:08 +01:00
31 lines
1008 B
Rust
31 lines
1008 B
Rust
use actix_http::Error;
|
|
use actix_rt::System;
|
|
use bytes::BytesMut;
|
|
use futures::{future::lazy, Future, Stream};
|
|
|
|
fn main() -> Result<(), Error> {
|
|
std::env::set_var("RUST_LOG", "actix_http=trace");
|
|
env_logger::init();
|
|
|
|
System::new("test").block_on(lazy(|| {
|
|
awc::Client::new()
|
|
.get("https://www.rust-lang.org/") // <- Create request builder
|
|
.header("User-Agent", "Actix-web")
|
|
.send() // <- Send http request
|
|
.from_err()
|
|
.and_then(|response| {
|
|
// <- server http response
|
|
println!("Response: {:?}", response);
|
|
|
|
// read response body
|
|
response
|
|
.from_err()
|
|
.fold(BytesMut::new(), move |mut acc, chunk| {
|
|
acc.extend_from_slice(&chunk);
|
|
Ok::<_, Error>(acc)
|
|
})
|
|
.map(|body| println!("Downloaded: {:?} bytes", body.len()))
|
|
})
|
|
}))
|
|
}
|