Skip to content

Commit 956968e

Browse files
committed
Merge remote-tracking branch 'upstream/0.14.x' into feat/backport-split-server-conn-modules
2 parents 46f1f9d + 0368a41 commit 956968e

File tree

12 files changed

+1205
-18
lines changed

12 files changed

+1205
-18
lines changed

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ ffi = ["libc"]
112112
# enable 1.0 backports
113113
backports = []
114114

115+
# whether or not to display deprecation warnings
116+
deprecated = []
117+
115118
# internal features used in CI
116119
nightly = []
117120
__internal_happy_eyeballs_tests = []

examples/tower_client.rs

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#![deny(warnings)]
22

3-
use hyper::client::conn::Builder;
4-
use hyper::client::connect::HttpConnector;
5-
use hyper::client::service::Connect;
3+
use std::future::Future;
4+
use std::pin::Pin;
5+
use std::task::{Context, Poll};
6+
67
use hyper::service::Service;
7-
use hyper::{Body, Request};
8+
use hyper::{Body, Request, Response};
9+
use tokio::net::TcpStream;
810

911
#[tokio::main]
10-
async fn main() -> Result<(), Box<dyn std::error::Error>> {
12+
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
1113
pretty_env_logger::init();
1214

13-
let mut mk_svc = Connect::new(HttpConnector::new(), Builder::new());
14-
1515
let uri = "http://127.0.0.1:8080".parse::<http::Uri>()?;
1616

17-
let mut svc = mk_svc.call(uri.clone()).await?;
17+
let mut svc = Connector;
1818

1919
let body = Body::empty();
2020

@@ -25,3 +25,35 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
2525

2626
Ok(())
2727
}
28+
29+
struct Connector;
30+
31+
impl Service<Request<Body>> for Connector {
32+
type Response = Response<Body>;
33+
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
34+
type Future = Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>>>>;
35+
36+
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> std::task::Poll<Result<(), Self::Error>> {
37+
Poll::Ready(Ok(()))
38+
}
39+
40+
fn call(&mut self, req: Request<Body>) -> Self::Future {
41+
Box::pin(async move {
42+
let host = req.uri().host().expect("no host in uri");
43+
let port = req.uri().port_u16().expect("no port in uri");
44+
45+
let stream = TcpStream::connect(format!("{}:{}", host, port)).await?;
46+
47+
let (mut sender, conn) = hyper::client::conn::http1::handshake(stream).await?;
48+
49+
tokio::task::spawn(async move {
50+
if let Err(err) = conn.await {
51+
println!("Connection error: {:?}", err);
52+
}
53+
});
54+
55+
let res = sender.send_request(req).await?;
56+
Ok(res)
57+
})
58+
}
59+
}

src/client/client.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use super::HttpConnector;
3333
#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))]
3434
pub struct Client<C, B = Body> {
3535
config: Config,
36+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
3637
conn_builder: conn::Builder,
3738
connector: C,
3839
pool: Pool<PoolClient<B>>,
@@ -327,12 +328,14 @@ where
327328
drop(delayed_tx);
328329
});
329330

331+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
330332
self.conn_builder.exec.execute(on_idle);
331333
} else {
332334
// There's no body to delay, but the connection isn't
333335
// ready yet. Only re-insert when it's ready
334336
let on_idle = future::poll_fn(move |cx| pooled.poll_ready(cx)).map(|_| ());
335337

338+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
336339
self.conn_builder.exec.execute(on_idle);
337340
}
338341

@@ -386,6 +389,7 @@ where
386389
});
387390
// An execute error here isn't important, we're just trying
388391
// to prevent a waste of a socket...
392+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
389393
self.conn_builder.exec.execute(bg);
390394
}
391395
Ok(checked_out)
@@ -430,6 +434,7 @@ where
430434
&self,
431435
pool_key: PoolKey,
432436
) -> impl Lazy<Output = crate::Result<Pooled<PoolClient<B>>>> + Unpin {
437+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
433438
let executor = self.conn_builder.exec.clone();
434439
let pool = self.pool.clone();
435440
#[cfg(not(feature = "http2"))]
@@ -629,6 +634,7 @@ struct PoolClient<B> {
629634
}
630635

631636
enum PoolTx<B> {
637+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
632638
Http1(conn::SendRequest<B>),
633639
#[cfg(feature = "http2")]
634640
Http2(conn::Http2SendRequest<B>),
@@ -905,6 +911,7 @@ fn is_schema_secure(uri: &Uri) -> bool {
905911
#[derive(Clone)]
906912
pub struct Builder {
907913
client_config: Config,
914+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
908915
conn_builder: conn::Builder,
909916
pool_config: pool::Config,
910917
}
@@ -917,6 +924,7 @@ impl Default for Builder {
917924
set_host: true,
918925
ver: Ver::Auto,
919926
},
927+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
920928
conn_builder: conn::Builder::new(),
921929
pool_config: pool::Config {
922930
idle_timeout: Some(Duration::from_secs(90)),
@@ -1381,6 +1389,7 @@ impl Builder {
13811389
B: HttpBody + Send,
13821390
B::Data: Send,
13831391
{
1392+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
13841393
Client {
13851394
config: self.client_config,
13861395
conn_builder: self.conn_builder.clone(),

src/client/conn.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454
//! # }
5555
//! ```
5656
57+
#[cfg(all(feature = "backports", feature = "http1"))]
58+
pub mod http1;
59+
#[cfg(all(feature = "backports", feature = "http2"))]
60+
pub mod http2;
61+
5762
use std::error::Error as StdError;
5863
use std::fmt;
5964
#[cfg(not(all(feature = "http1", feature = "http2")))]
@@ -118,16 +123,30 @@ pin_project! {
118123
///
119124
/// This is a shortcut for `Builder::new().handshake(io)`.
120125
/// See [`client::conn`](crate::client::conn) for more.
126+
#[cfg_attr(
127+
feature = "deprecated",
128+
deprecated(
129+
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."
130+
)
131+
)]
132+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
121133
pub async fn handshake<T>(
122134
io: T,
123135
) -> crate::Result<(SendRequest<crate::Body>, Connection<T, crate::Body>)>
124136
where
125137
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
126138
{
139+
#[allow(deprecated)]
127140
Builder::new().handshake(io).await
128141
}
129142

130143
/// The sender side of an established connection.
144+
#[cfg_attr(
145+
feature = "deprecated",
146+
deprecated(
147+
note = "This type will be replaced with `client::conn::http1::SendRequest` and `client::conn::http2::SendRequest` in 1.0, enable the \"backports\" feature to use them now."
148+
)
149+
)]
131150
pub struct SendRequest<B> {
132151
dispatch: dispatch::Sender<Request<B>, Response<Body>>,
133152
}
@@ -137,6 +156,12 @@ pub struct SendRequest<B> {
137156
/// In most cases, this should just be spawned into an executor, so that it
138157
/// can process incoming and outgoing messages, notice hangups, and the like.
139158
#[must_use = "futures do nothing unless polled"]
159+
#[cfg_attr(
160+
feature = "deprecated",
161+
deprecated(
162+
note = "This type will be replaced with `client::conn::http1::Connection` and `client::conn::http2::Connection` in 1.0, enable the \"backports\" feature to use them now."
163+
)
164+
)]
140165
pub struct Connection<T, B>
141166
where
142167
T: AsyncRead + AsyncWrite + Send + 'static,
@@ -149,6 +174,12 @@ where
149174
///
150175
/// After setting options, the builder is used to create a handshake future.
151176
#[derive(Clone, Debug)]
177+
#[cfg_attr(
178+
feature = "deprecated",
179+
deprecated(
180+
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."
181+
)
182+
)]
152183
pub struct Builder {
153184
pub(super) exec: Exec,
154185
h09_responses: bool,
@@ -221,6 +252,7 @@ pub(super) struct Http2SendRequest<B> {
221252

222253
// ===== impl SendRequest
223254

255+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
224256
impl<B> SendRequest<B> {
225257
/// Polls to determine whether this sender can be used yet for a request.
226258
///
@@ -254,6 +286,7 @@ impl<B> SendRequest<B> {
254286
}
255287
}
256288

289+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
257290
impl<B> SendRequest<B>
258291
where
259292
B: HttpBody + 'static,
@@ -339,6 +372,7 @@ where
339372
}
340373
}
341374

375+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
342376
impl<B> Service<Request<B>> for SendRequest<B>
343377
where
344378
B: HttpBody + 'static,
@@ -356,6 +390,7 @@ where
356390
}
357391
}
358392

393+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
359394
impl<B> fmt::Debug for SendRequest<B> {
360395
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
361396
f.debug_struct("SendRequest").finish()
@@ -425,6 +460,7 @@ impl<B> Clone for Http2SendRequest<B> {
425460

426461
// ===== impl Connection
427462

463+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
428464
impl<T, B> Connection<T, B>
429465
where
430466
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
@@ -508,9 +544,10 @@ where
508544
}
509545
}
510546

547+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
511548
impl<T, B> Future for Connection<T, B>
512549
where
513-
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
550+
T: AsyncRead + AsyncWrite + Unpin + Send,
514551
B: HttpBody + Send + 'static,
515552
B::Data: Send,
516553
B::Error: Into<Box<dyn StdError + Send + Sync>>,
@@ -536,6 +573,7 @@ where
536573
}
537574
}
538575

576+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
539577
impl<T, B> fmt::Debug for Connection<T, B>
540578
where
541579
T: AsyncRead + AsyncWrite + fmt::Debug + Send + 'static,
@@ -548,6 +586,7 @@ where
548586

549587
// ===== impl Builder
550588

589+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
551590
impl Builder {
552591
/// Creates a new connection builder.
553592
#[inline]
@@ -1085,9 +1124,11 @@ where
10851124
trait AssertSend: Send {}
10861125
trait AssertSendSync: Send + Sync {}
10871126

1127+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
10881128
#[doc(hidden)]
10891129
impl<B: Send> AssertSendSync for SendRequest<B> {}
10901130

1131+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
10911132
#[doc(hidden)]
10921133
impl<T: Send, B: Send> AssertSend for Connection<T, B>
10931134
where
@@ -1097,6 +1138,7 @@ where
10971138
{
10981139
}
10991140

1141+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
11001142
#[doc(hidden)]
11011143
impl<T: Send + Sync, B: Send + Sync> AssertSendSync for Connection<T, B>
11021144
where
@@ -1106,6 +1148,7 @@ where
11061148
{
11071149
}
11081150

1151+
#[cfg_attr(feature = "deprecated", allow(deprecated))]
11091152
#[doc(hidden)]
11101153
impl AssertSendSync for Builder {}
11111154

0 commit comments

Comments
 (0)