@@ -336,7 +336,7 @@ pub(crate) fn connect_https(unit: &Unit, hostname: &str) -> Result<Stream, Error
336
336
let ( sock, remote_addr) = connect_host ( unit, hostname, port) ?;
337
337
338
338
let tls_conf = & unit. agent . config . tls_config ;
339
- let https_stream = tls_conf. connect ( hostname, Box :: new ( sock) ) ?;
339
+ let https_stream = tls_conf. connect ( hostname, sock) ?;
340
340
let pool_key = PoolKey :: from_parts ( "https" , hostname, port) ;
341
341
let pool_returner = PoolReturner :: new ( & unit. agent , pool_key) ;
342
342
Ok ( Stream :: new ( https_stream, remote_addr, pool_returner) )
@@ -347,7 +347,7 @@ pub(crate) fn connect_host(
347
347
unit : & Unit ,
348
348
hostname : & str ,
349
349
port : u16 ,
350
- ) -> Result < ( TcpStream , SocketAddr ) , Error > {
350
+ ) -> Result < ( Box < dyn ReadWrite > , SocketAddr ) , Error > {
351
351
let connect_deadline: Option < Instant > =
352
352
if let Some ( timeout_connect) = unit. agent . config . timeout_connect {
353
353
Instant :: now ( ) . checked_add ( timeout_connect)
@@ -395,7 +395,8 @@ pub(crate) fn connect_host(
395
395
396
396
// connect with a configured timeout.
397
397
#[ allow( clippy:: unnecessary_unwrap) ]
398
- let stream = if proto. is_some ( ) && Some ( Proto :: HTTP ) != proto {
398
+ let stream = if proto. is_some ( ) && Some ( Proto :: HTTP ) != proto && Some ( Proto :: HTTPS ) != proto
399
+ {
399
400
connect_socks (
400
401
unit,
401
402
proxy. clone ( ) . unwrap ( ) ,
@@ -419,7 +420,7 @@ pub(crate) fn connect_host(
419
420
}
420
421
}
421
422
422
- let ( mut stream, remote_addr) = if let Some ( stream_and_addr) = any_stream_and_addr {
423
+ let ( stream, remote_addr) = if let Some ( stream_and_addr) = any_stream_and_addr {
423
424
stream_and_addr
424
425
} else if let Some ( e) = any_err {
425
426
return Err ( ErrorKind :: ConnectionFailed . msg ( "Connect error" ) . src ( e) ) ;
@@ -441,26 +442,38 @@ pub(crate) fn connect_host(
441
442
stream. set_write_timeout ( unit. agent . config . timeout_write ) ?;
442
443
}
443
444
444
- if proto == Some ( Proto :: HTTP ) && unit. url . scheme ( ) == "https" {
445
+ if ( proto == Some ( Proto :: HTTP ) || proto == Some ( Proto :: HTTPS ) ) && unit. url . scheme ( ) == "https" {
445
446
if let Some ( ref proxy) = proxy {
447
+ let stream = stream. try_clone ( ) ?;
448
+ let mut s;
449
+ if proto == Some ( Proto :: HTTPS ) {
450
+ s = unit
451
+ . agent
452
+ . config
453
+ . tls_config
454
+ . connect ( & proxy. server , Box :: new ( stream) ) ?;
455
+ } else {
456
+ s = Box :: new ( stream) ;
457
+ }
446
458
write ! (
447
- stream ,
459
+ s ,
448
460
"{}" ,
449
461
proxy. connect( hostname, port, & unit. agent. config. user_agent)
450
462
)
451
463
. unwrap ( ) ;
452
- stream . flush ( ) ?;
464
+ s . flush ( ) ?;
453
465
454
- let s = stream . try_clone ( ) ?;
466
+ // let s = s .try_clone()?; FIXME enable something like this so that we can return the stream
455
467
let pool_key = PoolKey :: from_parts ( unit. url . scheme ( ) , hostname, port) ;
456
468
let pool_returner = PoolReturner :: new ( & unit. agent , pool_key) ;
457
469
let s = Stream :: new ( s, remote_addr, pool_returner) ;
458
470
let response = Response :: do_from_stream ( s, unit. clone ( ) ) ?;
459
471
Proxy :: verify_response ( & response) ?;
472
+ // TODO! return Ok((Box::new(s), remote_addr)) otherwise this tunnel is not used
460
473
}
461
474
}
462
475
463
- Ok ( ( stream, remote_addr) )
476
+ Ok ( ( Box :: new ( stream) , remote_addr) )
464
477
}
465
478
466
479
#[ cfg( feature = "socks-proxy" ) ]
0 commit comments