1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#![allow(unused_imports)]
use http_body_util::{BodyExt, Full};
use hyper::body::Bytes;
use hyper_util::client::legacy::Client;
#[cfg(feature = "client")]
use hyperlocal::{UnixClientExt, UnixConnector, Uri};
use std::error::Error;
use tokio::io::{self, AsyncWriteExt as _};
#[tokio::main]
#[cfg(feature = "client")]
async fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
let url = Uri::new("/tmp/hyperlocal.sock", "/").into();
let client: Client<UnixConnector, Full<Bytes>> = Client::unix();
let mut response = client.get(url).await?;
while let Some(frame_result) = response.frame().await {
let frame = frame_result?;
if let Some(segment) = frame.data_ref() {
io::stdout().write_all(segment.iter().as_slice()).await?;
}
}
Ok(())
}
#[cfg(not(feature = "client"))]
fn main() {}
|