use aws_smithy_runtime_api::box_error::BoxError;
use aws_smithy_runtime_api::client::interceptors::context::BeforeTransmitInterceptorContextMut;
use aws_smithy_runtime_api::client::interceptors::{dyn_dispatch_hint, Intercept};
use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents;
use aws_smithy_types::config_bag::ConfigBag;
use aws_smithy_types::retry::{RetryConfig, RetrySpec};
#[derive(Debug, Default)]
pub(crate) struct LongPollingInterceptor;
#[dyn_dispatch_hint]
impl Intercept for LongPollingInterceptor {
fn name(&self) -> &'static str {
"LongPollingInterceptor"
}
fn modify_before_retry_loop(
&self,
_context: &mut BeforeTransmitInterceptorContextMut<'_>,
_runtime_components: &RuntimeComponents,
cfg: &mut ConfigBag,
) -> Result<(), BoxError> {
if let Some(rc) = cfg.load::<RetryConfig>().cloned() {
if let Some(spec) = rc.retry_spec().cloned() {
if spec.is_at_least(RetrySpec::V2_1) {
cfg.interceptor_state().store_put(rc.with_retry_spec(spec.with_long_polling(true)));
}
}
}
Ok(())
}
}