diff --git a/src/server/conn/http1.rs b/src/server/conn/http1.rs index d58a607c68..673d4f280b 100644 --- a/src/server/conn/http1.rs +++ b/src/server/conn/http1.rs @@ -10,6 +10,7 @@ use std::task::{Context, Poll}; use std::time::Duration; use crate::rt::{Read, Write}; +use crate::upgrade::Upgraded; use bytes::Bytes; use crate::body::{Body, Incoming as IncomingBody}; @@ -191,11 +192,11 @@ where /// Enable this connection to support higher-level HTTP upgrades. /// /// See [the `upgrade` module](crate::upgrade) for more. - pub fn with_upgrades(self) -> upgrades::UpgradeableConnection + pub fn with_upgrades(self) -> UpgradeableConnection where I: Send, { - upgrades::UpgradeableConnection { inner: Some(self) } + UpgradeableConnection { inner: Some(self) } } } @@ -433,60 +434,52 @@ impl Builder { } } -mod upgrades { - use crate::upgrade::Upgraded; - - use super::*; - - // A future binding a connection with a Service with Upgrade support. - // - // This type is unnameable outside the crate. - #[must_use = "futures do nothing unless polled"] - #[allow(missing_debug_implementations)] - pub struct UpgradeableConnection - where - S: HttpService, - { - pub(super) inner: Option>, - } +/// A future binding a connection with a Service with Upgrade support. +#[must_use = "futures do nothing unless polled"] +#[allow(missing_debug_implementations)] +pub struct UpgradeableConnection +where + S: HttpService, +{ + pub(super) inner: Option>, +} - impl UpgradeableConnection - where - S: HttpService, - S::Error: Into>, - I: Read + Write + Unpin, - B: Body + 'static, - B::Error: Into>, - { - /// Start a graceful shutdown process for this connection. - /// - /// This `Connection` should continue to be polled until shutdown - /// can finish. - pub fn graceful_shutdown(mut self: Pin<&mut Self>) { - Pin::new(self.inner.as_mut().unwrap()).graceful_shutdown() - } +impl UpgradeableConnection +where + S: HttpService, + S::Error: Into>, + I: Read + Write + Unpin, + B: Body + 'static, + B::Error: Into>, +{ + /// Start a graceful shutdown process for this connection. + /// + /// This `Connection` should continue to be polled until shutdown + /// can finish. + pub fn graceful_shutdown(mut self: Pin<&mut Self>) { + Pin::new(self.inner.as_mut().unwrap()).graceful_shutdown() } +} - impl Future for UpgradeableConnection - where - S: HttpService, - S::Error: Into>, - I: Read + Write + Unpin + Send + 'static, - B: Body + 'static, - B::Error: Into>, - { - type Output = crate::Result<()>; +impl Future for UpgradeableConnection +where + S: HttpService, + S::Error: Into>, + I: Read + Write + Unpin + Send + 'static, + B: Body + 'static, + B::Error: Into>, +{ + type Output = crate::Result<()>; - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - match ready!(Pin::new(&mut self.inner.as_mut().unwrap().conn).poll(cx)) { - Ok(proto::Dispatched::Shutdown) => Poll::Ready(Ok(())), - Ok(proto::Dispatched::Upgrade(pending)) => { - let (io, buf, _) = self.inner.take().unwrap().conn.into_inner(); - pending.fulfill(Upgraded::new(io, buf)); - Poll::Ready(Ok(())) - } - Err(e) => Poll::Ready(Err(e)), + fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { + match ready!(Pin::new(&mut self.inner.as_mut().unwrap().conn).poll(cx)) { + Ok(proto::Dispatched::Shutdown) => Poll::Ready(Ok(())), + Ok(proto::Dispatched::Upgrade(pending)) => { + let (io, buf, _) = self.inner.take().unwrap().conn.into_inner(); + pending.fulfill(Upgraded::new(io, buf)); + Poll::Ready(Ok(())) } + Err(e) => Poll::Ready(Err(e)), } } }