mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-24 05:17:05 +00:00
Move parsing http retries to EnvironmentOptions (#16284)
## Summary - Move parsing `UV_HTTP_RETRIES` to `EnvironmentOptions` Relates https://github.com/astral-sh/uv/issues/14720 ## Test Plan - Tests with existing tests
This commit is contained in:
parent
29cec24d5c
commit
51e8da2d1c
19 changed files with 123 additions and 91 deletions
|
|
@ -44,7 +44,6 @@ use crate::middleware::OfflineMiddleware;
|
|||
use crate::tls::read_identity;
|
||||
use crate::{Connectivity, WrappedReqwestError};
|
||||
|
||||
/// Do not use this value directly outside tests, use [`retries_from_env`] instead.
|
||||
pub const DEFAULT_RETRIES: u32 = 3;
|
||||
|
||||
/// Maximum number of redirects to follow before giving up.
|
||||
|
|
@ -154,11 +153,13 @@ impl BaseClientBuilder<'_> {
|
|||
allow_insecure_host: Vec<TrustedHost>,
|
||||
preview: Preview,
|
||||
timeout: Duration,
|
||||
retries: u32,
|
||||
) -> Self {
|
||||
Self {
|
||||
preview,
|
||||
allow_insecure_host,
|
||||
native_tls,
|
||||
retries,
|
||||
connectivity,
|
||||
timeout,
|
||||
..Self::default()
|
||||
|
|
@ -202,15 +203,6 @@ impl<'a> BaseClientBuilder<'a> {
|
|||
self
|
||||
}
|
||||
|
||||
/// Read the retry count from [`EnvVars::UV_HTTP_RETRIES`] if set, otherwise use the default
|
||||
/// retries.
|
||||
///
|
||||
/// Errors when [`EnvVars::UV_HTTP_RETRIES`] is not a valid u32.
|
||||
pub fn retries_from_env(mut self) -> Result<Self, RetryParsingError> {
|
||||
self.retries = retries_from_env()?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn native_tls(mut self, native_tls: bool) -> Self {
|
||||
self.native_tls = native_tls;
|
||||
|
|
@ -292,7 +284,7 @@ impl<'a> BaseClientBuilder<'a> {
|
|||
}
|
||||
|
||||
/// Create a [`RetryPolicy`] for the client.
|
||||
fn retry_policy(&self) -> ExponentialBackoff {
|
||||
pub fn retry_policy(&self) -> ExponentialBackoff {
|
||||
let mut builder = ExponentialBackoff::builder();
|
||||
if env::var_os(EnvVars::UV_TEST_NO_HTTP_RETRY_DELAY).is_some() {
|
||||
builder = builder.retry_bounds(Duration::from_millis(0), Duration::from_millis(0));
|
||||
|
|
@ -1093,19 +1085,6 @@ pub enum RetryParsingError {
|
|||
ParseInt(#[from] ParseIntError),
|
||||
}
|
||||
|
||||
/// Read the retry count from [`EnvVars::UV_HTTP_RETRIES`] if set, otherwise, make no change.
|
||||
///
|
||||
/// Errors when [`EnvVars::UV_HTTP_RETRIES`] is not a valid u32.
|
||||
pub fn retries_from_env() -> Result<u32, RetryParsingError> {
|
||||
// TODO(zanieb): We should probably parse this in another layer, but there's not a natural
|
||||
// fit for it right now
|
||||
if let Some(value) = env::var_os(EnvVars::UV_HTTP_RETRIES) {
|
||||
Ok(value.to_string_lossy().as_ref().parse::<u32>()?)
|
||||
} else {
|
||||
Ok(DEFAULT_RETRIES)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
pub use base_client::{
|
||||
AuthIntegration, BaseClient, BaseClientBuilder, DEFAULT_RETRIES, ExtraMiddleware,
|
||||
RedirectClientWithMiddleware, RequestBuilder, RetryParsingError, UvRetryableStrategy,
|
||||
is_transient_network_error, retries_from_env,
|
||||
is_transient_network_error,
|
||||
};
|
||||
pub use cached_client::{CacheControl, CachedClient, CachedClientError, DataWithCachePolicy};
|
||||
pub use error::{Error, ErrorKind, WrappedReqwestError};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue