use std::env::args; use anyhow::anyhow; use hyper::{Request, Uri}; use hyper::Body; use tokio::net::TcpStream; #[tokio::main] async fn main() -> anyhow::Result<()> { let arguments: Vec = args().collect(); let url_text = arguments.get(1).ok_or_else(|| anyhow!("Url required"))?; let url = url_text.parse::()?; let host = url.host().unwrap(); let port = url.port_u16().unwrap_or(80); let address = format!("{}:{}", host, port); let stream = TcpStream::connect(address).await?; let (mut sender, conn) = hyper::client::conn::handshake(stream).await?; tokio::task::spawn(async move { if let Err(err) = conn.await { eprintln!("connection failed: {}", err); } }); let authority = url.authority().unwrap().clone(); let req = Request::builder() .uri(url) .header(hyper::header::HOST, authority.as_str()) .body(Body::from(""))?; let mut res = sender.send_request(req).await?; println!("{:?}", res); Ok(()) }