@@ -408,34 +408,26 @@ pub fn http_handle_and_timeout(config: &Config) -> CargoResult<(Easy, HttpTimeou
408
408
}
409
409
410
410
pub fn needs_custom_http_transport ( config : & Config ) -> CargoResult < bool > {
411
- let proxy_exists = http_proxy_exists ( config) ?;
412
- let timeout = HttpTimeout :: new ( config) ?. is_non_default ( ) ;
413
- let cainfo = config. get_path ( "http.cainfo" ) ?;
414
- let check_revoke = config. get_bool ( "http.check-revoke" ) ?;
415
- let user_agent = config. get_string ( "http.user-agent" ) ?;
416
- let ssl_version = config. get :: < Option < SslVersionConfig > > ( "http.ssl-version" ) ?;
417
-
418
- Ok ( proxy_exists
419
- || timeout
420
- || cainfo. is_some ( )
421
- || check_revoke. is_some ( )
422
- || user_agent. is_some ( )
423
- || ssl_version. is_some ( ) )
411
+ Ok ( http_proxy_exists ( config) ?
412
+ || * config. http_config ( ) ? != Default :: default ( )
413
+ || env:: var_os ( "HTTP_TIMEOUT" ) . is_some ( ) )
424
414
}
425
415
426
416
/// Configure a libcurl http handle with the defaults options for Cargo
427
417
pub fn configure_http_handle ( config : & Config , handle : & mut Easy ) -> CargoResult < HttpTimeout > {
418
+ let http = config. http_config ( ) ?;
428
419
if let Some ( proxy) = http_proxy ( config) ? {
429
420
handle. proxy ( & proxy) ?;
430
421
}
431
- if let Some ( cainfo) = config. get_path ( "http.cainfo" ) ? {
432
- handle. cainfo ( & cainfo. val ) ?;
422
+ if let Some ( cainfo) = http. cainfo . clone ( ) {
423
+ let cainfo = cainfo. resolve ( config) ;
424
+ handle. cainfo ( & cainfo) ?;
433
425
}
434
- if let Some ( check) = config . get_bool ( " http.check-revoke" ) ? {
435
- handle. ssl_options ( SslOpt :: new ( ) . no_revoke ( !check. val ) ) ?;
426
+ if let Some ( check) = http. check_revoke {
427
+ handle. ssl_options ( SslOpt :: new ( ) . no_revoke ( !check) ) ?;
436
428
}
437
- if let Some ( user_agent) = config . get_string ( " http.user-agent" ) ? {
438
- handle. useragent ( & user_agent. val ) ?;
429
+ if let Some ( user_agent) = & http. user_agent {
430
+ handle. useragent ( user_agent) ?;
439
431
} else {
440
432
handle. useragent ( & version ( ) . to_string ( ) ) ?;
441
433
}
@@ -456,7 +448,7 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
456
448
} ;
457
449
Ok ( version)
458
450
}
459
- if let Some ( ssl_version) = config . get :: < Option < SslVersionConfig > > ( "http.ssl-version" ) ? {
451
+ if let Some ( ssl_version) = & http_config . ssl_version {
460
452
match ssl_version {
461
453
SslVersionConfig :: Single ( s) => {
462
454
let version = to_ssl_version ( s. as_str ( ) ) ?;
@@ -472,7 +464,7 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
472
464
}
473
465
}
474
466
475
- if let Some ( true ) = config . get :: < Option < bool > > ( " http.debug" ) ? {
467
+ if let Some ( true ) = http. debug {
476
468
handle. verbose ( true ) ?;
477
469
handle. debug_function ( |kind, data| {
478
470
let ( prefix, level) = match kind {
@@ -513,11 +505,10 @@ pub struct HttpTimeout {
513
505
514
506
impl HttpTimeout {
515
507
pub fn new ( config : & Config ) -> CargoResult < HttpTimeout > {
516
- let low_speed_limit = config
517
- . get :: < Option < u32 > > ( "http.low-speed-limit" ) ?
518
- . unwrap_or ( 10 ) ;
508
+ let config = config. http_config ( ) ?;
509
+ let low_speed_limit = config. low_speed_limit . unwrap_or ( 10 ) ;
519
510
let seconds = config
520
- . get :: < Option < u64 > > ( "http. timeout" ) ?
511
+ . timeout
521
512
. or_else ( || env:: var ( "HTTP_TIMEOUT" ) . ok ( ) . and_then ( |s| s. parse ( ) . ok ( ) ) )
522
513
. unwrap_or ( 30 ) ;
523
514
Ok ( HttpTimeout {
@@ -526,10 +517,6 @@ impl HttpTimeout {
526
517
} )
527
518
}
528
519
529
- fn is_non_default ( & self ) -> bool {
530
- self . dur != Duration :: new ( 30 , 0 ) || self . low_speed_limit != 10
531
- }
532
-
533
520
pub fn configure ( & self , handle : & mut Easy ) -> CargoResult < ( ) > {
534
521
// The timeout option for libcurl by default times out the entire
535
522
// transfer, but we probably don't want this. Instead we only set
@@ -548,8 +535,9 @@ impl HttpTimeout {
548
535
/// Favor cargo's `http.proxy`, then git's `http.proxy`. Proxies specified
549
536
/// via environment variables are picked up by libcurl.
550
537
fn http_proxy ( config : & Config ) -> CargoResult < Option < String > > {
551
- if let Some ( s) = config. get_string ( "http.proxy" ) ? {
552
- return Ok ( Some ( s. val ) ) ;
538
+ let http = config. http_config ( ) ?;
539
+ if let Some ( s) = & http. proxy {
540
+ return Ok ( Some ( s. clone ( ) ) ) ;
553
541
}
554
542
if let Ok ( cfg) = git2:: Config :: open_default ( ) {
555
543
if let Ok ( s) = cfg. get_str ( "http.proxy" ) {
0 commit comments