Skip to main content

aws_smithy_runtime/client/
defaults.rs

1/*
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6//! Runtime plugins that provide defaults for clients.
7//!
8//! Note: these are the absolute base-level defaults. They may not be the defaults
9//! for _your_ client, since many things can change these defaults on the way to
10//! code generating and constructing a full client.
11
12use crate::client::http::body::content_length_enforcement::EnforceContentLengthRuntimePlugin;
13use crate::client::identity::IdentityCache;
14use crate::client::retries::strategy::standard::TokenBucketProvider;
15use crate::client::retries::strategy::StandardRetryStrategy;
16use crate::client::retries::RetryPartition;
17use aws_smithy_async::rt::sleep::default_async_sleep;
18use aws_smithy_async::time::SystemTimeSource;
19use aws_smithy_runtime_api::box_error::BoxError;
20use aws_smithy_runtime_api::client::behavior_version::BehaviorVersion;
21use aws_smithy_runtime_api::client::http::SharedHttpClient;
22use aws_smithy_runtime_api::client::interceptors::SharedInterceptor;
23use aws_smithy_runtime_api::client::runtime_components::{
24    RuntimeComponentsBuilder, SharedConfigValidator,
25};
26use aws_smithy_runtime_api::client::runtime_plugin::{
27    Order, SharedRuntimePlugin, StaticRuntimePlugin,
28};
29use aws_smithy_runtime_api::client::stalled_stream_protection::StalledStreamProtectionConfig;
30use aws_smithy_runtime_api::shared::IntoShared;
31use aws_smithy_types::config_bag::{ConfigBag, FrozenLayer, Layer};
32use aws_smithy_types::retry::{ReconnectMode, RetryConfig, RetrySpec};
33use aws_smithy_types::timeout::TimeoutConfig;
34use std::borrow::Cow;
35use std::time::Duration;
36
37/// Default connect timeout for all clients with BehaviorVersion >= v2026_01_12
38pub(crate) const DEFAULT_CONNECT_TIMEOUT: Duration = Duration::from_millis(3100);
39
40fn default_plugin<CompFn>(name: &'static str, components_fn: CompFn) -> StaticRuntimePlugin
41where
42    CompFn: FnOnce(RuntimeComponentsBuilder) -> RuntimeComponentsBuilder,
43{
44    StaticRuntimePlugin::new()
45        .with_order(Order::Defaults)
46        .with_runtime_components((components_fn)(RuntimeComponentsBuilder::new(name)))
47}
48
49fn layer<LayerFn>(name: &'static str, layer_fn: LayerFn) -> FrozenLayer
50where
51    LayerFn: FnOnce(&mut Layer),
52{
53    let mut layer = Layer::new(name);
54    (layer_fn)(&mut layer);
55    layer.freeze()
56}
57
58/// Runtime plugin that provides a default connector.
59#[deprecated(
60    since = "1.8.0",
61    note = "This function wasn't intended to be public, and didn't take the behavior major version as an argument, so it couldn't be evolved over time."
62)]
63pub fn default_http_client_plugin() -> Option<SharedRuntimePlugin> {
64    #[expect(deprecated)]
65    default_http_client_plugin_v2(BehaviorVersion::v2024_03_28())
66}
67
68/// Announce the upcoming default HTTP client change, while the legacy stack is still the default.
69///
70/// Called only where the legacy client was actually selected, which is exactly the set of
71/// configurations that will resolve differently once `rustls` stops being a default feature of
72/// generated SDK crates. Callers who have already pinned `legacy-https-client` cannot be
73/// distinguished from callers riding the default at this layer — both arrive as `tls-rustls` — so
74/// they see it too; the message is written to be actionable either way.
75///
76/// This is transient: delete it when that default change lands. From then on the fallback warning
77/// in `default_http_client_plugin_v2` is what callers see instead.
78#[cfg(feature = "connector-hyper-0-14-x")]
79fn warn_legacy_client_default_is_changing(behavior_version: BehaviorVersion) {
80    let emit = || {
81        tracing::warn!(
82            behavior_version = ?behavior_version,
83            "this build resolves to the legacy hyper 0.14.x / http 0.2.x HTTP client. In the 2.x \
84             release, currently expected November 2026, the default becomes the hyper 1.x client: \
85             a different TLS implementation, with different connection-pooling and timeout \
86             behavior. To keep the legacy client, add `features = [\"legacy-https-client\"]` to \
87             your AWS SDK crate now — that spelling is stable across the change, whereas `rustls` \
88             will become a synonym for the hyper 1.x client. To move early instead, use \
89             `BehaviorVersion::v2026_01_12()` or later. \
90             See https://github.com/smithy-lang/smithy-rs/issues/4489",
91        );
92    };
93
94    // Once per process, so building a client per request does not flood the log. Under `cfg(test)`
95    // every call warns, because a process-wide latch would let whichever test ran first consume
96    // the only warning and make the others silently vacuous.
97    #[cfg(not(test))]
98    {
99        static WARNED: std::sync::Once = std::sync::Once::new();
100        WARNED.call_once(emit);
101    }
102    #[cfg(test)]
103    emit();
104}
105
106/// Runtime plugin that provides a default HTTPS connector.
107pub fn default_http_client_plugin_v2(
108    behavior_version: BehaviorVersion,
109) -> Option<SharedRuntimePlugin> {
110    let mut _default: Option<SharedHttpClient> = None;
111
112    #[allow(deprecated)]
113    if behavior_version.is_at_least(BehaviorVersion::v2026_01_12()) {
114        // the latest https stack takes precedence if the config flag
115        // is enabled otherwise try to fall back to the legacy connector
116        // if that feature flag is available.
117        #[cfg(all(
118            feature = "connector-hyper-0-14-x",
119            not(feature = "default-https-client")
120        ))]
121        #[allow(deprecated)]
122        {
123            _default = crate::client::http::hyper_014::default_client();
124
125            // A legacy-only build reaches the legacy client even on a current behavior version,
126            // and will resolve to hyper 1.x once `rustls` stops being a default feature.
127            if _default.is_some() {
128                warn_legacy_client_default_is_changing(behavior_version);
129            }
130        }
131
132        // takes precedence over legacy connector if enabled
133        #[cfg(feature = "default-https-client")]
134        {
135            let opts = crate::client::http::DefaultClientOptions::default()
136                .with_behavior_version(behavior_version);
137            _default = crate::client::http::default_https_client(opts);
138        }
139    } else {
140        // fallback to legacy hyper client for given behavior version
141        #[cfg(feature = "connector-hyper-0-14-x")]
142        #[allow(deprecated)]
143        {
144            _default = crate::client::http::hyper_014::default_client();
145
146            // The main population for the upcoming default change: an older behavior version with
147            // the legacy stack compiled in, which is what a default build is today.
148            if _default.is_some() {
149                warn_legacy_client_default_is_changing(behavior_version);
150            }
151        }
152
153        // Fall back to the latest https stack so that an older behavior version still gets a
154        // working HTTP client rather than none at all. The legacy connector comes back empty both
155        // when it isn't compiled in and when it is compiled in without a TLS implementation
156        // (`hyper_014::default_client` requires `legacy-rustls-ring`), so key off the value rather
157        // than off `connector-hyper-0-14-x`.
158        //
159        // NOTE: this deliberately only runs when the legacy client came back empty, so builds that
160        // do have one keep getting it for these behavior versions, exactly as before.
161        #[cfg(feature = "default-https-client")]
162        if _default.is_none() {
163            let opts = crate::client::http::DefaultClientOptions::default()
164                .with_behavior_version(behavior_version);
165            _default = crate::client::http::default_https_client(opts);
166
167            // Say so rather than substituting a different HTTP stack silently: the behavior
168            // version asked for the legacy one, and a caller who pinned it for a hyper 0.14.x
169            // quirk needs to know they are not getting it.
170            if _default.is_some() {
171                tracing::warn!(
172                    behavior_version = ?behavior_version,
173                    "this behavior version selects the legacy hyper 0.14.x HTTP client, which is \
174                     not available in this build, so the default hyper 1.x HTTPS client is being \
175                     used instead. Enable the `legacy-https-client` feature on your AWS SDK crate \
176                     (or `aws-smithy-runtime/tls-rustls`) to get the legacy stack, or move to \
177                     `BehaviorVersion::v2026_01_12()` or later to stop seeing this warning.",
178                );
179            }
180        }
181    }
182
183    _default.map(|default| {
184        default_plugin("default_http_client_plugin", |components| {
185            components.with_http_client(Some(default))
186        })
187        .into_shared()
188    })
189}
190
191/// Runtime plugin that provides a default async sleep implementation.
192pub fn default_sleep_impl_plugin() -> Option<SharedRuntimePlugin> {
193    default_async_sleep().map(|default| {
194        default_plugin("default_sleep_impl_plugin", |components| {
195            components.with_sleep_impl(Some(default))
196        })
197        .into_shared()
198    })
199}
200
201/// Runtime plugin that provides a default time source.
202pub fn default_time_source_plugin() -> Option<SharedRuntimePlugin> {
203    Some(
204        default_plugin("default_time_source_plugin", |components| {
205            components.with_time_source(Some(SystemTimeSource::new()))
206        })
207        .into_shared(),
208    )
209}
210
211/// Runtime plugin that sets the default retry strategy, config (disabled), and partition.
212pub fn default_retry_config_plugin(
213    default_partition_name: impl Into<Cow<'static, str>>,
214) -> Option<SharedRuntimePlugin> {
215    let retry_partition = RetryPartition::new(default_partition_name);
216    Some(
217        default_plugin("default_retry_config_plugin", |components| {
218            components
219                .with_retry_strategy(Some(StandardRetryStrategy::new()))
220                .with_config_validator(SharedConfigValidator::base_client_config_fn(
221                    validate_retry_config,
222                ))
223                .with_interceptor(SharedInterceptor::permanent(TokenBucketProvider::new(
224                    retry_partition.clone(),
225                )))
226        })
227        .with_config(layer("default_retry_config", |layer| {
228            layer.store_put(RetryConfig::disabled());
229            layer.store_put(retry_partition);
230        }))
231        .into_shared(),
232    )
233}
234
235/// Runtime plugin that sets the default retry strategy, config, and partition.
236///
237/// This version respects the behavior version to enable retries by default for newer versions.
238/// For AWS SDK clients with BehaviorVersion >= v2026_01_12, retries are enabled by default.
239/// For all clients with BehaviorVersion >= v2026_11_10, the default config uses Retry Behavior 2.1.
240pub fn default_retry_config_plugin_v2(params: &DefaultPluginParams) -> Option<SharedRuntimePlugin> {
241    let retry_partition = RetryPartition::new(
242        params
243            .retry_partition_name
244            .as_ref()
245            .expect("retry partition name is required")
246            .clone(),
247    );
248    let is_aws_sdk = params.is_aws_sdk;
249    let behavior_version = params
250        .behavior_version
251        .unwrap_or_else(BehaviorVersion::latest);
252    Some(
253        default_plugin("default_retry_config_plugin", |components| {
254            components
255                .with_retry_strategy(Some(StandardRetryStrategy::new()))
256                .with_config_validator(SharedConfigValidator::base_client_config_fn(
257                    validate_retry_config,
258                ))
259                .with_interceptor(SharedInterceptor::permanent(TokenBucketProvider::new(
260                    retry_partition.clone(),
261                )))
262        })
263        .with_config(layer("default_retry_config", |layer| {
264            #[allow(deprecated)]
265            let retry_config =
266                if is_aws_sdk && behavior_version.is_at_least(BehaviorVersion::v2026_01_12()) {
267                    RetryConfig::standard()
268                } else {
269                    RetryConfig::disabled()
270                };
271            #[allow(deprecated)]
272            let retry_config = if behavior_version.is_at_least(BehaviorVersion::v2026_11_10()) {
273                retry_config
274                    .with_retry_spec(RetrySpec::v2_1())
275                    .with_reconnect_mode(ReconnectMode::ReuseAllConnections)
276            } else {
277                retry_config
278            };
279            layer.store_put(retry_config);
280            layer.store_put(retry_partition);
281        }))
282        .into_shared(),
283    )
284}
285
286fn validate_retry_config(
287    components: &RuntimeComponentsBuilder,
288    cfg: &ConfigBag,
289) -> Result<(), BoxError> {
290    if let Some(retry_config) = cfg.load::<RetryConfig>() {
291        if retry_config.has_retry() && components.sleep_impl().is_none() {
292            Err("An async sleep implementation is required for retry to work. Please provide a `sleep_impl` on \
293                 the config, or disable timeouts.".into())
294        } else {
295            Ok(())
296        }
297    } else {
298        Err(
299            "The default retry config was removed, and no other config was put in its place."
300                .into(),
301        )
302    }
303}
304
305/// Runtime plugin that sets the default timeout config (no timeouts).
306pub fn default_timeout_config_plugin() -> Option<SharedRuntimePlugin> {
307    Some(
308        default_plugin("default_timeout_config_plugin", |components| {
309            components.with_config_validator(SharedConfigValidator::base_client_config_fn(
310                validate_timeout_config,
311            ))
312        })
313        .with_config(layer("default_timeout_config", |layer| {
314            layer.store_put(TimeoutConfig::disabled());
315        }))
316        .into_shared(),
317    )
318}
319
320/// Runtime plugin that sets the default timeout config.
321///
322/// This version respects the behavior version to enable connection timeout by default for newer versions.
323/// For all clients with BehaviorVersion >= v2026_01_12, a 3.1s connection timeout is set.
324pub fn default_timeout_config_plugin_v2(
325    params: &DefaultPluginParams,
326) -> Option<SharedRuntimePlugin> {
327    let behavior_version = params
328        .behavior_version
329        .unwrap_or_else(BehaviorVersion::latest);
330    Some(
331        default_plugin("default_timeout_config_plugin", |components| {
332            components.with_config_validator(SharedConfigValidator::base_client_config_fn(
333                validate_timeout_config,
334            ))
335        })
336        .with_config(layer("default_timeout_config", |layer| {
337            #[allow(deprecated)]
338            let timeout_config = if behavior_version.is_at_least(BehaviorVersion::v2026_01_12()) {
339                // All clients with BMV >= v2026_01_12: Set connect_timeout only
340                TimeoutConfig::builder()
341                    .connect_timeout(DEFAULT_CONNECT_TIMEOUT)
342                    .build()
343            } else {
344                // Old behavior versions: All timeouts disabled
345                TimeoutConfig::disabled()
346            };
347            layer.store_put(timeout_config);
348        }))
349        .into_shared(),
350    )
351}
352
353fn validate_timeout_config(
354    components: &RuntimeComponentsBuilder,
355    cfg: &ConfigBag,
356) -> Result<(), BoxError> {
357    if let Some(timeout_config) = cfg.load::<TimeoutConfig>() {
358        if timeout_config.has_timeouts() && components.sleep_impl().is_none() {
359            Err("An async sleep implementation is required for timeouts to work. Please provide a `sleep_impl` on \
360                 the config, or disable timeouts.".into())
361        } else {
362            Ok(())
363        }
364    } else {
365        Err(
366            "The default timeout config was removed, and no other config was put in its place."
367                .into(),
368        )
369    }
370}
371
372/// Runtime plugin that registers the default identity cache implementation.
373pub fn default_identity_cache_plugin() -> Option<SharedRuntimePlugin> {
374    Some(
375        default_plugin("default_identity_cache_plugin", |components| {
376            components.with_identity_cache(Some(IdentityCache::lazy().build()))
377        })
378        .into_shared(),
379    )
380}
381
382/// Runtime plugin that sets the default stalled stream protection config.
383///
384/// By default, when throughput falls below 1/Bs for more than 5 seconds, the
385/// stream is cancelled.
386#[deprecated(
387    since = "1.2.0",
388    note = "This function wasn't intended to be public, and didn't take the behavior major version as an argument, so it couldn't be evolved over time."
389)]
390pub fn default_stalled_stream_protection_config_plugin() -> Option<SharedRuntimePlugin> {
391    #[expect(deprecated)]
392    default_stalled_stream_protection_config_plugin_v2(BehaviorVersion::v2023_11_09())
393}
394fn default_stalled_stream_protection_config_plugin_v2(
395    behavior_version: BehaviorVersion,
396) -> Option<SharedRuntimePlugin> {
397    Some(
398        default_plugin(
399            "default_stalled_stream_protection_config_plugin",
400            |components| {
401                components.with_config_validator(SharedConfigValidator::base_client_config_fn(
402                    validate_stalled_stream_protection_config,
403                ))
404            },
405        )
406        .with_config(layer("default_stalled_stream_protection_config", |layer| {
407            let mut config =
408                StalledStreamProtectionConfig::enabled().grace_period(Duration::from_secs(5));
409            // Before v2024_03_28, upload streams did not have stalled stream protection by default
410            #[expect(deprecated)]
411            if !behavior_version.is_at_least(BehaviorVersion::v2024_03_28()) {
412                config = config.upload_enabled(false);
413            }
414            layer.store_put(config.build());
415        }))
416        .into_shared(),
417    )
418}
419
420fn enforce_content_length_runtime_plugin() -> Option<SharedRuntimePlugin> {
421    Some(EnforceContentLengthRuntimePlugin::new().into_shared())
422}
423
424fn validate_stalled_stream_protection_config(
425    components: &RuntimeComponentsBuilder,
426    cfg: &ConfigBag,
427) -> Result<(), BoxError> {
428    if let Some(stalled_stream_protection_config) = cfg.load::<StalledStreamProtectionConfig>() {
429        if stalled_stream_protection_config.is_enabled() {
430            if components.sleep_impl().is_none() {
431                return Err(
432                    "An async sleep implementation is required for stalled stream protection to work. \
433                     Please provide a `sleep_impl` on the config, or disable stalled stream protection.".into());
434            }
435
436            if components.time_source().is_none() {
437                return Err(
438                    "A time source is required for stalled stream protection to work.\
439                     Please provide a `time_source` on the config, or disable stalled stream protection.".into());
440            }
441        }
442
443        Ok(())
444    } else {
445        Err(
446            "The default stalled stream protection config was removed, and no other config was put in its place."
447                .into(),
448        )
449    }
450}
451
452/// Arguments for the [`default_plugins`] method.
453///
454/// This is a struct to enable adding new parameters in the future without breaking the API.
455#[non_exhaustive]
456#[derive(Debug, Default)]
457pub struct DefaultPluginParams {
458    retry_partition_name: Option<Cow<'static, str>>,
459    behavior_version: Option<BehaviorVersion>,
460    is_aws_sdk: bool,
461}
462
463impl DefaultPluginParams {
464    /// Creates a new [`DefaultPluginParams`].
465    pub fn new() -> Self {
466        Default::default()
467    }
468
469    /// Sets the retry partition name.
470    pub fn with_retry_partition_name(mut self, name: impl Into<Cow<'static, str>>) -> Self {
471        self.retry_partition_name = Some(name.into());
472        self
473    }
474
475    /// Sets the behavior major version.
476    pub fn with_behavior_version(mut self, version: BehaviorVersion) -> Self {
477        self.behavior_version = Some(version);
478        self
479    }
480
481    /// Marks this as an AWS SDK client (enables retries by default for newer behavior versions).
482    pub fn with_is_aws_sdk(mut self, is_aws_sdk: bool) -> Self {
483        self.is_aws_sdk = is_aws_sdk;
484        self
485    }
486}
487
488/// All default plugins.
489pub fn default_plugins(
490    params: DefaultPluginParams,
491) -> impl IntoIterator<Item = SharedRuntimePlugin> {
492    let behavior_version = params
493        .behavior_version
494        .unwrap_or_else(BehaviorVersion::latest);
495
496    [
497        default_http_client_plugin_v2(behavior_version),
498        default_identity_cache_plugin(),
499        default_retry_config_plugin_v2(&params),
500        default_sleep_impl_plugin(),
501        default_time_source_plugin(),
502        default_timeout_config_plugin_v2(&params),
503        enforce_content_length_runtime_plugin(),
504        default_stalled_stream_protection_config_plugin_v2(behavior_version),
505    ]
506    .into_iter()
507    .flatten()
508    .collect::<Vec<SharedRuntimePlugin>>()
509}
510
511#[cfg(test)]
512mod tests {
513    use super::*;
514    use aws_smithy_runtime_api::client::runtime_plugin::{RuntimePlugin, RuntimePlugins};
515    #[cfg(any(feature = "default-https-client", feature = "tls-rustls"))]
516    use tracing_test::traced_test;
517
518    fn test_plugin_params(version: BehaviorVersion) -> DefaultPluginParams {
519        DefaultPluginParams::new()
520            .with_behavior_version(version)
521            .with_retry_partition_name("dontcare")
522            .with_is_aws_sdk(false) // Default to non-AWS SDK for existing tests
523    }
524    fn config_for(plugins: impl IntoIterator<Item = SharedRuntimePlugin>) -> ConfigBag {
525        let mut config = ConfigBag::base();
526        let plugins = RuntimePlugins::new().with_client_plugins(plugins);
527        plugins.apply_client_configuration(&mut config).unwrap();
528        config
529    }
530
531    #[test]
532    #[expect(deprecated)]
533    fn v2024_03_28_stalled_stream_protection_difference() {
534        let latest = config_for(default_plugins(test_plugin_params(
535            BehaviorVersion::latest(),
536        )));
537        let v2023 = config_for(default_plugins(test_plugin_params(
538            BehaviorVersion::v2023_11_09(),
539        )));
540
541        assert!(
542            latest
543                .load::<StalledStreamProtectionConfig>()
544                .unwrap()
545                .upload_enabled(),
546            "stalled stream protection on uploads MUST be enabled after v2024_03_28"
547        );
548        assert!(
549            !v2023
550                .load::<StalledStreamProtectionConfig>()
551                .unwrap()
552                .upload_enabled(),
553            "stalled stream protection on uploads MUST NOT be enabled before v2024_03_28"
554        );
555    }
556
557    #[test]
558    fn test_retry_enabled_for_aws_sdk() {
559        let params = DefaultPluginParams::new()
560            .with_retry_partition_name("test-partition")
561            .with_behavior_version(BehaviorVersion::latest())
562            .with_is_aws_sdk(true);
563        let plugin = default_retry_config_plugin_v2(&params).expect("plugin should be created");
564
565        let config = plugin.config().expect("config should exist");
566        let retry_config = config
567            .load::<RetryConfig>()
568            .expect("retry config should exist");
569
570        assert_eq!(
571            retry_config.max_attempts(),
572            3,
573            "retries should be enabled with max_attempts=3 for AWS SDK with latest behavior version"
574        );
575    }
576
577    #[test]
578    #[expect(deprecated)]
579    fn test_retry_disabled_for_aws_sdk_old_behavior_version() {
580        // Any version before v2026_01_12 should have retries disabled
581        let params = DefaultPluginParams::new()
582            .with_retry_partition_name("test-partition")
583            .with_behavior_version(BehaviorVersion::v2024_03_28())
584            .with_is_aws_sdk(true);
585        let plugin = default_retry_config_plugin_v2(&params).expect("plugin should be created");
586
587        let config = plugin.config().expect("config should exist");
588        let retry_config = config
589            .load::<RetryConfig>()
590            .expect("retry config should exist");
591
592        assert_eq!(
593            retry_config.max_attempts(),
594            1,
595            "retries should be disabled for AWS SDK with behavior version < v2026_01_12"
596        );
597    }
598
599    #[test]
600    #[allow(deprecated)]
601    fn test_retry_enabled_at_cutoff_version() {
602        // v2026_01_12 is the cutoff - retries should be enabled from this version onwards
603        let params = DefaultPluginParams::new()
604            .with_retry_partition_name("test-partition")
605            .with_behavior_version(BehaviorVersion::v2026_01_12())
606            .with_is_aws_sdk(true);
607        let plugin = default_retry_config_plugin_v2(&params).expect("plugin should be created");
608
609        let config = plugin.config().expect("config should exist");
610        let retry_config = config
611            .load::<RetryConfig>()
612            .expect("retry config should exist");
613
614        assert_eq!(
615            retry_config.max_attempts(),
616            3,
617            "retries should be enabled for AWS SDK starting from v2026_01_12"
618        );
619    }
620
621    #[test]
622    fn test_retry_disabled_for_non_aws_sdk() {
623        let params = DefaultPluginParams::new()
624            .with_retry_partition_name("test-partition")
625            .with_behavior_version(BehaviorVersion::latest())
626            .with_is_aws_sdk(false);
627        let plugin = default_retry_config_plugin_v2(&params).expect("plugin should be created");
628
629        let config = plugin.config().expect("config should exist");
630        let retry_config = config
631            .load::<RetryConfig>()
632            .expect("retry config should exist");
633
634        assert_eq!(
635            retry_config.max_attempts(),
636            1,
637            "retries should be disabled for non-AWS SDK clients"
638        );
639    }
640
641    #[test]
642    #[expect(deprecated)]
643    fn test_behavior_version_gates_retry_for_aws_sdk() {
644        // This test demonstrates the complete behavior:
645        // AWS SDK clients get retries enabled ONLY when BehaviorVersion >= v2026_01_12
646
647        // Test all behavior versions
648        let test_cases = vec![
649            (BehaviorVersion::v2023_11_09(), 1, "v2023_11_09 (old)"),
650            (BehaviorVersion::v2024_03_28(), 1, "v2024_03_28 (old)"),
651            (BehaviorVersion::v2025_01_17(), 1, "v2025_01_17 (old)"),
652            (BehaviorVersion::v2025_08_07(), 1, "v2025_08_07 (old)"),
653            (BehaviorVersion::v2026_01_12(), 3, "v2026_01_12 (cutoff)"),
654            (BehaviorVersion::latest(), 3, "latest"),
655        ];
656
657        for (version, expected_attempts, version_name) in test_cases {
658            let params = DefaultPluginParams::new()
659                .with_retry_partition_name("test-partition")
660                .with_behavior_version(version)
661                .with_is_aws_sdk(true);
662
663            let plugin = default_retry_config_plugin_v2(&params).expect("plugin should be created");
664            let config = plugin.config().expect("config should exist");
665            let retry_config = config
666                .load::<RetryConfig>()
667                .expect("retry config should exist");
668
669            assert_eq!(
670                retry_config.max_attempts(),
671                expected_attempts,
672                "AWS SDK with {} should have {} max attempts",
673                version_name,
674                expected_attempts
675            );
676        }
677    }
678
679    #[test]
680    #[expect(deprecated)]
681    fn test_complete_default_plugins_integration() {
682        // This test simulates the complete flow as it would happen in a real AWS SDK client
683        // It verifies that default_plugins() correctly applies retry config based on
684        // both is_aws_sdk flag and BehaviorVersion
685
686        // Scenario 1: AWS SDK with latest behavior version -> retries enabled
687        let params_aws_latest = DefaultPluginParams::new()
688            .with_retry_partition_name("aws-s3")
689            .with_behavior_version(BehaviorVersion::latest())
690            .with_is_aws_sdk(true);
691
692        let config_aws_latest = config_for(default_plugins(params_aws_latest));
693        let retry_aws_latest = config_aws_latest
694            .load::<RetryConfig>()
695            .expect("retry config should exist");
696        assert_eq!(
697            retry_aws_latest.max_attempts(),
698            3,
699            "AWS SDK with latest behavior version should have retries enabled (3 attempts)"
700        );
701
702        // Scenario 2: AWS SDK with old behavior version -> retries disabled
703        let params_aws_old = DefaultPluginParams::new()
704            .with_retry_partition_name("aws-s3")
705            .with_behavior_version(BehaviorVersion::v2024_03_28())
706            .with_is_aws_sdk(true);
707
708        let config_aws_old = config_for(default_plugins(params_aws_old));
709        let retry_aws_old = config_aws_old
710            .load::<RetryConfig>()
711            .expect("retry config should exist");
712        assert_eq!(
713            retry_aws_old.max_attempts(),
714            1,
715            "AWS SDK with old behavior version should have retries disabled (1 attempt)"
716        );
717
718        // Scenario 3: Non-AWS SDK (generic Smithy client) -> retries always disabled
719        let params_generic = DefaultPluginParams::new()
720            .with_retry_partition_name("my-service")
721            .with_behavior_version(BehaviorVersion::latest())
722            .with_is_aws_sdk(false);
723
724        let config_generic = config_for(default_plugins(params_generic));
725        let retry_generic = config_generic
726            .load::<RetryConfig>()
727            .expect("retry config should exist");
728        assert_eq!(
729            retry_generic.max_attempts(),
730            1,
731            "Non-AWS SDK clients should always have retries disabled (1 attempt)"
732        );
733
734        // Scenario 4: Verify the cutoff version v2026_01_12 is the exact boundary
735        let params_cutoff = DefaultPluginParams::new()
736            .with_retry_partition_name("aws-s3")
737            .with_behavior_version(BehaviorVersion::v2026_01_12())
738            .with_is_aws_sdk(true);
739
740        let config_cutoff = config_for(default_plugins(params_cutoff));
741        let retry_cutoff = config_cutoff
742            .load::<RetryConfig>()
743            .expect("retry config should exist");
744        assert_eq!(
745            retry_cutoff.max_attempts(),
746            3,
747            "AWS SDK with v2026_01_12 (the cutoff version) should have retries enabled (3 attempts)"
748        );
749    }
750
751    /// A behavior version older than `v2026_01_12` must still end up with an HTTP client whenever
752    /// the hyper 1.x stack is compiled in, rather than with none at all.
753    ///
754    /// The configuration that actually exercises the fallback is `connector-hyper-0-14-x` plus
755    /// `default-https-client` with no legacy TLS implementation: `hyper_014::default_client()`
756    /// returns `None` there, so the fallback is the only thing that can supply a client. Note that
757    /// `--all-features` does *not* exercise it, because `tls-rustls` gives the legacy connector a
758    /// TLS implementation and it returns `Some`, which would satisfy the assertion below no matter
759    /// what the fallback did. `tools/ci-scripts/check-rust-runtimes` runs that combination
760    /// explicitly so this test has teeth.
761    #[test]
762    #[expect(deprecated)]
763    fn old_behavior_version_still_gets_an_http_client() {
764        let old = default_http_client_plugin_v2(BehaviorVersion::v2024_03_28());
765        let latest = default_http_client_plugin_v2(BehaviorVersion::latest());
766
767        // The hyper 1.x stack is available, so both behavior versions get a client: the latest
768        // directly, and the older one either from a working legacy connector or from the fallback.
769        #[cfg(feature = "default-https-client")]
770        {
771            assert!(
772                old.is_some(),
773                "a pre-v2026_01_12 behavior version must fall back to the hyper 1.x client \
774                 instead of getting no HTTP client"
775            );
776            assert!(
777                latest.is_some(),
778                "the latest behavior version must get the hyper 1.x client"
779            );
780        }
781
782        // No hyper 1.x stack, so there is nothing to fall back to and the legacy connector is the
783        // only possible source. It yields a client only when it also has a TLS implementation.
784        #[cfg(all(not(feature = "default-https-client"), feature = "tls-rustls"))]
785        assert!(
786            old.is_some(),
787            "a pre-v2026_01_12 behavior version must still get the legacy client when that is \
788             the only stack compiled in"
789        );
790
791        // Neither stack is compiled in, so no default client is possible for either version.
792        #[cfg(all(
793            not(feature = "default-https-client"),
794            not(feature = "connector-hyper-0-14-x")
795        ))]
796        {
797            assert!(
798                old.is_none(),
799                "no HTTP client stack is compiled in, so there is nothing to install"
800            );
801            assert!(
802                latest.is_none(),
803                "no HTTP client stack is compiled in, so there is nothing to install"
804            );
805        }
806
807        let _ = (old, latest);
808    }
809
810    /// Falling back must not be silent: a caller who pinned an old behavior version for a
811    /// hyper 0.14.x quirk needs to learn that they are on the hyper 1.x client instead.
812    ///
813    /// Gated to the configurations where the fallback actually runs. With `tls-rustls` the legacy
814    /// connector has a TLS implementation and returns `Some`, so no fallback happens and there is
815    /// correctly nothing to warn about.
816    #[test]
817    #[traced_test]
818    #[expect(deprecated)]
819    #[cfg(all(feature = "default-https-client", not(feature = "tls-rustls")))]
820    fn falling_back_to_the_hyper_1x_client_warns() {
821        let old = default_http_client_plugin_v2(BehaviorVersion::v2024_03_28());
822        assert!(old.is_some(), "the fallback should have supplied a client");
823        assert!(
824            logs_contain("selects the legacy hyper 0.14.x HTTP client"),
825            "falling back to the hyper 1.x client must be logged"
826        );
827    }
828
829    /// While the legacy stack is still the default, a build that resolves to it must be told the
830    /// default is changing — otherwise the change arrives with no notice.
831    ///
832    /// Gated to a build where the legacy client actually yields something: `hyper_014::default_client`
833    /// needs `legacy-rustls-ring`, which `tls-rustls` supplies.
834    #[test]
835    #[traced_test]
836    #[expect(deprecated)]
837    #[cfg(feature = "tls-rustls")]
838    fn resolving_to_the_legacy_client_warns_that_the_default_is_changing() {
839        let old = default_http_client_plugin_v2(BehaviorVersion::v2024_03_28());
840        assert!(old.is_some(), "the legacy client should have been selected");
841        assert!(
842            logs_contain("the default becomes the hyper 1.x client"),
843            "resolving to the legacy client must announce the upcoming default change"
844        );
845        assert!(
846            logs_contain("legacy-https-client"),
847            "the warning must name the feature that pins the legacy client"
848        );
849    }
850
851    /// The warning is about *resolving to* the legacy client, so a build without it must stay quiet
852    /// rather than warn about a stack it never had.
853    #[test]
854    #[traced_test]
855    #[expect(deprecated)]
856    #[cfg(all(
857        feature = "default-https-client",
858        not(feature = "connector-hyper-0-14-x")
859    ))]
860    fn a_build_without_the_legacy_client_does_not_warn_about_it() {
861        let _ = default_http_client_plugin_v2(BehaviorVersion::v2024_03_28());
862        assert!(
863            !logs_contain("the default becomes the hyper 1.x client"),
864            "a build with no legacy client must not warn about the legacy default changing"
865        );
866    }
867
868    /// The converse: a behavior version that asks for the current stack has nothing to warn about.
869    #[test]
870    #[traced_test]
871    #[cfg(feature = "default-https-client")]
872    fn the_latest_behavior_version_does_not_warn() {
873        let latest = default_http_client_plugin_v2(BehaviorVersion::latest());
874        assert!(latest.is_some(), "the latest version should get a client");
875        assert!(
876            !logs_contain("selects the legacy hyper 0.14.x HTTP client"),
877            "the latest behavior version must not warn about the legacy stack"
878        );
879    }
880}