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 {