Skip to content

Commit

Permalink
feat(server): deprecate server conn structs (#3161)
Browse files Browse the repository at this point in the history
  • Loading branch information
oddgrd authored Mar 9, 2023
1 parent 84881c9 commit 02fe20f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/server/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<E = Exec> {
pub(crate) exec: E,
h1_half_close: bool,
Expand Down Expand Up @@ -213,6 +219,12 @@ impl<E> Unpin for Fallback<E> {}
#[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<T, S> {
/// The original IO object used in the handshake.
pub io: T,
Expand All @@ -232,6 +244,7 @@ pub struct Parts<T, S> {

// ===== 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
Expand All @@ -255,6 +268,7 @@ impl Http {
}
}

#[cfg_attr(feature = "deprecated", allow(deprecated))]
#[cfg(any(feature = "http1", feature = "http2"))]
impl<E> Http<E> {
/// Sets whether HTTP1 is required.
Expand Down Expand Up @@ -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<I, S> {
self.try_into_parts()
.unwrap_or_else(|| panic!("h2 cannot into_inner"))
Expand All @@ -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<Parts<I, S>> {
match self.conn.unwrap() {
#[cfg(feature = "http1")]
Expand All @@ -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<crate::Result<()>>
{
pub fn poll_without_shutdown(&mut self, cx: &mut task::Context<'_>) -> Poll<crate::Result<()>> {
loop {
match *self.conn.as_mut().unwrap() {
#[cfg(feature = "http1")]
Expand Down Expand Up @@ -809,8 +824,8 @@ where
/// # Error
///
/// This errors if the underlying connection protocol is not HTTP/1.
pub fn without_shutdown(self) -> impl Future<Output = crate::Result<Parts<I, S>>>
{
#[cfg_attr(feature = "deprecated", allow(deprecated))]
pub fn without_shutdown(self) -> impl Future<Output = crate::Result<Parts<I, S>>> {
let mut conn = Some(self);
futures_util::future::poll_fn(move |cx| {
ready!(conn.as_mut().unwrap().poll_without_shutdown(cx))?;
Expand Down
8 changes: 8 additions & 0 deletions src/server/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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<I, S, E = Exec> {
#[pin]
incoming: I,
Expand All @@ -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<I, E = Exec> {
incoming: I,
protocol: Http_<E>,
Expand All @@ -52,6 +55,7 @@ pub struct Builder<I, E = Exec> {
// ===== impl Server =====

#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))]
#[cfg_attr(feature = "deprecated", allow(deprecated))]
impl<I> Server<I, ()> {
/// Starts a [`Builder`](Builder) with the provided incoming stream.
pub fn builder(incoming: I) -> Builder<I> {
Expand Down Expand Up @@ -105,6 +109,7 @@ impl<S, E> Server<AddrIncoming, S, E> {
}

#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))]
#[cfg_attr(feature = "deprecated", allow(deprecated))]
impl<I, IO, IE, S, E, B> Server<I, S, E>
where
I: Accept<Conn = IO, Error = IE>,
Expand Down Expand Up @@ -207,6 +212,7 @@ where
}

#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))]
#[cfg_attr(feature = "deprecated", allow(deprecated))]
impl<I, IO, IE, S, B, E> Future for Server<I, S, E>
where
I: Accept<Conn = IO, Error = IE>,
Expand Down Expand Up @@ -237,6 +243,7 @@ impl<I: fmt::Debug, S: fmt::Debug> fmt::Debug for Server<I, S> {
// ===== impl Builder =====

#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))]
#[cfg_attr(feature = "deprecated", allow(deprecated))]
impl<I, E> Builder<I, E> {
/// Start a new builder, wrapping an incoming stream and low-level options.
///
Expand Down Expand Up @@ -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<I, F, E = Exec> {
#[pin]
future: F,
Expand Down
1 change: 1 addition & 0 deletions tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down

0 comments on commit 02fe20f

Please sign in to comment.