Skip to content

Commit 319e8ae

Browse files
committed
feat(client): remove Destination for http::Uri in connectors
BREAKING CHANGE: All usage of `hyper::client::connect::Destination` should be replaced with `http::Uri`.
1 parent 9645a12 commit 319e8ae

File tree

6 files changed

+40
-430
lines changed

6 files changed

+40
-430
lines changed

benches/connect.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ extern crate test;
55

66
use std::net::SocketAddr;
77
use tokio::net::TcpListener;
8-
use hyper::client::connect::{Destination, HttpConnector};
8+
use hyper::client::connect::{HttpConnector};
99
use hyper::service::Service;
1010
use http::Uri;
1111

@@ -19,8 +19,7 @@ fn http_connector(b: &mut test::Bencher) {
1919
.expect("rt build");
2020
let mut listener = rt.block_on(TcpListener::bind(&SocketAddr::from(([127, 0, 0, 1], 0)))).expect("bind");
2121
let addr = listener.local_addr().expect("local_addr");
22-
let uri: Uri = format!("http://{}/", addr).parse().expect("uri parse");
23-
let dst = Destination::try_from_uri(uri).expect("destination");
22+
let dst: Uri = format!("http://{}/", addr).parse().expect("uri parse");
2423
let mut connector = HttpConnector::new();
2524

2625
rt.spawn(async move {

src/client/connect/dns.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -391,11 +391,10 @@ mod tests {
391391

392392
#[test]
393393
fn ip_addrs_try_parse_v6() {
394-
let uri = ::http::Uri::from_static("http://[::1]:8080/");
395-
let dst = super::super::Destination { uri };
394+
let dst = ::http::Uri::from_static("http://[::1]:8080/");
396395

397396
let mut addrs =
398-
IpAddrs::try_parse(dst.host(), dst.port().expect("port")).expect("try_parse");
397+
IpAddrs::try_parse(dst.host().expect("host"), dst.port_u16().expect("port")).expect("try_parse");
399398

400399
let expected = "[::1]:8080".parse::<SocketAddr>().expect("expected");
401400

src/client/connect/http.rs

+16-36
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use tokio::net::TcpStream;
1717
use tokio::time::Delay;
1818

1919
use super::dns::{self, resolve, GaiResolver, Resolve};
20-
use super::{Connected, Destination};
20+
use super::{Connected};
2121
//#[cfg(feature = "runtime")] use super::dns::TokioThreadpoolGaiResolver;
2222

2323

@@ -229,7 +229,7 @@ impl<R: fmt::Debug> fmt::Debug for HttpConnector<R> {
229229
}
230230
}
231231

232-
impl<R> tower_service::Service<Destination> for HttpConnector<R>
232+
impl<R> tower_service::Service<Uri> for HttpConnector<R>
233233
where
234234
R: Resolve + Clone + Send + Sync + 'static,
235235
R::Future: Send,
@@ -243,7 +243,7 @@ where
243243
Poll::Ready(Ok(()))
244244
}
245245

246-
fn call(&mut self, dst: Destination) -> Self::Future {
246+
fn call(&mut self, dst: Uri) -> Self::Future {
247247
let mut self_ = self.clone();
248248
HttpConnecting {
249249
fut: Box::pin(async move { self_.call_async(dst).await }),
@@ -258,30 +258,30 @@ where
258258
{
259259
async fn call_async(
260260
&mut self,
261-
dst: Destination,
261+
dst: Uri,
262262
) -> Result<(TcpStream, Connected), ConnectError> {
263263
trace!(
264-
"Http::connect; scheme={}, host={}, port={:?}",
264+
"Http::connect; scheme={:?}, host={:?}, port={:?}",
265265
dst.scheme(),
266266
dst.host(),
267267
dst.port(),
268268
);
269269

270270
if self.config.enforce_http {
271-
if dst.uri.scheme() != Some(&Scheme::HTTP) {
271+
if dst.scheme() != Some(&Scheme::HTTP) {
272272
return Err(ConnectError {
273273
msg: INVALID_NOT_HTTP.into(),
274274
cause: None,
275275
});
276276
}
277-
} else if dst.uri.scheme().is_none() {
277+
} else if dst.scheme().is_none() {
278278
return Err(ConnectError {
279279
msg: INVALID_MISSING_SCHEME.into(),
280280
cause: None,
281281
});
282282
}
283283

284-
let host = match dst.uri.host() {
284+
let host = match dst.host() {
285285
Some(s) => s,
286286
None => {
287287
return Err(ConnectError {
@@ -290,9 +290,9 @@ where
290290
})
291291
}
292292
};
293-
let port = match dst.uri.port() {
293+
let port = match dst.port() {
294294
Some(port) => port.as_u16(),
295-
None => if dst.uri.scheme() == Some(&Scheme::HTTPS) { 443 } else { 80 },
295+
None => if dst.scheme() == Some(&Scheme::HTTPS) { 443 } else { 80 },
296296
};
297297

298298
let config = &self.config;
@@ -351,26 +351,6 @@ where
351351
}
352352
}
353353

354-
impl<R> tower_service::Service<Uri> for HttpConnector<R>
355-
where
356-
R: Resolve + Clone + Send + Sync + 'static,
357-
R::Future: Send,
358-
{
359-
type Response = TcpStream;
360-
type Error = ConnectError;
361-
type Future =
362-
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
363-
364-
fn poll_ready(&mut self, cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
365-
tower_service::Service::<Destination>::poll_ready(self, cx)
366-
}
367-
368-
fn call(&mut self, uri: Uri) -> Self::Future {
369-
let mut self_ = self.clone();
370-
Box::pin(async move { self_.call_async(Destination { uri }).await.map(|(s, _)| s) })
371-
}
372-
}
373-
374354
impl HttpInfo {
375355
/// Get the remote address of the transport used.
376356
pub fn remote_addr(&self) -> SocketAddr {
@@ -661,12 +641,14 @@ impl ConnectingTcp {
661641
mod tests {
662642
use std::io;
663643

644+
use ::http::Uri;
645+
664646
use super::super::sealed::Connect;
665-
use super::{Connected, Destination, HttpConnector};
647+
use super::{Connected, HttpConnector};
666648

667649
async fn connect<C>(
668650
connector: C,
669-
dst: Destination,
651+
dst: Uri,
670652
) -> Result<(C::Transport, Connected), C::Error>
671653
where
672654
C: Connect,
@@ -676,8 +658,7 @@ mod tests {
676658

677659
#[tokio::test]
678660
async fn test_errors_enforce_http() {
679-
let uri = "https://example.domain/foo/bar?baz".parse().unwrap();
680-
let dst = Destination { uri };
661+
let dst = "https://example.domain/foo/bar?baz".parse().unwrap();
681662
let connector = HttpConnector::new();
682663

683664
let err = connect(connector, dst).await.unwrap_err();
@@ -686,8 +667,7 @@ mod tests {
686667

687668
#[tokio::test]
688669
async fn test_errors_missing_scheme() {
689-
let uri = "example.domain".parse().unwrap();
690-
let dst = Destination { uri };
670+
let dst = "example.domain".parse().unwrap();
691671
let mut connector = HttpConnector::new();
692672
connector.enforce_http(false);
693673

0 commit comments

Comments
 (0)