@@ -5,13 +5,13 @@ use std::fmt;
5
5
use std:: intrinsics:: TypeId ;
6
6
use std:: io:: { IoResult , IoError , ConnectionAborted , InvalidInput , OtherIoError ,
7
7
Stream , Listener , Acceptor } ;
8
- use std:: io:: net:: ip:: { SocketAddr , ToSocketAddr } ;
8
+ use std:: io:: net:: ip:: { SocketAddr , ToSocketAddr , Port } ;
9
9
use std:: io:: net:: tcp:: { TcpStream , TcpListener , TcpAcceptor } ;
10
10
use std:: mem:: { mod, transmute, transmute_copy} ;
11
11
use std:: raw:: { mod, TraitObject } ;
12
12
13
13
use uany:: UncheckedBoxAnyDowncast ;
14
- use openssl:: ssl:: { SslStream , SslContext } ;
14
+ use openssl:: ssl:: { SslStream , SslContext , Ssl } ;
15
15
use openssl:: ssl:: SslMethod :: Sslv23 ;
16
16
use openssl:: ssl:: error:: { SslError , StreamError , OpenSslErrors , SslSessionClosed } ;
17
17
@@ -62,7 +62,7 @@ impl<T: NetworkStream + Send + Clone> StreamClone for T {
62
62
/// A connector creates a NetworkStream.
63
63
pub trait NetworkConnector < S : NetworkStream > {
64
64
/// Connect to a remote address.
65
- fn connect < To : ToSocketAddr > ( & mut self , addr : To , scheme : & str ) -> IoResult < S > ;
65
+ fn connect ( & mut self , host : & str , port : Port , scheme : & str ) -> IoResult < S > ;
66
66
}
67
67
68
68
impl fmt:: Show for Box < NetworkStream + Send > {
@@ -239,7 +239,8 @@ impl NetworkStream for HttpStream {
239
239
pub struct HttpConnector ;
240
240
241
241
impl NetworkConnector < HttpStream > for HttpConnector {
242
- fn connect < To : ToSocketAddr > ( & mut self , addr : To , scheme : & str ) -> IoResult < HttpStream > {
242
+ fn connect ( & mut self , host : & str , port : Port , scheme : & str ) -> IoResult < HttpStream > {
243
+ let addr = ( host, port) ;
243
244
match scheme {
244
245
"http" => {
245
246
debug ! ( "http scheme" ) ;
@@ -249,7 +250,11 @@ impl NetworkConnector<HttpStream> for HttpConnector {
249
250
debug ! ( "https scheme" ) ;
250
251
let stream = try!( TcpStream :: connect ( addr) ) ;
251
252
let context = try!( SslContext :: new ( Sslv23 ) . map_err ( lift_ssl_error) ) ;
252
- let stream = try!( SslStream :: new ( & context, stream) . map_err ( lift_ssl_error) ) ;
253
+ let ssl = try!( Ssl :: new ( & context) . map_err ( lift_ssl_error) ) ;
254
+ debug ! ( "ssl set_hostname = {}" , host) ;
255
+ try!( ssl. set_hostname ( host) . map_err ( lift_ssl_error) ) ;
256
+ debug ! ( "ssl set_hostname done" ) ;
257
+ let stream = try!( SslStream :: new_from ( ssl, stream) . map_err ( lift_ssl_error) ) ;
253
258
Ok ( Https ( stream) )
254
259
} ,
255
260
_ => {
@@ -264,6 +269,7 @@ impl NetworkConnector<HttpStream> for HttpConnector {
264
269
}
265
270
266
271
fn lift_ssl_error ( ssl : SslError ) -> IoError {
272
+ debug ! ( "lift_ssl_error: {}" , ssl) ;
267
273
match ssl {
268
274
StreamError ( err) => err,
269
275
SslSessionClosed => IoError {
0 commit comments