@@ -358,8 +358,12 @@ pub fn needs_custom_http_transport(config: &Config) -> CargoResult<bool> {
358358 let timeout = http_timeout ( config) ?;
359359 let cainfo = config. get_path ( "http.cainfo" ) ?;
360360 let check_revoke = config. get_bool ( "http.check-revoke" ) ?;
361+ let user_agent = config. get_string ( "http.user-agent" ) ?;
361362
362- Ok ( proxy_exists || timeout. is_some ( ) || cainfo. is_some ( ) || check_revoke. is_some ( ) )
363+ Ok (
364+ proxy_exists || timeout. is_some ( ) || cainfo. is_some ( ) || check_revoke. is_some ( )
365+ || user_agent. is_some ( ) ,
366+ )
363367}
364368
365369/// Configure a libcurl http handle with the defaults options for Cargo
@@ -371,7 +375,6 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
371375 handle. connect_timeout ( Duration :: new ( 30 , 0 ) ) ?;
372376 handle. low_speed_limit ( 10 /* bytes per second */ ) ?;
373377 handle. low_speed_time ( Duration :: new ( 30 , 0 ) ) ?;
374- handle. useragent ( & version ( ) . to_string ( ) ) ?;
375378 if let Some ( proxy) = http_proxy ( config) ? {
376379 handle. proxy ( & proxy) ?;
377380 }
@@ -385,6 +388,11 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
385388 handle. connect_timeout ( Duration :: new ( timeout as u64 , 0 ) ) ?;
386389 handle. low_speed_time ( Duration :: new ( timeout as u64 , 0 ) ) ?;
387390 }
391+ if let Some ( user_agent) = config. get_string ( "http.user-agent" ) ? {
392+ handle. useragent ( & user_agent. val ) ?;
393+ } else {
394+ handle. useragent ( & version ( ) . to_string ( ) ) ?;
395+ }
388396 Ok ( ( ) )
389397}
390398
0 commit comments