mirror of
https://github.com/TrueLayer/reqwest-middleware.git
synced 2024-12-25 18:36:30 +00:00
parent
3604b1436b
commit
9c17d2f215
3 changed files with 11 additions and 23 deletions
|
@ -15,6 +15,7 @@ multipart = ["reqwest/multipart"]
|
|||
json = ["reqwest/json"]
|
||||
charset = ["reqwest/charset"]
|
||||
http2 = ["reqwest/http2"]
|
||||
rustls-tls = ["reqwest/rustls-tls"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.0"
|
||||
|
|
|
@ -9,26 +9,20 @@ license = "MIT OR Apache-2.0"
|
|||
keywords = ["reqwest", "http", "middleware", "retry"]
|
||||
categories = ["web-programming::http-client"]
|
||||
|
||||
[features]
|
||||
default = ["tracing"]
|
||||
log = ["dep:log"]
|
||||
tracing = ["dep:tracing"]
|
||||
|
||||
[dependencies]
|
||||
reqwest-middleware = { version = "0.3.0", path = "../reqwest-middleware" }
|
||||
|
||||
anyhow = "1.0.0"
|
||||
async-trait = "0.1.51"
|
||||
futures = "0.3.0"
|
||||
log = { version = "0.4.22", optional = true }
|
||||
http = "1.0"
|
||||
reqwest = { version = "0.12.0", default-features = false }
|
||||
retry-policies = "0.4"
|
||||
tracing = { version = "0.1.26", optional = true }
|
||||
tracing = "0.1.26"
|
||||
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
hyper = "1.0"
|
||||
tokio = { version = "1.6.0", default-features = false, features = ["time"] }
|
||||
tokio = { version = "1.6.0", features = ["time"] }
|
||||
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
parking_lot = { version = "0.11.2", features = ["wasm-bindgen"] } # work around https://github.com/tomaka/wasm-timer/issues/14
|
||||
|
|
|
@ -9,22 +9,17 @@ use reqwest::{Request, Response};
|
|||
use reqwest_middleware::{Error, Middleware, Next, Result};
|
||||
use retry_policies::RetryPolicy;
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
type LogLevel = ::tracing::Level;
|
||||
#[cfg(all(feature = "log", not(feature = "tracing")))]
|
||||
type LogLevel = ::log::Level;
|
||||
|
||||
#[doc(hidden)]
|
||||
// We need this macro because tracing expects the level to be const:
|
||||
// https://github.com/tokio-rs/tracing/issues/2730
|
||||
macro_rules! log_retry {
|
||||
($level:expr, $($args:tt)*) => {{
|
||||
match $level {
|
||||
LogLevel::TRACE => ::tracing::trace!($($args)*),
|
||||
LogLevel::DEBUG => ::tracing::debug!($($args)*),
|
||||
LogLevel::INFO => ::tracing::info!($($args)*),
|
||||
LogLevel::WARN => ::tracing::warn!($($args)*),
|
||||
LogLevel::ERROR => ::tracing::error!($($args)*),
|
||||
::tracing::Level::TRACE => ::tracing::trace!($($args)*),
|
||||
::tracing::Level::DEBUG => ::tracing::debug!($($args)*),
|
||||
::tracing::Level::INFO => ::tracing::info!($($args)*),
|
||||
::tracing::Level::WARN => ::tracing::warn!($($args)*),
|
||||
::tracing::Level::ERROR => ::tracing::error!($($args)*),
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
@ -74,8 +69,7 @@ pub struct RetryTransientMiddleware<
|
|||
> {
|
||||
retry_policy: T,
|
||||
retryable_strategy: R,
|
||||
#[cfg(any(feature = "log", feature = "tracing"))]
|
||||
retry_log_level: LogLevel,
|
||||
retry_log_level: tracing::Level,
|
||||
}
|
||||
|
||||
impl<T: RetryPolicy + Send + Sync> RetryTransientMiddleware<T, DefaultRetryableStrategy> {
|
||||
|
@ -86,8 +80,7 @@ impl<T: RetryPolicy + Send + Sync> RetryTransientMiddleware<T, DefaultRetryableS
|
|||
|
||||
/// Set the log [level][tracing::Level] for retry events.
|
||||
/// The default is [`WARN`][tracing::Level::WARN].
|
||||
#[cfg(any(feature = "log", feature = "tracing"))]
|
||||
pub fn with_retry_log_level(mut self, level: LogLevel) -> Self {
|
||||
pub fn with_retry_log_level(mut self, level: tracing::Level) -> Self {
|
||||
self.retry_log_level = level;
|
||||
self
|
||||
}
|
||||
|
@ -103,7 +96,7 @@ where
|
|||
Self {
|
||||
retry_policy,
|
||||
retryable_strategy,
|
||||
retry_log_level: LogLevel::WARN,
|
||||
retry_log_level: tracing::Level::WARN,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue