diff --git a/Cargo.toml b/Cargo.toml index 9349f4039d..009adb83e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -112,6 +112,9 @@ ffi = ["libc"] # 1.0 compatibile client API backports = [] +# whether or not to display deprecation warnings +deprecated = [] + # internal features used in CI nightly = [] __internal_happy_eyeballs_tests = [] diff --git a/examples/tower_client.rs b/examples/tower_client.rs index 5a2a6e78df..f733fe0d35 100644 --- a/examples/tower_client.rs +++ b/examples/tower_client.rs @@ -1,20 +1,20 @@ #![deny(warnings)] -use hyper::client::conn::Builder; -use hyper::client::connect::HttpConnector; -use hyper::client::service::Connect; +use std::future::Future; +use std::pin::Pin; +use std::task::{Context, Poll}; + use hyper::service::Service; -use hyper::{Body, Request}; +use hyper::{Body, Request, Response}; +use tokio::net::TcpStream; #[tokio::main] -async fn main() -> Result<(), Box> { +async fn main() -> Result<(), Box> { pretty_env_logger::init(); - let mut mk_svc = Connect::new(HttpConnector::new(), Builder::new()); - let uri = "http://127.0.0.1:8080".parse::()?; - let mut svc = mk_svc.call(uri.clone()).await?; + let mut svc = Connector; let body = Body::empty(); @@ -25,3 +25,35 @@ async fn main() -> Result<(), Box> { Ok(()) } + +struct Connector; + +impl Service> for Connector { + type Response = Response; + type Error = Box; + type Future = Pin>>>; + + fn poll_ready(&mut self, _cx: &mut Context<'_>) -> std::task::Poll> { + Poll::Ready(Ok(())) + } + + fn call(&mut self, req: Request) -> Self::Future { + Box::pin(async move { + let host = req.uri().host().expect("no host in uri"); + let port = req.uri().port_u16().expect("no port in uri"); + + let stream = TcpStream::connect(format!("{}:{}", host, port)).await?; + + let (mut sender, conn) = hyper::client::conn::http1::handshake(stream).await?; + + tokio::task::spawn(async move { + if let Err(err) = conn.await { + println!("Connection error: {:?}", err); + } + }); + + let res = sender.send_request(req).await?; + Ok(res) + }) + } +} diff --git a/src/client/client.rs b/src/client/client.rs index 96de907655..c24a5803d5 100644 --- a/src/client/client.rs +++ b/src/client/client.rs @@ -917,6 +917,7 @@ impl Default for Builder { set_host: true, ver: Ver::Auto, }, + #[allow(deprecated)] conn_builder: conn::Builder::new(), pool_config: pool::Config { idle_timeout: Some(Duration::from_secs(90)), diff --git a/src/client/conn.rs b/src/client/conn.rs index a8b41e4adb..3938605258 100644 --- a/src/client/conn.rs +++ b/src/client/conn.rs @@ -123,12 +123,19 @@ pin_project! { /// /// This is a shortcut for `Builder::new().handshake(io)`. /// See [`client::conn`](crate::client::conn) for more. +#[cfg_attr( + feature = "deprecated", + deprecated( + note = "This function will be replaced with `client::conn::http1::handshake` and `client::conn::http2::handshake` in 1.0, enable the \"backports\" feature to use them now." + ) +)] pub async fn handshake( io: T, ) -> crate::Result<(SendRequest, Connection)> where T: AsyncRead + AsyncWrite + Unpin + Send + 'static, { + #[allow(deprecated)] Builder::new().handshake(io).await } @@ -555,6 +562,12 @@ where impl Builder { /// Creates a new connection builder. + #[cfg_attr( + feature = "deprecated", + deprecated( + note = "This type will be replaced with `client::conn::http1::Builder` and `client::conn::http2::Builder` in 1.0, enable the \"backports\" feature to use them now." + ) + )] #[inline] pub fn new() -> Builder { Builder { diff --git a/src/ffi/client.rs b/src/ffi/client.rs index 4cdb257e30..670f77d141 100644 --- a/src/ffi/client.rs +++ b/src/ffi/client.rs @@ -93,6 +93,7 @@ unsafe impl AsTaskType for hyper_clientconn { ffi_fn! { /// Creates a new set of HTTP clientconn options to be used in a handshake. fn hyper_clientconn_options_new() -> *mut hyper_clientconn_options { + #[allow(deprecated)] let builder = conn::Builder::new(); Box::into_raw(Box::new(hyper_clientconn_options { diff --git a/tests/client.rs b/tests/client.rs index 965c21bb12..010860adc6 100644 --- a/tests/client.rs +++ b/tests/client.rs @@ -2181,6 +2181,7 @@ mod dispatch_impl { } } +#[allow(deprecated)] mod conn { use std::io::{self, Read, Write}; use std::net::{SocketAddr, TcpListener}; @@ -2246,6 +2247,7 @@ mod conn { future::join(server, client).await; } + #[deny(deprecated)] #[cfg(feature = "backports")] mod backports { use super::*; diff --git a/tests/server.rs b/tests/server.rs index 017cca9405..d5e09f9795 100644 --- a/tests/server.rs +++ b/tests/server.rs @@ -2536,6 +2536,7 @@ async fn http2_keep_alive_with_responsive_client() { }); let tcp = connect_async(addr).await; + #[allow(deprecated)] let (mut client, conn) = hyper::client::conn::Builder::new() .http2_only(true) .handshake::<_, Body>(tcp)