Trait qiniu_http_client::prelude::Chooser
source · pub trait Chooser: DynClone + Debug + Sync + Send {
fn choose(
&self,
ips: &[IpAddrWithPort],
opts: ChooseOptions<'_>
) -> ChosenResults;
fn feedback(&self, feedback: ChooserFeedback<'_>);
fn async_choose<'a>(
&'a self,
ips: &'a [IpAddrWithPort],
opts: ChooseOptions<'a>
) -> BoxFuture<'a, ChosenResults> { ... }
fn async_feedback<'a>(
&'a self,
feedback: ChooserFeedback<'a>
) -> BoxFuture<'a, ()> { ... }
}
Expand description
选择 IP 地址接口
还提供了对选择结果的反馈接口,用以修正自身选择逻辑,优化选择结果
同时提供阻塞接口和异步接口,异步接口则需要启用 async
功能
Required Methods§
sourcefn choose(&self, ips: &[IpAddrWithPort], opts: ChooseOptions<'_>) -> ChosenResults
fn choose(&self, ips: &[IpAddrWithPort], opts: ChooseOptions<'_>) -> ChosenResults
选择 IP 地址列表
sourcefn feedback(&self, feedback: ChooserFeedback<'_>)
fn feedback(&self, feedback: ChooserFeedback<'_>)
反馈选择的 IP 地址列表的结果
Provided Methods§
sourcefn async_choose<'a>(
&'a self,
ips: &'a [IpAddrWithPort],
opts: ChooseOptions<'a>
) -> BoxFuture<'a, ChosenResults>
fn async_choose<'a>(
&'a self,
ips: &'a [IpAddrWithPort],
opts: ChooseOptions<'a>
) -> BoxFuture<'a, ChosenResults>
Available on crate feature
async
only.异步选择 IP 地址列表
该方法的异步版本为 Self::async_choose
。
Examples found in repository?
More examples
src/client/call/utils.rs (line 506)
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
pub(in super::super) async fn async_choose(
parts: &InnerRequestParts<'_>,
ips: &[IpAddrWithPort],
extensions: &mut Extensions,
retried: &RetriedStatsInfo,
) -> Result<Vec<IpAddrWithPort>, TryError> {
call_to_choose_ips_callbacks(parts, ips, extensions, retried)?;
let chosen_ips = parts
.http_client()
.chooser()
.async_choose(ips, Default::default())
.await
.into_ip_addrs();
call_ips_chosen_callbacks(parts, ips, &chosen_ips, extensions, retried)?;
Ok(chosen_ips)
}
sourcefn async_feedback<'a>(
&'a self,
feedback: ChooserFeedback<'a>
) -> BoxFuture<'a, ()>
fn async_feedback<'a>(
&'a self,
feedback: ChooserFeedback<'a>
) -> BoxFuture<'a, ()>
Available on crate feature
async
only.异步反馈选择的 IP 地址列表的结果
Examples found in repository?
More examples
src/client/call/try_domain_or_ip_addr.rs (lines 180-186)
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
pub(super) async fn async_try_domain_or_ip_addr(
domain_or_ip: &DomainOrIpAddr,
parts: &InnerRequestParts<'_>,
body: &mut AsyncRequestBody<'_>,
mut extensions: Extensions,
retried: &mut RetriedStatsInfo,
) -> Result<AsyncResponse, TryErrorWithExtensions> {
let (url, resolved_ips) =
make_url(domain_or_ip, parts, retried).map_err(|err| err.with_extensions(take(&mut extensions)))?;
let on_uploading_progress = |info: TransferProgressInfo<'_>| parts.call_uploading_progress_callbacks(parts, info);
let on_receive_response_status =
|status_code: StatusCode| parts.call_receive_response_status_callbacks(parts, status_code);
let on_receive_response_header =
|name: &HeaderName, value: &HeaderValue| parts.call_receive_response_header_callbacks(parts, name, value);
let mut http_request: HttpRequest<AsyncRequestBody> =
make_request(url, parts, body.into(), extensions, &resolved_ips);
reset_async_request_body(http_request.body_mut(), retried)
.await
.map_err(|err| err.with_request(&mut http_request))?;
call_before_request_signed_callbacks(parts, &mut http_request, retried)
.map_err(|err| err.with_request(&mut http_request))?;
sign_async_request(&mut http_request, parts.authorization(), retried)
.await
.map_err(|err| err.with_request(&mut http_request))?;
call_after_request_signed_callbacks(parts, &mut http_request, retried)
.map_err(|err| err.with_request(&mut http_request))?;
reset_async_request_body(http_request.body_mut(), retried)
.await
.map_err(|err| err.with_request(&mut http_request))?;
if parts.uploading_progress_callbacks_count() > 0 {
*http_request.on_uploading_progress_mut() = Some(OnProgressCallback::reference(&on_uploading_progress));
}
if parts.receive_response_status_callbacks_count() > 0 {
*http_request.on_receive_response_status_mut() =
Some(OnStatusCodeCallback::reference(&on_receive_response_status));
}
if parts.receive_response_header_callbacks_count() > 0 {
*http_request.on_receive_response_header_mut() = Some(OnHeaderCallback::reference(&on_receive_response_header));
}
let (extracted_ips, domain) = extract_ips_from(domain_or_ip);
match async_send_http_request(&mut http_request, parts, retried).await {
Ok(response) => {
if !extracted_ips.is_empty() {
parts
.http_client()
.chooser()
.async_feedback(make_positive_feedback(
&extracted_ips,
domain,
&mut http_request,
response.metrics(),
retried,
))
.await;
}
Ok(response)
}
Err(err) => {
if !extracted_ips.is_empty() {
parts
.http_client()
.chooser()
.async_feedback(make_negative_feedback(
&extracted_ips,
domain,
&mut http_request,
&err,
retried,
))
.await;
}
Err(err.with_request(&mut http_request))
}
}
}
Trait Implementations§
Implementations on Foreign Types§
source§impl<'b, T: 'b + Chooser + ?Sized> Chooser for &'b Twhere
&'b T: DynClone + Debug + Sync + Send,
impl<'b, T: 'b + Chooser + ?Sized> Chooser for &'b Twhere
&'b T: DynClone + Debug + Sync + Send,
fn choose(&self, ips: &[IpAddrWithPort], opts: ChooseOptions<'_>) -> ChosenResults
fn feedback(&self, feedback: ChooserFeedback<'_>)
source§fn async_choose<'a>(
&'a self,
ips: &'a [IpAddrWithPort],
opts: ChooseOptions<'a>
) -> BoxFuture<'a, ChosenResults>
fn async_choose<'a>(
&'a self,
ips: &'a [IpAddrWithPort],
opts: ChooseOptions<'a>
) -> BoxFuture<'a, ChosenResults>
Available on crate feature
async
only.source§fn async_feedback<'a>(
&'a self,
feedback: ChooserFeedback<'a>
) -> BoxFuture<'a, ()>
fn async_feedback<'a>(
&'a self,
feedback: ChooserFeedback<'a>
) -> BoxFuture<'a, ()>
Available on crate feature
async
only.source§impl<'b, T: 'b + Chooser + ?Sized> Chooser for &'b mut Twhere
&'b mut T: DynClone + Debug + Sync + Send,
impl<'b, T: 'b + Chooser + ?Sized> Chooser for &'b mut Twhere
&'b mut T: DynClone + Debug + Sync + Send,
fn choose(&self, ips: &[IpAddrWithPort], opts: ChooseOptions<'_>) -> ChosenResults
fn feedback(&self, feedback: ChooserFeedback<'_>)
source§fn async_choose<'a>(
&'a self,
ips: &'a [IpAddrWithPort],
opts: ChooseOptions<'a>
) -> BoxFuture<'a, ChosenResults>
fn async_choose<'a>(
&'a self,
ips: &'a [IpAddrWithPort],
opts: ChooseOptions<'a>
) -> BoxFuture<'a, ChosenResults>
Available on crate feature
async
only.source§fn async_feedback<'a>(
&'a self,
feedback: ChooserFeedback<'a>
) -> BoxFuture<'a, ()>
fn async_feedback<'a>(
&'a self,
feedback: ChooserFeedback<'a>
) -> BoxFuture<'a, ()>
Available on crate feature
async
only.source§impl<T: Chooser + ?Sized> Chooser for Box<T>where
Box<T>: DynClone + Debug + Sync + Send,
impl<T: Chooser + ?Sized> Chooser for Box<T>where
Box<T>: DynClone + Debug + Sync + Send,
fn choose(&self, ips: &[IpAddrWithPort], opts: ChooseOptions<'_>) -> ChosenResults
fn feedback(&self, feedback: ChooserFeedback<'_>)
source§fn async_choose<'a>(
&'a self,
ips: &'a [IpAddrWithPort],
opts: ChooseOptions<'a>
) -> BoxFuture<'a, ChosenResults>
fn async_choose<'a>(
&'a self,
ips: &'a [IpAddrWithPort],
opts: ChooseOptions<'a>
) -> BoxFuture<'a, ChosenResults>
Available on crate feature
async
only.source§fn async_feedback<'a>(
&'a self,
feedback: ChooserFeedback<'a>
) -> BoxFuture<'a, ()>
fn async_feedback<'a>(
&'a self,
feedback: ChooserFeedback<'a>
) -> BoxFuture<'a, ()>
Available on crate feature
async
only.source§impl<T: Chooser + ?Sized> Chooser for Rc<T>where
Rc<T>: DynClone + Debug + Sync + Send,
impl<T: Chooser + ?Sized> Chooser for Rc<T>where
Rc<T>: DynClone + Debug + Sync + Send,
fn choose(&self, ips: &[IpAddrWithPort], opts: ChooseOptions<'_>) -> ChosenResults
fn feedback(&self, feedback: ChooserFeedback<'_>)
source§fn async_choose<'a>(
&'a self,
ips: &'a [IpAddrWithPort],
opts: ChooseOptions<'a>
) -> BoxFuture<'a, ChosenResults>
fn async_choose<'a>(
&'a self,
ips: &'a [IpAddrWithPort],
opts: ChooseOptions<'a>
) -> BoxFuture<'a, ChosenResults>
Available on crate feature
async
only.source§fn async_feedback<'a>(
&'a self,
feedback: ChooserFeedback<'a>
) -> BoxFuture<'a, ()>
fn async_feedback<'a>(
&'a self,
feedback: ChooserFeedback<'a>
) -> BoxFuture<'a, ()>
Available on crate feature
async
only.source§impl<T: Chooser + ?Sized> Chooser for Arc<T>where
Arc<T>: DynClone + Debug + Sync + Send,
impl<T: Chooser + ?Sized> Chooser for Arc<T>where
Arc<T>: DynClone + Debug + Sync + Send,
fn choose(&self, ips: &[IpAddrWithPort], opts: ChooseOptions<'_>) -> ChosenResults
fn feedback(&self, feedback: ChooserFeedback<'_>)
source§fn async_choose<'a>(
&'a self,
ips: &'a [IpAddrWithPort],
opts: ChooseOptions<'a>
) -> BoxFuture<'a, ChosenResults>
fn async_choose<'a>(
&'a self,
ips: &'a [IpAddrWithPort],
opts: ChooseOptions<'a>
) -> BoxFuture<'a, ChosenResults>
Available on crate feature
async
only.source§fn async_feedback<'a>(
&'a self,
feedback: ChooserFeedback<'a>
) -> BoxFuture<'a, ()>
fn async_feedback<'a>(
&'a self,
feedback: ChooserFeedback<'a>
) -> BoxFuture<'a, ()>
Available on crate feature
async
only.