@@ -8,6 +8,7 @@ use stream::MaybeHttpsStream;
8
8
use tokio_core:: reactor:: Handle ;
9
9
use tokio_rustls:: ClientConfigExt ;
10
10
use tokio_service:: Service ;
11
+ use webpki:: { DNSName , DNSNameRef } ;
11
12
use webpki_roots;
12
13
use ct_logs;
13
14
@@ -26,9 +27,14 @@ impl HttpsConnector {
26
27
let mut http = HttpConnector :: new ( threads, handle) ;
27
28
http. enforce_http ( false ) ;
28
29
let mut config = ClientConfig :: new ( ) ;
29
- config. root_store . add_server_trust_anchors ( & webpki_roots:: TLS_SERVER_ROOTS ) ;
30
+ config
31
+ . root_store
32
+ . add_server_trust_anchors ( & webpki_roots:: TLS_SERVER_ROOTS ) ;
30
33
config. ct_logs = Some ( & ct_logs:: LOGS ) ;
31
- HttpsConnector { http : http, tls_config : Arc :: new ( config) }
34
+ HttpsConnector {
35
+ http : http,
36
+ tls_config : Arc :: new ( config) ,
37
+ }
32
38
}
33
39
}
34
40
@@ -55,36 +61,42 @@ impl Service for HttpsConnector {
55
61
56
62
fn call ( & self , uri : Uri ) -> Self :: Future {
57
63
let is_https = uri. scheme ( ) == Some ( "https" ) ;
58
- let host = match uri. host ( ) {
59
- Some ( host) => host. to_owned ( ) ,
60
- None => return HttpsConnecting (
61
- Box :: new (
62
- :: futures:: future:: err (
63
- io:: Error :: new (
64
- io:: ErrorKind :: InvalidInput ,
65
- "invalid url, missing host"
66
- )
67
- )
68
- )
69
- ) ,
64
+ let host: DNSName = match uri. host ( ) {
65
+ Some ( host) => match DNSNameRef :: try_from_ascii_str ( host) {
66
+ Ok ( host) => host. into ( ) ,
67
+ Err ( err) => {
68
+ return HttpsConnecting ( Box :: new ( :: futures:: future:: err ( io:: Error :: new (
69
+ io:: ErrorKind :: InvalidInput ,
70
+ format ! ( "invalid url: {:?}" , err) ,
71
+ ) ) ) )
72
+ }
73
+ } ,
74
+ None => {
75
+ return HttpsConnecting ( Box :: new ( :: futures:: future:: err ( io:: Error :: new (
76
+ io:: ErrorKind :: InvalidInput ,
77
+ "invalid url, missing host" ,
78
+ ) ) ) )
79
+ }
70
80
} ;
71
81
let connecting = self . http . call ( uri) ;
72
82
73
83
HttpsConnecting ( if is_https {
74
84
let tls = self . tls_config . clone ( ) ;
75
- Box :: new ( connecting. and_then ( move |tcp| {
76
- tls
77
- . connect_async ( & host, tcp)
78
- . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: Other , e) )
79
- } ) . map ( |tls| MaybeHttpsStream :: Https ( tls) )
80
- . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: Other , e) ) )
85
+ Box :: new (
86
+ connecting
87
+ . and_then ( move |tcp| {
88
+ tls. connect_async ( host. as_ref ( ) , tcp)
89
+ . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: Other , e) )
90
+ } )
91
+ . map ( |tls| MaybeHttpsStream :: Https ( tls) )
92
+ . map_err ( |e| io:: Error :: new ( io:: ErrorKind :: Other , e) ) ,
93
+ )
81
94
} else {
82
95
Box :: new ( connecting. map ( |tcp| MaybeHttpsStream :: Http ( tcp) ) )
83
96
} )
84
97
}
85
98
}
86
99
87
-
88
100
pub struct HttpsConnecting ( Box < Future < Item = MaybeHttpsStream , Error = io:: Error > > ) ;
89
101
90
102
impl Future for HttpsConnecting {
0 commit comments