From d97181a278d9c59f1d7f2713732e400440861216 Mon Sep 17 00:00:00 2001 From: Rakshith Ravi Date: Fri, 29 Sep 2023 23:07:59 +0530 Subject: [PATCH] Added with upgrades to auto serve connection (#38) --- src/server/conn/auto.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/server/conn/auto.rs b/src/server/conn/auto.rs index 11ac954..adb7405 100644 --- a/src/server/conn/auto.rs +++ b/src/server/conn/auto.rs @@ -86,6 +86,35 @@ impl Builder { Ok(()) } + + /// Bind a connection together with a [`Service`], with the ability to + /// handle HTTP upgrades. This requires that the IO object implements + /// `Send`. + pub async fn serve_connection_with_upgrades(&self, io: I, service: S) -> Result<()> + where + S: Service, Response = Response> + Send, + S::Future: Send + 'static, + S::Error: Into>, + B: Body + Send + 'static, + B::Data: Send, + B::Error: Into>, + I: AsyncRead + AsyncWrite + Unpin + Send + 'static, + E: Http2ConnExec, + { + let (version, io) = read_version(io).await?; + let io = TokioIo::new(io); + match version { + Version::H1 => { + self.http1 + .serve_connection(io, service) + .with_upgrades() + .await? + } + Version::H2 => self.http2.serve_connection(io, service).await?, + } + + Ok(()) + } } #[derive(Copy, Clone)] enum Version {