From a8e80bcb97430da35585cecf3ed2bd2e2bb06323 Mon Sep 17 00:00:00 2001 From: kkocdko <31189892+kkocdko@users.noreply.github.com> Date: Fri, 12 Aug 2022 19:57:59 +0800 Subject: [PATCH] Improve performance in low-level-rustls example (#1254) --- examples/low-level-rustls/src/main.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/low-level-rustls/src/main.rs b/examples/low-level-rustls/src/main.rs index 6f4a2259..331b8c90 100644 --- a/examples/low-level-rustls/src/main.rs +++ b/examples/low-level-rustls/src/main.rs @@ -50,6 +50,8 @@ async fn main() { let listener = TcpListener::bind("127.0.0.1:3000").await.unwrap(); let mut listener = AddrIncoming::from_listener(listener).unwrap(); + let protocol = Arc::new(Http::new()); + let mut app = Router::new() .route("/", get(handler)) .into_make_service_with_connect_info::(); @@ -62,11 +64,13 @@ async fn main() { let acceptor = acceptor.clone(); - let app = app.make_service(&stream).await.unwrap(); + let protocol = protocol.clone(); + + let svc = app.make_service(&stream); tokio::spawn(async move { if let Ok(stream) = acceptor.accept(stream).await { - let _ = Http::new().serve_connection(stream, app).await; + let _ = protocol.serve_connection(stream, svc.await.unwrap()).await; } }); }