From 02fe20f232a7c3cf24d505b121ce4d428a93254d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oddbj=C3=B8rn=20Gr=C3=B8dem?= <29732646+oddgrd@users.noreply.github.com> Date: Thu, 9 Mar 2023 18:27:14 +0000 Subject: [PATCH] feat(server): deprecate server conn structs (#3161) --- src/server/conn.rs | 23 +++++++++++++++++++---- src/server/server.rs | 8 ++++++++ tests/server.rs | 1 + 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/server/conn.rs b/src/server/conn.rs index 897ec640e2..f820e083d0 100644 --- a/src/server/conn.rs +++ b/src/server/conn.rs @@ -98,6 +98,12 @@ pub use super::tcp::{AddrIncoming, AddrStream}; #[derive(Clone, Debug)] #[cfg(any(feature = "http1", feature = "http2"))] #[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))] +#[cfg_attr( + feature = "deprecated", + deprecated( + note = "This struct will be replaced with `server::conn::http1::Builder` and `server::conn::http2::Builder` in 1.0, enable the \"backports\" feature to use them now." + ) +)] pub struct Http { pub(crate) exec: E, h1_half_close: bool, @@ -213,6 +219,12 @@ impl Unpin for Fallback {} #[derive(Debug)] #[cfg(any(feature = "http1", feature = "http2"))] #[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))] +#[cfg_attr( + feature = "deprecated", + deprecated( + note = "This struct will be replaced with `server::conn::http1::Parts` in 1.0, enable the \"backports\" feature to use them now." + ) +)] pub struct Parts { /// The original IO object used in the handshake. pub io: T, @@ -232,6 +244,7 @@ pub struct Parts { // ===== impl Http ===== +#[cfg_attr(feature = "deprecated", allow(deprecated))] #[cfg(any(feature = "http1", feature = "http2"))] impl Http { /// Creates a new instance of the HTTP protocol, ready to spawn a server or @@ -255,6 +268,7 @@ impl Http { } } +#[cfg_attr(feature = "deprecated", allow(deprecated))] #[cfg(any(feature = "http1", feature = "http2"))] impl Http { /// Sets whether HTTP1 is required. @@ -738,6 +752,7 @@ where /// /// # Panics /// This method will panic if this connection is using an h2 protocol. + #[cfg_attr(feature = "deprecated", allow(deprecated))] pub fn into_parts(self) -> Parts { self.try_into_parts() .unwrap_or_else(|| panic!("h2 cannot into_inner")) @@ -746,6 +761,7 @@ where /// Return the inner IO object, and additional information, if available. /// /// This method will return a `None` if this connection is using an h2 protocol. + #[cfg_attr(feature = "deprecated", allow(deprecated))] pub fn try_into_parts(self) -> Option> { match self.conn.unwrap() { #[cfg(feature = "http1")] @@ -772,8 +788,7 @@ where /// upgrade. Once the upgrade is completed, the connection would be "done", /// but it is not desired to actually shutdown the IO object. Instead you /// would take it back using `into_parts`. - pub fn poll_without_shutdown(&mut self, cx: &mut task::Context<'_>) -> Poll> - { + pub fn poll_without_shutdown(&mut self, cx: &mut task::Context<'_>) -> Poll> { loop { match *self.conn.as_mut().unwrap() { #[cfg(feature = "http1")] @@ -809,8 +824,8 @@ where /// # Error /// /// This errors if the underlying connection protocol is not HTTP/1. - pub fn without_shutdown(self) -> impl Future>> - { + #[cfg_attr(feature = "deprecated", allow(deprecated))] + pub fn without_shutdown(self) -> impl Future>> { let mut conn = Some(self); futures_util::future::poll_fn(move |cx| { ready!(conn.as_mut().unwrap().poll_without_shutdown(cx))?; diff --git a/src/server/server.rs b/src/server/server.rs index e4273674fc..e80c7d791b 100644 --- a/src/server/server.rs +++ b/src/server/server.rs @@ -20,6 +20,7 @@ use crate::common::exec::{ConnStreamExec, NewSvcExec}; use crate::common::{task, Future, Pin, Poll, Unpin}; // Renamed `Http` as `Http_` for now so that people upgrading don't see an // error that `hyper::server::Http` is private... +#[cfg_attr(feature = "deprecated", allow(deprecated))] use super::conn::{Connection, Http as Http_, UpgradeableConnection}; use super::shutdown::{Graceful, GracefulWatcher}; use crate::service::{HttpService, MakeServiceRef}; @@ -33,6 +34,7 @@ pin_project! { /// handlers. It is built using the [`Builder`](Builder), and the future /// completes when the server has been shutdown. It should be run by an /// `Executor`. + #[cfg_attr(feature = "deprecated", allow(deprecated))] pub struct Server { #[pin] incoming: I, @@ -44,6 +46,7 @@ pin_project! { /// A builder for a [`Server`](Server). #[derive(Debug)] #[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))] +#[cfg_attr(feature = "deprecated", allow(deprecated))] pub struct Builder { incoming: I, protocol: Http_, @@ -52,6 +55,7 @@ pub struct Builder { // ===== impl Server ===== #[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))] +#[cfg_attr(feature = "deprecated", allow(deprecated))] impl Server { /// Starts a [`Builder`](Builder) with the provided incoming stream. pub fn builder(incoming: I) -> Builder { @@ -105,6 +109,7 @@ impl Server { } #[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))] +#[cfg_attr(feature = "deprecated", allow(deprecated))] impl Server where I: Accept, @@ -207,6 +212,7 @@ where } #[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))] +#[cfg_attr(feature = "deprecated", allow(deprecated))] impl Future for Server where I: Accept, @@ -237,6 +243,7 @@ impl fmt::Debug for Server { // ===== impl Builder ===== #[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))] +#[cfg_attr(feature = "deprecated", allow(deprecated))] impl Builder { /// Start a new builder, wrapping an incoming stream and low-level options. /// @@ -771,6 +778,7 @@ pin_project! { #[must_use = "futures do nothing unless polled"] #[derive(Debug)] #[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))] + #[cfg_attr(feature = "deprecated", allow(deprecated))] pub struct Connecting { #[pin] future: F, diff --git a/tests/server.rs b/tests/server.rs index 67b48d344f..1e944ea45b 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -2642,6 +2642,7 @@ async fn http2_keep_alive_count_server_pings() { } // Tests for backported 1.0 APIs +#[deny(deprecated)] mod backports { use super::*; use hyper::server::conn::{http1, http2};