This commit is contained in:
Felipe Noronha 2022-03-12 12:48:31 -03:00
parent 3f341d9337
commit cd9a5053eb
2 changed files with 6 additions and 0 deletions

View File

@ -73,18 +73,23 @@ async fn handle(client_ip: IpAddr, req: Request<Body>) -> Result<Response<Body>,
debug_request(req) debug_request(req)
} }
} }
#[tokio::main] #[tokio::main]
async fn main() { async fn main() {
let bind_addr = "127.0.0.1:8000"; let bind_addr = "127.0.0.1:8000";
let addr:SocketAddr = bind_addr.parse().expect("Could not parse ip:port."); let addr:SocketAddr = bind_addr.parse().expect("Could not parse ip:port.");
let make_svc = make_service_fn(|conn: &AddrStream| { let make_svc = make_service_fn(|conn: &AddrStream| {
let remote_addr = conn.remote_addr().ip(); let remote_addr = conn.remote_addr().ip();
async move { async move {
Ok::<_, Infallible>(service_fn(move |req| handle(remote_addr, req))) Ok::<_, Infallible>(service_fn(move |req| handle(remote_addr, req)))
} }
}); });
let server = Server::bind(&addr).serve(make_svc); let server = Server::bind(&addr).serve(make_svc);
println!("Running server on {:?}", addr); println!("Running server on {:?}", addr);
if let Err(e) = server.await { if let Err(e) = server.await {
eprintln!("server error: {}", e); eprintln!("server error: {}", e);
} }

View File

@ -83,6 +83,7 @@
//! let server = Server::bind(&addr).serve(make_svc); //! let server = Server::bind(&addr).serve(make_svc);
//! //!
//! println!("Running server on {:?}", addr); //! println!("Running server on {:?}", addr);
//!
//! if let Err(e) = server.await { //! if let Err(e) = server.await {
//! eprintln!("server error: {}", e); //! eprintln!("server error: {}", e);
//! } //! }