Struct qiniu_http_client::RequestRetrierOptions
source · pub struct RequestRetrierOptions<'a> { /* private fields */ }
Expand description
重试器选项
Implementations§
source§impl<'a> RequestRetrierOptions<'a>
impl<'a> RequestRetrierOptions<'a>
sourcepub fn builder(
response_error: &'a ResponseError,
retried: &'a RetriedStatsInfo
) -> RequestRetrierOptionsBuilder<'a>
pub fn builder(
response_error: &'a ResponseError,
retried: &'a RetriedStatsInfo
) -> RequestRetrierOptionsBuilder<'a>
创建重试器选项构建器
Examples found in repository?
src/client/call/send_http_request.rs (line 96)
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
fn handle_response_error(
mut response_error: ResponseError,
http_parts: &mut HttpRequestParts,
parts: &InnerRequestParts<'_>,
retried: &mut RetriedStatsInfo,
) -> TryError {
let retry_result = parts.http_client().request_retrier().retry(
http_parts,
RequestRetrierOptions::builder(&response_error, retried)
.idempotent(parts.idempotent())
.build(),
);
retried.increase_current_endpoint();
response_error = response_error.set_retry_decision(retry_result.decision());
TryError::new(response_error, retry_result)
}
sourcepub fn idempotent(&self) -> Idempotent
pub fn idempotent(&self) -> Idempotent
是否是幂等请求
Examples found in repository?
src/client/retrier/error.rs (line 23)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
fn retry(&self, request: &mut HttpRequestParts, opts: RequestRetrierOptions) -> RetryResult {
return match opts.response_error().kind() {
ResponseErrorKind::HttpError(http_err_kind) => match http_err_kind {
HttpResponseErrorKind::ProtocolError => RetryDecision::RetryRequest,
HttpResponseErrorKind::InvalidUrl => RetryDecision::TryNextServer,
HttpResponseErrorKind::ConnectError => RetryDecision::TryNextServer,
HttpResponseErrorKind::ProxyError => RetryDecision::RetryRequest,
HttpResponseErrorKind::DnsServerError => RetryDecision::RetryRequest,
HttpResponseErrorKind::UnknownHostError => RetryDecision::TryNextServer,
HttpResponseErrorKind::SendError => RetryDecision::RetryRequest,
HttpResponseErrorKind::ReceiveError | HttpResponseErrorKind::UnknownError => {
if is_idempotent(request, opts.idempotent()) {
RetryDecision::RetryRequest
} else {
RetryDecision::DontRetry
}
}
HttpResponseErrorKind::LocalIoError => RetryDecision::DontRetry,
HttpResponseErrorKind::TimeoutError => RetryDecision::RetryRequest,
HttpResponseErrorKind::ServerCertError => RetryDecision::TryAlternativeEndpoints,
HttpResponseErrorKind::ClientCertError => RetryDecision::DontRetry,
HttpResponseErrorKind::TooManyRedirect => RetryDecision::DontRetry,
HttpResponseErrorKind::CallbackError => RetryDecision::DontRetry,
_ => RetryDecision::RetryRequest,
},
ResponseErrorKind::UnexpectedStatusCode(_) => RetryDecision::DontRetry,
ResponseErrorKind::StatusCodeError(status_code) => match status_code.as_u16() {
0..=399 => panic!("Should not arrive here"),
400..=499 | 501 | 579 | 608 | 612 | 614 | 616 | 618 | 630 | 631 | 632 | 640 | 701 => {
RetryDecision::DontRetry
}
509 | 573 => RetryDecision::Throttled,
_ => RetryDecision::TryNextServer,
},
ResponseErrorKind::ParseResponseError | ResponseErrorKind::UnexpectedEof => {
if is_idempotent(request, opts.idempotent()) {
RetryDecision::RetryRequest
} else {
RetryDecision::DontRetry
}
}
ResponseErrorKind::MaliciousResponse => RetryDecision::RetryRequest,
ResponseErrorKind::NoTry | ResponseErrorKind::SystemCallError => RetryDecision::DontRetry,
}
.into();
fn is_idempotent(request: &HttpRequestParts, idempotent: Idempotent) -> bool {
match idempotent {
Idempotent::Always => true,
Idempotent::Default => request.method().is_safe(),
Idempotent::Never => false,
}
}
}
sourcepub fn response_error(&self) -> &ResponseError
pub fn response_error(&self) -> &ResponseError
获取响应错误
Examples found in repository?
src/client/retrier/error.rs (line 13)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
fn retry(&self, request: &mut HttpRequestParts, opts: RequestRetrierOptions) -> RetryResult {
return match opts.response_error().kind() {
ResponseErrorKind::HttpError(http_err_kind) => match http_err_kind {
HttpResponseErrorKind::ProtocolError => RetryDecision::RetryRequest,
HttpResponseErrorKind::InvalidUrl => RetryDecision::TryNextServer,
HttpResponseErrorKind::ConnectError => RetryDecision::TryNextServer,
HttpResponseErrorKind::ProxyError => RetryDecision::RetryRequest,
HttpResponseErrorKind::DnsServerError => RetryDecision::RetryRequest,
HttpResponseErrorKind::UnknownHostError => RetryDecision::TryNextServer,
HttpResponseErrorKind::SendError => RetryDecision::RetryRequest,
HttpResponseErrorKind::ReceiveError | HttpResponseErrorKind::UnknownError => {
if is_idempotent(request, opts.idempotent()) {
RetryDecision::RetryRequest
} else {
RetryDecision::DontRetry
}
}
HttpResponseErrorKind::LocalIoError => RetryDecision::DontRetry,
HttpResponseErrorKind::TimeoutError => RetryDecision::RetryRequest,
HttpResponseErrorKind::ServerCertError => RetryDecision::TryAlternativeEndpoints,
HttpResponseErrorKind::ClientCertError => RetryDecision::DontRetry,
HttpResponseErrorKind::TooManyRedirect => RetryDecision::DontRetry,
HttpResponseErrorKind::CallbackError => RetryDecision::DontRetry,
_ => RetryDecision::RetryRequest,
},
ResponseErrorKind::UnexpectedStatusCode(_) => RetryDecision::DontRetry,
ResponseErrorKind::StatusCodeError(status_code) => match status_code.as_u16() {
0..=399 => panic!("Should not arrive here"),
400..=499 | 501 | 579 | 608 | 612 | 614 | 616 | 618 | 630 | 631 | 632 | 640 | 701 => {
RetryDecision::DontRetry
}
509 | 573 => RetryDecision::Throttled,
_ => RetryDecision::TryNextServer,
},
ResponseErrorKind::ParseResponseError | ResponseErrorKind::UnexpectedEof => {
if is_idempotent(request, opts.idempotent()) {
RetryDecision::RetryRequest
} else {
RetryDecision::DontRetry
}
}
ResponseErrorKind::MaliciousResponse => RetryDecision::RetryRequest,
ResponseErrorKind::NoTry | ResponseErrorKind::SystemCallError => RetryDecision::DontRetry,
}
.into();
fn is_idempotent(request: &HttpRequestParts, idempotent: Idempotent) -> bool {
match idempotent {
Idempotent::Always => true,
Idempotent::Default => request.method().is_safe(),
Idempotent::Never => false,
}
}
}
sourcepub fn retried(&self) -> &RetriedStatsInfo
pub fn retried(&self) -> &RetriedStatsInfo
获取重试统计信息
Examples found in repository?
src/client/retrier/limited.rs (line 21)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn retry(self, decision: RetryDecision, retries: usize, opts: RequestRetrierOptions) -> RetryDecision {
match self {
Self::LimitCurrentEndpoint => match decision {
RetryDecision::RetryRequest | RetryDecision::Throttled
if opts.retried().retried_on_current_endpoint() >= retries =>
{
RetryDecision::TryNextServer
}
result => result,
},
Self::LimitTotal => match decision {
RetryDecision::RetryRequest | RetryDecision::Throttled if opts.retried().retried_total() >= retries => {
RetryDecision::DontRetry
}
result => result,
},
}
}
Trait Implementations§
source§impl<'a> Clone for RequestRetrierOptions<'a>
impl<'a> Clone for RequestRetrierOptions<'a>
source§fn clone(&self) -> RequestRetrierOptions<'a>
fn clone(&self) -> RequestRetrierOptions<'a>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<'a> Debug for RequestRetrierOptions<'a>
impl<'a> Debug for RequestRetrierOptions<'a>
impl<'a> Copy for RequestRetrierOptions<'a>
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for RequestRetrierOptions<'a>
impl<'a> Send for RequestRetrierOptions<'a>
impl<'a> Sync for RequestRetrierOptions<'a>
impl<'a> Unpin for RequestRetrierOptions<'a>
impl<'a> !UnwindSafe for RequestRetrierOptions<'a>
Blanket Implementations§
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> 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,
Pipes by value. This is generally the method you want to use. Read more
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,
Borrows
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,
Mutably borrows
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) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
Borrows
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) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
Mutably borrows
self
, then passes self.as_mut()
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)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Immutable access to the
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
Immutable access to the
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
Mutable access to the
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
Immutable access to the
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Mutable access to the
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
Calls
.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
Calls
.tap_mut()
only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Calls
.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)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
Calls
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
Calls
.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)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
Calls
.tap_ref_mut()
only in debug builds, and is erased in release
builds.