Support setting request timeout with UV_HTTP_TIMEOUT and HTTP_TIMEOUT (#1780)

Follow-up to #1694 matching Cargo's environment variable names


https://doc.rust-lang.org/nightly/cargo/reference/config.html#httptimeout
This commit is contained in:
Zanie Blue 2024-02-20 18:48:18 -06:00 committed by GitHub
parent d07b587f3f
commit 3cd51ffc92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -88,17 +88,17 @@ impl RegistryClientBuilder {
pub fn build(self) -> RegistryClient {
let client_raw = self.client.unwrap_or_else(|| {
// Get pip timeout from env var
// Timeout options, matching https://doc.rust-lang.org/nightly/cargo/reference/config.html#httptimeout
// `UV_REQUEST_TIMEOUT` is provided for backwards compatibility with v0.1.6
let default_timeout = 5 * 60;
let timeout = env::var("UV_REQUEST_TIMEOUT")
.map_err(|_| default_timeout)
.and_then(|value| {
value.parse::<u64>()
.map_err(|_| {
warn_user_once!("Ignoring invalid value for UV_REQUEST_TIMEOUT. Expected integer number of seconds, got {value}.");
default_timeout
})
}).unwrap_or(default_timeout);
let timeout = env::var("UV_HTTP_TIMEOUT").or_else(|_| env::var("UV_REQUEST_TIMEOUT")).or_else(|_| env::var("HTTP_TIMEOUT")).and_then(|value| {
value.parse::<u64>()
.or_else(|_| {
// On parse error, warn and use the default timeout
warn_user_once!("Ignoring invalid value from environment for UV_REQUEST_TIMEOUT. Expected integer number of seconds, got \"{value}\".");
Ok(default_timeout)
})
}).unwrap_or(default_timeout);
debug!("Using registry request timeout of {}s", timeout);
// Disallow any connections.
let client_core = ClientBuilder::new()