Skip to content

Commit f898015

Browse files
committed
feat: upgrade to hyper 1.0.0-rc.4, add TokioIo
1 parent 4390d51 commit f898015

File tree

8 files changed

+208
-25
lines changed

8 files changed

+208
-25
lines changed

.github/workflows/CI.yml

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ jobs:
8282
with:
8383
toolchain: ${{ matrix.rust }}
8484

85+
- name: Make sure log v0.4.18 is used
86+
run: |
87+
cargo update
88+
cargo update -p log --precise 0.4.18
89+
8590
- run: cargo check
8691

8792
miri:

Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ edition = "2018"
1515
publish = false # no accidents while in dev
1616

1717
[dependencies]
18-
hyper = "=1.0.0-rc.3"
18+
hyper = "=1.0.0-rc.4"
1919
futures-channel = "0.3"
2020
futures-util = { version = "0.3", default-features = false }
2121
http = "0.2"
@@ -31,7 +31,7 @@ tower = { version = "0.4", features = ["make", "util"] }
3131

3232
[dev-dependencies]
3333
bytes = "1"
34-
http-body-util = "0.1.0-rc.2"
34+
http-body-util = "0.1.0-rc.3"
3535
tokio = { version = "1", features = ["macros", "test-util"] }
3636

3737
[target.'cfg(any(target_os = "linux", target_os = "macos"))'.dev-dependencies]

src/client/connect/http.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use tracing::{debug, trace, warn};
1919

2020
use super::dns::{self, resolve, GaiResolver, Resolve};
2121
use super::{Connected, Connection};
22+
use crate::rt::TokioIo;
2223

2324
/// A connector for the `http` scheme.
2425
///
@@ -335,7 +336,7 @@ where
335336
R: Resolve + Clone + Send + Sync + 'static,
336337
R::Future: Send,
337338
{
338-
type Response = TcpStream;
339+
type Response = TokioIo<TcpStream>;
339340
type Error = ConnectError;
340341
type Future = HttpConnecting<R>;
341342

@@ -402,7 +403,7 @@ impl<R> HttpConnector<R>
402403
where
403404
R: Resolve,
404405
{
405-
async fn call_async(&mut self, dst: Uri) -> Result<TcpStream, ConnectError> {
406+
async fn call_async(&mut self, dst: Uri) -> Result<TokioIo<TcpStream>, ConnectError> {
406407
let config = &self.config;
407408

408409
let (host, port) = get_host_port(config, &dst)?;
@@ -433,14 +434,16 @@ where
433434
warn!("tcp set_nodelay error: {}", e);
434435
}
435436

436-
Ok(sock)
437+
Ok(TokioIo::new(sock))
437438
}
438439
}
439440

440-
impl Connection for TcpStream {
441+
impl Connection for TokioIo<TcpStream> {
441442
fn connected(&self) -> Connected {
442443
let connected = Connected::new();
443-
if let (Ok(remote_addr), Ok(local_addr)) = (self.peer_addr(), self.local_addr()) {
444+
if let (Ok(remote_addr), Ok(local_addr)) =
445+
(self.inner().peer_addr(), self.inner().local_addr())
446+
{
444447
connected.extra(HttpInfo {
445448
remote_addr,
446449
local_addr,
@@ -478,7 +481,7 @@ pin_project! {
478481
}
479482
}
480483

481-
type ConnectResult = Result<TcpStream, ConnectError>;
484+
type ConnectResult = Result<TokioIo<TcpStream>, ConnectError>;
482485
type BoxConnecting = Pin<Box<dyn Future<Output = ConnectResult> + Send>>;
483486

484487
impl<R: Resolve> Future for HttpConnecting<R> {

src/client/connect/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! # Connectors
1010
//!
1111
//! A "connector" is a [`Service`][] that takes a [`Uri`][] destination, and
12-
//! its `Response` is some type implementing [`AsyncRead`][], [`AsyncWrite`][],
12+
//! its `Response` is some type implementing [`Read`][], [`Write`][],
1313
//! and [`Connection`][].
1414
//!
1515
//! ## Custom Connectors
@@ -59,8 +59,8 @@
5959
//! [`HttpConnector`]: HttpConnector
6060
//! [`Service`]: tower::Service
6161
//! [`Uri`]: ::http::Uri
62-
//! [`AsyncRead`]: tokio::io::AsyncRead
63-
//! [`AsyncWrite`]: tokio::io::AsyncWrite
62+
//! [`Read`]: hyper::rt::Read
63+
//! [`Write`]: hyper::rt::Write
6464
//! [`Connection`]: Connection
6565
use std::fmt;
6666

@@ -248,7 +248,7 @@ pub(super) mod sealed {
248248
use std::marker::Unpin;
249249

250250
use ::http::Uri;
251-
use tokio::io::{AsyncRead, AsyncWrite};
251+
use hyper::rt::{Read, Write};
252252

253253
use super::Connection;
254254

@@ -272,7 +272,7 @@ pub(super) mod sealed {
272272
}
273273

274274
pub trait ConnectSvc {
275-
type Connection: AsyncRead + AsyncWrite + Connection + Unpin + Send + 'static;
275+
type Connection: Read + Write + Connection + Unpin + Send + 'static;
276276
type Error: Into<Box<dyn StdError + Send + Sync>>;
277277
type Future: Future<Output = Result<Self::Connection, Self::Error>> + Unpin + Send + 'static;
278278

@@ -284,7 +284,7 @@ pub(super) mod sealed {
284284
S: tower_service::Service<Uri, Response = T> + Send + 'static,
285285
S::Error: Into<Box<dyn StdError + Send + Sync>>,
286286
S::Future: Unpin + Send,
287-
T: AsyncRead + AsyncWrite + Connection + Unpin + Send + 'static,
287+
T: Read + Write + Connection + Unpin + Send + 'static,
288288
{
289289
type _Svc = S;
290290

@@ -298,7 +298,7 @@ pub(super) mod sealed {
298298
S: tower_service::Service<Uri, Response = T> + Send + 'static,
299299
S::Error: Into<Box<dyn StdError + Send + Sync>>,
300300
S::Future: Unpin + Send,
301-
T: AsyncRead + AsyncWrite + Connection + Unpin + Send + 'static,
301+
T: Read + Write + Connection + Unpin + Send + 'static,
302302
{
303303
type Connection = T;
304304
type Error = S::Error;
@@ -314,7 +314,7 @@ pub(super) mod sealed {
314314
S: tower_service::Service<Uri, Response = T> + Send,
315315
S::Error: Into<Box<dyn StdError + Send + Sync>>,
316316
S::Future: Unpin + Send,
317-
T: AsyncRead + AsyncWrite + Connection + Unpin + Send + 'static,
317+
T: Read + Write + Connection + Unpin + Send + 'static,
318318
{
319319
}
320320

src/client/legacy.rs

+10-9
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub struct Client<C, B> {
3737
#[cfg(feature = "http1")]
3838
h1_builder: hyper::client::conn::http1::Builder,
3939
#[cfg(feature = "http2")]
40-
h2_builder: hyper::client::conn::http2::Builder,
40+
h2_builder: hyper::client::conn::http2::Builder<Exec>,
4141
pool: pool::Pool<PoolClient<B>, PoolKey>,
4242
}
4343

@@ -128,7 +128,7 @@ impl Client<(), ()> {
128128
impl<C, B> Client<C, B>
129129
where
130130
C: Connect + Clone + Send + Sync + 'static,
131-
B: Body + Send + 'static,
131+
B: Body + Send + 'static + Unpin,
132132
B::Data: Send,
133133
B::Error: Into<Box<dyn StdError + Send + Sync>>,
134134
{
@@ -458,7 +458,8 @@ where
458458
fn connect_to(
459459
&self,
460460
pool_key: PoolKey,
461-
) -> impl Lazy<Output = Result<pool::Pooled<PoolClient<B>, PoolKey>, Error>> + Unpin {
461+
) -> impl Lazy<Output = Result<pool::Pooled<PoolClient<B>, PoolKey>, Error>> + Send + Unpin
462+
{
462463
let executor = self.exec.clone();
463464
let pool = self.pool.clone();
464465
#[cfg(feature = "http1")]
@@ -574,7 +575,7 @@ where
574575
impl<C, B> tower_service::Service<Request<B>> for Client<C, B>
575576
where
576577
C: Connect + Clone + Send + Sync + 'static,
577-
B: Body + Send + 'static,
578+
B: Body + Send + 'static + Unpin,
578579
B::Data: Send,
579580
B::Error: Into<Box<dyn StdError + Send + Sync>>,
580581
{
@@ -594,7 +595,7 @@ where
594595
impl<C, B> tower_service::Service<Request<B>> for &'_ Client<C, B>
595596
where
596597
C: Connect + Clone + Send + Sync + 'static,
597-
B: Body + Send + 'static,
598+
B: Body + Send + 'static + Unpin,
598599
B::Data: Send,
599600
B::Error: Into<Box<dyn StdError + Send + Sync>>,
600601
{
@@ -955,7 +956,7 @@ pub struct Builder {
955956
#[cfg(feature = "http1")]
956957
h1_builder: hyper::client::conn::http1::Builder,
957958
#[cfg(feature = "http2")]
958-
h2_builder: hyper::client::conn::http2::Builder,
959+
h2_builder: hyper::client::conn::http2::Builder<Exec>,
959960
pool_config: pool::Config,
960961
}
961962

@@ -965,18 +966,18 @@ impl Builder {
965966
where
966967
E: hyper::rt::Executor<BoxSendFuture> + Send + Sync + Clone + 'static,
967968
{
968-
let exec = Exec::new(executor.clone());
969+
let exec = Exec::new(executor);
969970
Self {
970971
client_config: Config {
971972
retry_canceled_requests: true,
972973
set_host: true,
973974
ver: Ver::Auto,
974975
},
975-
exec,
976+
exec: exec.clone(),
976977
#[cfg(feature = "http1")]
977978
h1_builder: hyper::client::conn::http1::Builder::new(),
978979
#[cfg(feature = "http2")]
979-
h2_builder: hyper::client::conn::http2::Builder::new(executor),
980+
h2_builder: hyper::client::conn::http2::Builder::new(exec),
980981
pool_config: pool::Config {
981982
idle_timeout: Some(Duration::from_secs(90)),
982983
max_idle_per_host: std::usize::MAX,

src/common/exec.rs

+9
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,12 @@ impl fmt::Debug for Exec {
5454
f.debug_struct("Exec").finish()
5555
}
5656
}
57+
58+
impl<F> hyper::rt::Executor<F> for Exec
59+
where
60+
F: Future<Output = ()> + Send + 'static,
61+
{
62+
fn execute(&self, fut: F) {
63+
Exec::execute(self, fut);
64+
}
65+
}

src/rt/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
33
/// Implementation of [`hyper::rt::Executor`] that utilises [`tokio::spawn`].
44
pub mod tokio_executor;
5+
mod tokio_io;
56

67
pub use tokio_executor::TokioExecutor;
8+
pub use tokio_io::TokioIo;

0 commit comments

Comments
 (0)