pub struct ClientBuilder { /* private fields */ }Expand description
HTTP 客户端构建器,通过链式调用配置后调用 .build() 生成 Client。
Implementations§
Source§impl ClientBuilder
impl ClientBuilder
Sourcepub fn with_base_url(self, base_url: impl Into<String>) -> Self
pub fn with_base_url(self, base_url: impl Into<String>) -> Self
设置基础 URL,相对路径请求将拼接在此 URL 之后。
Sourcepub fn with_interceptor(self, interceptor: Box<dyn HttpInterceptor>) -> Self
pub fn with_interceptor(self, interceptor: Box<dyn HttpInterceptor>) -> Self
追加一个请求拦截器,拦截器按注册顺序链式执行。
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
设置整体请求超时时间(含建连和传输)。
Sourcepub fn with_read_timeout(self, read_timeout: Duration) -> Self
pub fn with_read_timeout(self, read_timeout: Duration) -> Self
设置响应体读取超时时间。
Sourcepub fn with_connect_timeout(self, connect_timeout: Duration) -> Self
pub fn with_connect_timeout(self, connect_timeout: Duration) -> Self
设置 TCP 连接超时时间。
Sourcepub fn with_pool_idle_timeout(self, pool_idle_timeout: Duration) -> Self
pub fn with_pool_idle_timeout(self, pool_idle_timeout: Duration) -> Self
设置连接池空闲连接的回收超时时间。
Sourcepub fn with_headers(self, headers: HeaderMap) -> Self
pub fn with_headers(self, headers: HeaderMap) -> Self
设置每个请求默认携带的请求头。
Sourcepub fn with_common_interceptor(self) -> Self
pub fn with_common_interceptor(self) -> Self
追加通用日志拦截器(CommonInterceptor),自动使用当前服务名。
Sourcepub fn with_pool_max_idle_per_host(self, pool_max_idle_per_host: usize) -> Self
pub fn with_pool_max_idle_per_host(self, pool_max_idle_per_host: usize) -> Self
设置每个 host 的最大空闲连接数。
Sourcepub fn with_max_processing(self, max_processing: u32) -> Self
pub fn with_max_processing(self, max_processing: u32) -> Self
设置最大并发在途请求数,超出时立即返回错误,防止雪崩。
Sourcepub fn with_dns_overrides(
self,
dns_overrides: HashMap<String, Vec<SocketAddr>>,
) -> Self
pub fn with_dns_overrides( self, dns_overrides: HashMap<String, Vec<SocketAddr>>, ) -> Self
设置自定义 DNS 解析映射,格式为 host -> [SocketAddr]。
Auto Trait Implementations§
impl !RefUnwindSafe for ClientBuilder
impl !UnwindSafe for ClientBuilder
impl Freeze for ClientBuilder
impl Send for ClientBuilder
impl Sync for ClientBuilder
impl Unpin for ClientBuilder
impl UnsafeUnpin for ClientBuilder
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