mirror of
https://github.com/TrueLayer/reqwest-middleware.git
synced 2024-12-26 02:46: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"]
|
json = ["reqwest/json"]
|
||||||
charset = ["reqwest/charset"]
|
charset = ["reqwest/charset"]
|
||||||
http2 = ["reqwest/http2"]
|
http2 = ["reqwest/http2"]
|
||||||
|
rustls-tls = ["reqwest/rustls-tls"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.0"
|
anyhow = "1.0.0"
|
||||||
|
|
|
@ -9,26 +9,20 @@ license = "MIT OR Apache-2.0"
|
||||||
keywords = ["reqwest", "http", "middleware", "retry"]
|
keywords = ["reqwest", "http", "middleware", "retry"]
|
||||||
categories = ["web-programming::http-client"]
|
categories = ["web-programming::http-client"]
|
||||||
|
|
||||||
[features]
|
|
||||||
default = ["tracing"]
|
|
||||||
log = ["dep:log"]
|
|
||||||
tracing = ["dep:tracing"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
reqwest-middleware = { version = "0.3.0", path = "../reqwest-middleware" }
|
reqwest-middleware = { version = "0.3.0", path = "../reqwest-middleware" }
|
||||||
|
|
||||||
anyhow = "1.0.0"
|
anyhow = "1.0.0"
|
||||||
async-trait = "0.1.51"
|
async-trait = "0.1.51"
|
||||||
futures = "0.3.0"
|
futures = "0.3.0"
|
||||||
log = { version = "0.4.22", optional = true }
|
|
||||||
http = "1.0"
|
http = "1.0"
|
||||||
reqwest = { version = "0.12.0", default-features = false }
|
reqwest = { version = "0.12.0", default-features = false }
|
||||||
retry-policies = "0.4"
|
retry-policies = "0.4"
|
||||||
tracing = { version = "0.1.26", optional = true }
|
tracing = "0.1.26"
|
||||||
|
|
||||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
hyper = "1.0"
|
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]
|
[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
|
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 reqwest_middleware::{Error, Middleware, Next, Result};
|
||||||
use retry_policies::RetryPolicy;
|
use retry_policies::RetryPolicy;
|
||||||
|
|
||||||
#[cfg(feature = "tracing")]
|
|
||||||
type LogLevel = ::tracing::Level;
|
|
||||||
#[cfg(all(feature = "log", not(feature = "tracing")))]
|
|
||||||
type LogLevel = ::log::Level;
|
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
// We need this macro because tracing expects the level to be const:
|
// We need this macro because tracing expects the level to be const:
|
||||||
// https://github.com/tokio-rs/tracing/issues/2730
|
// https://github.com/tokio-rs/tracing/issues/2730
|
||||||
macro_rules! log_retry {
|
macro_rules! log_retry {
|
||||||
($level:expr, $($args:tt)*) => {{
|
($level:expr, $($args:tt)*) => {{
|
||||||
match $level {
|
match $level {
|
||||||
LogLevel::TRACE => ::tracing::trace!($($args)*),
|
::tracing::Level::TRACE => ::tracing::trace!($($args)*),
|
||||||
LogLevel::DEBUG => ::tracing::debug!($($args)*),
|
::tracing::Level::DEBUG => ::tracing::debug!($($args)*),
|
||||||
LogLevel::INFO => ::tracing::info!($($args)*),
|
::tracing::Level::INFO => ::tracing::info!($($args)*),
|
||||||
LogLevel::WARN => ::tracing::warn!($($args)*),
|
::tracing::Level::WARN => ::tracing::warn!($($args)*),
|
||||||
LogLevel::ERROR => ::tracing::error!($($args)*),
|
::tracing::Level::ERROR => ::tracing::error!($($args)*),
|
||||||
}
|
}
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
@ -74,8 +69,7 @@ pub struct RetryTransientMiddleware<
|
||||||
> {
|
> {
|
||||||
retry_policy: T,
|
retry_policy: T,
|
||||||
retryable_strategy: R,
|
retryable_strategy: R,
|
||||||
#[cfg(any(feature = "log", feature = "tracing"))]
|
retry_log_level: tracing::Level,
|
||||||
retry_log_level: LogLevel,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: RetryPolicy + Send + Sync> RetryTransientMiddleware<T, DefaultRetryableStrategy> {
|
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.
|
/// Set the log [level][tracing::Level] for retry events.
|
||||||
/// The default is [`WARN`][tracing::Level::WARN].
|
/// The default is [`WARN`][tracing::Level::WARN].
|
||||||
#[cfg(any(feature = "log", feature = "tracing"))]
|
pub fn with_retry_log_level(mut self, level: tracing::Level) -> Self {
|
||||||
pub fn with_retry_log_level(mut self, level: LogLevel) -> Self {
|
|
||||||
self.retry_log_level = level;
|
self.retry_log_level = level;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
@ -103,7 +96,7 @@ where
|
||||||
Self {
|
Self {
|
||||||
retry_policy,
|
retry_policy,
|
||||||
retryable_strategy,
|
retryable_strategy,
|
||||||
retry_log_level: LogLevel::WARN,
|
retry_log_level: tracing::Level::WARN,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue