diff --git a/src/server/conn/auto.rs b/src/server/conn/auto.rs index 7e74d16..47d88dc 100644 --- a/src/server/conn/auto.rs +++ b/src/server/conn/auto.rs @@ -665,6 +665,27 @@ impl Http1Builder<'_, E> { { self.inner.serve_connection(io, service).await } + + /// Bind a connection together with a [`Service`], with the ability to + /// handle HTTP upgrades. This requires that the IO object implements + /// `Send`. + #[cfg(feature = "http2")] + pub fn serve_connection_with_upgrades( + &self, + io: I, + service: S, + ) -> UpgradeableConnection<'_, I, S, E> + where + S: Service, Response = Response>, + S::Future: 'static, + S::Error: Into>, + B: Body + 'static, + B::Error: Into>, + I: Read + Write + Unpin + Send + 'static, + E: HttpServerConnExec, + { + self.inner.serve_connection_with_upgrades(io, service) + } } /// Http2 part of builder. @@ -824,6 +845,26 @@ impl Http2Builder<'_, E> { { self.inner.serve_connection(io, service).await } + + /// Bind a connection together with a [`Service`], with the ability to + /// handle HTTP upgrades. This requires that the IO object implements + /// `Send`. + pub fn serve_connection_with_upgrades( + &self, + io: I, + service: S, + ) -> UpgradeableConnection<'_, I, S, E> + where + S: Service, Response = Response>, + S::Future: 'static, + S::Error: Into>, + B: Body + 'static, + B::Error: Into>, + I: Read + Write + Unpin + Send + 'static, + E: HttpServerConnExec, + { + self.inner.serve_connection_with_upgrades(io, service) + } } #[cfg(test)] @@ -971,7 +1012,9 @@ mod tests { let stream = TokioIo::new(stream); tokio::task::spawn(async move { let _ = auto::Builder::new(TokioExecutor::new()) - .serve_connection(stream, service_fn(hello)) + .http2() + .max_header_list_size(4096) + .serve_connection_with_upgrades(stream, service_fn(hello)) .await; }); }