pub struct HttpClientBuilder { /* private fields */ }
Expand description
HTTP 客户端构建器
Implementations§
Source§impl HttpClientBuilder
impl HttpClientBuilder
Sourcepub fn ureq() -> Self
pub fn ureq() -> Self
创建一个新的 HTTP 客户端构建器,使用 crate::ureq::Client
作为 HttpCaller
实现
Sourcepub fn isahc() -> Result<Self, IsahcError>
pub fn isahc() -> Result<Self, IsahcError>
创建一个新的 HTTP 客户端构建器,使用 crate::isahc::Client
作为 HttpCaller
实现
Sourcepub fn reqwest_sync() -> Self
pub fn reqwest_sync() -> Self
创建一个新的 HTTP 客户端构建器,使用 crate::reqwest::SyncClient
作为 HttpCaller
实现
Sourcepub fn reqwest_async() -> Self
pub fn reqwest_async() -> Self
创建一个新的 HTTP 客户端构建器,使用 crate::reqwest::SyncClient
作为 HttpCaller
实现
Sourcepub fn new(http_caller: impl HttpCaller + 'static) -> Self
pub fn new(http_caller: impl HttpCaller + 'static) -> Self
创建一个新的 HTTP 客户端构建器,需要指定 HttpCaller
实现
Sourcepub fn appended_user_agent(
&mut self,
appended_user_agent: impl Into<UserAgent>,
) -> &mut Self
pub fn appended_user_agent( &mut self, appended_user_agent: impl Into<UserAgent>, ) -> &mut Self
设置追加的 UserAgent
Sourcepub fn http_caller(
&mut self,
http_caller: impl HttpCaller + 'static,
) -> &mut Self
pub fn http_caller( &mut self, http_caller: impl HttpCaller + 'static, ) -> &mut Self
设置 HTTP 客户端实现
默认根据启用的功能自动选择。
Sourcepub fn request_retrier(
&mut self,
request_retrier: impl RequestRetrier + 'static,
) -> &mut Self
pub fn request_retrier( &mut self, request_retrier: impl RequestRetrier + 'static, ) -> &mut Self
设置重试器
默认使用 ErrorRetrier
,并使用 LimitedRetrier
对其进行包装。
Sourcepub fn backoff(&mut self, backoff: impl Backoff + 'static) -> &mut Self
pub fn backoff(&mut self, backoff: impl Backoff + 'static) -> &mut Self
设置退避器
默认使用 ExponentialBackoff
,并使用 LimitedBackoff
和 RandomizedBackoff
对其进行包装。
Sourcepub fn chooser(&mut self, chooser: impl Chooser + 'static) -> &mut Self
pub fn chooser(&mut self, chooser: impl Chooser + 'static) -> &mut Self
设置选择器
默认使用 SubnetChooser
,并使用 ShuffledChooser
和 NeverEmptyHandedChooser
对其进行包装。
Sourcepub fn resolver(&mut self, resolver: impl Resolver + 'static) -> &mut Self
pub fn resolver(&mut self, resolver: impl Resolver + 'static) -> &mut Self
设置域名解析器
默认通过当前启用的功能来判定,并使用 CachedResolver
和 ShuffledResolver
对其进行包装。
Sourcepub fn on_uploading_progress(
&mut self,
callback: impl Fn(&dyn SimplifiedCallbackContext, TransferProgressInfo<'_>) -> AnyResult<()> + Send + Sync + 'static,
) -> &mut Self
pub fn on_uploading_progress( &mut self, callback: impl Fn(&dyn SimplifiedCallbackContext, TransferProgressInfo<'_>) -> AnyResult<()> + Send + Sync + 'static, ) -> &mut Self
设置上传进度回调函数
Sourcepub fn on_receive_response_status(
&mut self,
callback: impl Fn(&dyn SimplifiedCallbackContext, StatusCode) -> AnyResult<()> + Send + Sync + 'static,
) -> &mut Self
pub fn on_receive_response_status( &mut self, callback: impl Fn(&dyn SimplifiedCallbackContext, StatusCode) -> AnyResult<()> + Send + Sync + 'static, ) -> &mut Self
设置响应状态码回调函数
Sourcepub fn on_receive_response_header(
&mut self,
callback: impl Fn(&dyn SimplifiedCallbackContext, &HeaderName, &HeaderValue) -> AnyResult<()> + Send + Sync + 'static,
) -> &mut Self
pub fn on_receive_response_header( &mut self, callback: impl Fn(&dyn SimplifiedCallbackContext, &HeaderName, &HeaderValue) -> AnyResult<()> + Send + Sync + 'static, ) -> &mut Self
设置响应 HTTP 头回调函数
Sourcepub fn on_to_resolve_domain(
&mut self,
callback: impl Fn(&mut dyn CallbackContext, &str) -> AnyResult<()> + Send + Sync + 'static,
) -> &mut Self
pub fn on_to_resolve_domain( &mut self, callback: impl Fn(&mut dyn CallbackContext, &str) -> AnyResult<()> + Send + Sync + 'static, ) -> &mut Self
设置域名解析前回调函数
Sourcepub fn on_domain_resolved(
&mut self,
callback: impl Fn(&mut dyn CallbackContext, &str, &ResolveAnswers) -> AnyResult<()> + Send + Sync + 'static,
) -> &mut Self
pub fn on_domain_resolved( &mut self, callback: impl Fn(&mut dyn CallbackContext, &str, &ResolveAnswers) -> AnyResult<()> + Send + Sync + 'static, ) -> &mut Self
设置域名解析成功回调函数
Sourcepub fn on_to_choose_ips(
&mut self,
callback: impl Fn(&mut dyn CallbackContext, &[IpAddrWithPort]) -> AnyResult<()> + Send + Sync + 'static,
) -> &mut Self
pub fn on_to_choose_ips( &mut self, callback: impl Fn(&mut dyn CallbackContext, &[IpAddrWithPort]) -> AnyResult<()> + Send + Sync + 'static, ) -> &mut Self
设置 IP 地址选择前回调函数
Sourcepub fn on_ips_chosen(
&mut self,
callback: impl Fn(&mut dyn CallbackContext, &[IpAddrWithPort], &[IpAddrWithPort]) -> AnyResult<()> + Send + Sync + 'static,
) -> &mut Self
pub fn on_ips_chosen( &mut self, callback: impl Fn(&mut dyn CallbackContext, &[IpAddrWithPort], &[IpAddrWithPort]) -> AnyResult<()> + Send + Sync + 'static, ) -> &mut Self
设置 IP 地址选择成功回调函数
Sourcepub fn on_before_request_signed(
&mut self,
callback: impl Fn(&mut dyn ExtendedCallbackContext) -> AnyResult<()> + Send + Sync + 'static,
) -> &mut Self
pub fn on_before_request_signed( &mut self, callback: impl Fn(&mut dyn ExtendedCallbackContext) -> AnyResult<()> + Send + Sync + 'static, ) -> &mut Self
设置 HTTP 请求签名前回调函数
Sourcepub fn on_after_request_signed(
&mut self,
callback: impl Fn(&mut dyn ExtendedCallbackContext) -> AnyResult<()> + Send + Sync + 'static,
) -> &mut Self
pub fn on_after_request_signed( &mut self, callback: impl Fn(&mut dyn ExtendedCallbackContext) -> AnyResult<()> + Send + Sync + 'static, ) -> &mut Self
设置 HTTP 请求前回调函数
Sourcepub fn on_response(
&mut self,
callback: impl Fn(&mut dyn ExtendedCallbackContext, &ResponseParts) -> AnyResult<()> + Send + Sync + 'static,
) -> &mut Self
pub fn on_response( &mut self, callback: impl Fn(&mut dyn ExtendedCallbackContext, &ResponseParts) -> AnyResult<()> + Send + Sync + 'static, ) -> &mut Self
设置 HTTP 响应成功回调函数
Sourcepub fn on_error(
&mut self,
callback: impl Fn(&mut dyn ExtendedCallbackContext, &mut ResponseError) -> AnyResult<()> + Send + Sync + 'static,
) -> &mut Self
pub fn on_error( &mut self, callback: impl Fn(&mut dyn ExtendedCallbackContext, &mut ResponseError) -> AnyResult<()> + Send + Sync + 'static, ) -> &mut Self
设置 HTTP 响应出错回调函数
Sourcepub fn on_before_backoff(
&mut self,
callback: impl Fn(&mut dyn ExtendedCallbackContext, Duration) -> AnyResult<()> + Send + Sync + 'static,
) -> &mut Self
pub fn on_before_backoff( &mut self, callback: impl Fn(&mut dyn ExtendedCallbackContext, Duration) -> AnyResult<()> + Send + Sync + 'static, ) -> &mut Self
设置退避前回调函数
Sourcepub fn on_after_backoff(
&mut self,
callback: impl Fn(&mut dyn ExtendedCallbackContext, Duration) -> AnyResult<()> + Send + Sync + 'static,
) -> &mut Self
pub fn on_after_backoff( &mut self, callback: impl Fn(&mut dyn ExtendedCallbackContext, Duration) -> AnyResult<()> + Send + Sync + 'static, ) -> &mut Self
设置退避后回调函数
Sourcepub fn build(&mut self) -> HttpClient
pub fn build(&mut self) -> HttpClient
构建 HTTP 客户端
Trait Implementations§
Source§impl Debug for HttpClientBuilder
impl Debug for HttpClientBuilder
Auto Trait Implementations§
impl Freeze for HttpClientBuilder
impl !RefUnwindSafe for HttpClientBuilder
impl Send for HttpClientBuilder
impl Sync for HttpClientBuilder
impl Unpin for HttpClientBuilder
impl !UnwindSafe for HttpClientBuilder
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
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> 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>
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>
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 moreSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.