#[non_exhaustive]pub struct HttpClientConfig {
pub timeout_secs: u64,
pub pool_max_idle_per_host: usize,
pub pool_idle_timeout_secs: u64,
pub user_agent: Option<String>,
pub accept_invalid_certs: bool,
pub proxy_url: Option<String>,
pub circuit_breaker: Option<CircuitBreakerConfig>,
pub max_response_bytes: usize,
pub redirect: HttpRedirectPolicy,
}Expand description
HTTP 客户端配置
用于通过 HttpClient::with_config 创建自定义配置的客户端
§示例
ⓘ
use yang_base::http::{HttpClient, HttpClientConfig};
let config = HttpClientConfig {
timeout_secs: 60,
pool_max_idle_per_host: 10,
user_agent: Some("MyApp/1.0".to_string()),
..Default::default()
};
let client = HttpClient::with_config(config)?;Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.timeout_secs: u64请求超时时间(秒),默认 30 秒
pool_max_idle_per_host: usize每个主机最大空闲连接数,默认 10
pool_idle_timeout_secs: u64连接池空闲超时时间(秒),默认 90 秒
user_agent: Option<String>自定义 User-Agent,默认为 None(使用 reqwest 默认值)
accept_invalid_certs: bool是否接受无效的 TLS 证书,默认 false(生产环境不应设为 true)
proxy_url: Option<String>代理 URL,默认为 None(不使用代理)
circuit_breaker: Option<CircuitBreakerConfig>熔断器策略,默认 None(不启用)。设为 Some(..) 后,对连续失败的目标
host 快速失败(返回 BaseError::HttpCircuitBreakerOpen),按 host 分键。
max_response_bytes: usize出站响应体最大允许字节数,默认 10 MiB(DEFAULT_MAX_RESPONSE_BYTES)。
读取响应体(bytes/json/text)时先查 Content-Length 做快速失败,
再流式累计校验运行中上限,超限返回 BaseError::HttpResponseTooLarge。
redirect: HttpRedirectPolicy重定向跟随策略,默认 HttpRedirectPolicy::Limited(10)(reqwest 默认:
最多跟随 10 跳)。
默认策略不逐跳校验目标 host,也不会额外剥离自定义凭证头;需要 SSRF
白名单或严格同源校验的调用方应显式设为 HttpRedirectPolicy::None,
自行校验 3xx 的 Location。
Implementations§
Trait Implementations§
Source§impl Clone for HttpClientConfig
impl Clone for HttpClientConfig
Source§impl Debug for HttpClientConfig
impl Debug for HttpClientConfig
Auto Trait Implementations§
impl Forget for HttpClientConfig
impl Freeze for HttpClientConfig
impl Move for HttpClientConfig
impl RefUnwindSafe for HttpClientConfig
impl Send for HttpClientConfig
impl Sync for HttpClientConfig
impl Unpin for HttpClientConfig
impl UnsafeUnpin for HttpClientConfig
impl UnwindSafe for HttpClientConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more