diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index eab2fb8087..c82295a0af 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -65,3 +65,23 @@ message = "Update MSRV to `1.76.0`" references = ["smithy-rs#3653"] meta = { "breaking" = true, "tada" = true, "bug" = false, "target" = "all" } author = "landonxjames" + +[[smithy-rs]] +message = """ +Compression is now supported for operations modeled with the `@requestCompression` trait. + +[**For more details, see the long-form changelog discussion**](https://github.com/smithy-lang/smithy-rs/discussions/3646). +""" +references = ["smithy-rs#2891"] +meta = { "breaking" = false, "bug" = false, "tada" = true, "target" = "client" } +author = "Velfi" + +[[aws-sdk-rust]] +message = """ +Compression is now supported for operations modeled with the `@requestCompression` trait. + +[**For more details, see the long-form changelog discussion**](https://github.com/smithy-lang/smithy-rs/discussions/3646). +""" +references = ["smithy-rs#2891"] +meta = { "breaking" = false, "bug" = false, "tada" = true } +author = "Velfi" diff --git a/aws/rust-runtime/aws-config/Cargo.toml b/aws/rust-runtime/aws-config/Cargo.toml index e9be8457d8..697476a911 100644 --- a/aws/rust-runtime/aws-config/Cargo.toml +++ b/aws/rust-runtime/aws-config/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-config" -version = "1.4.1" +version = "1.5.0" authors = [ "AWS Rust SDK Team ", "Russell Cohen ", @@ -14,12 +14,11 @@ repository = "https://github.com/smithy-lang/smithy-rs" [features] behavior-version-latest = [] client-hyper = ["aws-smithy-runtime/connector-hyper-0-14-x"] -rustls = ["aws-smithy-runtime/tls-rustls", "client-hyper"] -rt-tokio = ["aws-smithy-async/rt-tokio", "aws-smithy-runtime/rt-tokio", "tokio/rt"] -sso = ["dep:aws-sdk-sso", "dep:aws-sdk-ssooidc", "dep:ring", "dep:hex", "dep:zeroize", "aws-smithy-runtime-api/http-auth"] credentials-process = ["tokio/process"] - default = ["client-hyper", "rustls", "rt-tokio", "credentials-process", "sso"] +rt-tokio = ["aws-smithy-async/rt-tokio", "aws-smithy-runtime/rt-tokio", "tokio/rt"] +rustls = ["aws-smithy-runtime/tls-rustls", "client-hyper"] +sso = ["dep:aws-sdk-sso", "dep:aws-sdk-ssooidc", "dep:ring", "dep:hex", "dep:zeroize", "aws-smithy-runtime-api/http-auth"] # deprecated: this feature does nothing allow-compilation = [] diff --git a/aws/rust-runtime/aws-config/src/default_provider.rs b/aws/rust-runtime/aws-config/src/default_provider.rs index 845093bd00..fceb869fb0 100644 --- a/aws/rust-runtime/aws-config/src/default_provider.rs +++ b/aws/rust-runtime/aws-config/src/default_provider.rs @@ -57,3 +57,9 @@ pub mod ignore_configured_endpoint_urls; /// Default endpoint URL provider chain pub mod endpoint_url; + +/// Default "disable request compression" provider chain +pub mod disable_request_compression; + +/// Default "request minimum compression size bytes" provider chain +pub mod request_min_compression_size_bytes; diff --git a/aws/rust-runtime/aws-config/src/default_provider/disable_request_compression.rs b/aws/rust-runtime/aws-config/src/default_provider/disable_request_compression.rs new file mode 100644 index 0000000000..a43886913b --- /dev/null +++ b/aws/rust-runtime/aws-config/src/default_provider/disable_request_compression.rs @@ -0,0 +1,122 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +use crate::environment::parse_bool; +use crate::provider_config::ProviderConfig; +use aws_runtime::env_config::EnvConfigValue; +use aws_smithy_types::error::display::DisplayErrorContext; + +mod env { + pub(super) const DISABLE_REQUEST_COMPRESSION: &str = "AWS_DISABLE_REQUEST_COMPRESSION"; +} + +mod profile_key { + pub(super) const DISABLE_REQUEST_COMPRESSION: &str = "disable_request_compression"; +} + +/// Load the value for "disable request compression". +/// +/// This checks the following sources: +/// 1. The environment variable `AWS_DISABLE_REQUEST_COMPRESSION=true/false` +/// 2. The profile key `disable_request_compression=true/false` +/// +/// If invalid values are found, the provider will return None and an error will be logged. +pub(crate) async fn disable_request_compression_provider( + provider_config: &ProviderConfig, +) -> Option { + let env = provider_config.env(); + let profiles = provider_config.profile().await; + + EnvConfigValue::new() + .env(env::DISABLE_REQUEST_COMPRESSION) + .profile(profile_key::DISABLE_REQUEST_COMPRESSION) + .validate(&env, profiles, parse_bool) + .map_err( + |err| tracing::warn!(err = %DisplayErrorContext(&err), "invalid value for `disable request compression` setting"), + ) + .unwrap_or(None) +} + +#[cfg(test)] +mod test { + use super::disable_request_compression_provider; + #[allow(deprecated)] + use crate::profile::profile_file::{ProfileFileKind, ProfileFiles}; + use crate::provider_config::ProviderConfig; + use aws_types::os_shim_internal::{Env, Fs}; + use tracing_test::traced_test; + + #[tokio::test] + #[traced_test] + async fn log_error_on_invalid_value() { + let conf = ProviderConfig::empty().with_env(Env::from_slice(&[( + "AWS_DISABLE_REQUEST_COMPRESSION", + "not-a-boolean", + )])); + assert_eq!(disable_request_compression_provider(&conf).await, None); + assert!(logs_contain( + "invalid value for `disable request compression` setting" + )); + assert!(logs_contain("AWS_DISABLE_REQUEST_COMPRESSION")); + } + + #[tokio::test] + #[traced_test] + async fn environment_priority() { + let conf = ProviderConfig::empty() + .with_env(Env::from_slice(&[( + "AWS_DISABLE_REQUEST_COMPRESSION", + "TRUE", + )])) + .with_profile_config( + Some( + #[allow(deprecated)] + ProfileFiles::builder() + .with_file( + #[allow(deprecated)] + ProfileFileKind::Config, + "conf", + ) + .build(), + ), + None, + ) + .with_fs(Fs::from_slice(&[( + "conf", + "[default]\ndisable_request_compression = false", + )])); + assert_eq!( + disable_request_compression_provider(&conf).await, + Some(true) + ); + } + + #[tokio::test] + #[traced_test] + async fn profile_config_works() { + let conf = ProviderConfig::empty() + .with_profile_config( + Some( + #[allow(deprecated)] + ProfileFiles::builder() + .with_file( + #[allow(deprecated)] + ProfileFileKind::Config, + "conf", + ) + .build(), + ), + None, + ) + .with_fs(Fs::from_slice(&[( + "conf", + "[default]\ndisable_request_compression = true", + )])); + assert_eq!( + disable_request_compression_provider(&conf).await, + Some(true) + ); + } +} diff --git a/aws/rust-runtime/aws-config/src/default_provider/request_min_compression_size_bytes.rs b/aws/rust-runtime/aws-config/src/default_provider/request_min_compression_size_bytes.rs new file mode 100644 index 0000000000..4ccbbf84b3 --- /dev/null +++ b/aws/rust-runtime/aws-config/src/default_provider/request_min_compression_size_bytes.rs @@ -0,0 +1,127 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +use crate::environment::parse_uint; +use crate::provider_config::ProviderConfig; +use aws_runtime::env_config::EnvConfigValue; +use aws_smithy_types::error::display::DisplayErrorContext; + +mod env { + pub(super) const REQUEST_MIN_COMPRESSION_SIZE_BYTES: &str = + "AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTES"; +} + +mod profile_key { + pub(super) const REQUEST_MIN_COMPRESSION_SIZE_BYTES: &str = + "request_min_compression_size_bytes"; +} + +/// Load the value for "request minimum compression size bytes". +/// +/// This checks the following sources: +/// 1. The environment variable `AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTES=10240` +/// 2. The profile key `request_min_compression_size_bytes=10240` +/// +/// If invalid values are found, the provider will return None and an error will be logged. +pub(crate) async fn request_min_compression_size_bytes_provider( + provider_config: &ProviderConfig, +) -> Option { + let env = provider_config.env(); + let profiles = provider_config.profile().await; + + EnvConfigValue::new() + .env(env::REQUEST_MIN_COMPRESSION_SIZE_BYTES) + .profile(profile_key::REQUEST_MIN_COMPRESSION_SIZE_BYTES) + .validate(&env, profiles, parse_uint) + .map_err( + |err| tracing::warn!(err = %DisplayErrorContext(&err), "invalid value for `request minimum compression size bytes` setting"), + ) + .unwrap_or(None) +} + +#[cfg(test)] +mod test { + use super::request_min_compression_size_bytes_provider; + #[allow(deprecated)] + use crate::profile::profile_file::{ProfileFileKind, ProfileFiles}; + use crate::provider_config::ProviderConfig; + use aws_types::os_shim_internal::{Env, Fs}; + use tracing_test::traced_test; + + #[tokio::test] + #[traced_test] + async fn log_error_on_invalid_value() { + let conf = ProviderConfig::empty().with_env(Env::from_slice(&[( + "AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTES", + "not-a-uint", + )])); + assert_eq!( + request_min_compression_size_bytes_provider(&conf).await, + None + ); + assert!(logs_contain( + "invalid value for `request minimum compression size bytes` setting" + )); + assert!(logs_contain("AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTES")); + } + + #[tokio::test] + #[traced_test] + async fn environment_priority() { + let conf = ProviderConfig::empty() + .with_env(Env::from_slice(&[( + "AWS_REQUEST_MIN_COMPRESSION_SIZE_BYTES", + "99", + )])) + .with_profile_config( + Some( + #[allow(deprecated)] + ProfileFiles::builder() + .with_file( + #[allow(deprecated)] + ProfileFileKind::Config, + "conf", + ) + .build(), + ), + None, + ) + .with_fs(Fs::from_slice(&[( + "conf", + "[default]\nrequest_min_compression_size_bytes = 100", + )])); + assert_eq!( + request_min_compression_size_bytes_provider(&conf).await, + Some(99) + ); + } + + #[tokio::test] + #[traced_test] + async fn profile_config_works() { + let conf = ProviderConfig::empty() + .with_profile_config( + Some( + #[allow(deprecated)] + ProfileFiles::builder() + .with_file( + #[allow(deprecated)] + ProfileFileKind::Config, + "conf", + ) + .build(), + ), + None, + ) + .with_fs(Fs::from_slice(&[( + "conf", + "[default]\nrequest_min_compression_size_bytes = 22", + )])); + assert_eq!( + request_min_compression_size_bytes_provider(&conf).await, + Some(22) + ); + } +} diff --git a/aws/rust-runtime/aws-config/src/environment/mod.rs b/aws/rust-runtime/aws-config/src/environment/mod.rs index 3d5a35920a..d43dc6588f 100644 --- a/aws/rust-runtime/aws-config/src/environment/mod.rs +++ b/aws/rust-runtime/aws-config/src/environment/mod.rs @@ -41,6 +41,25 @@ pub(crate) fn parse_bool(value: &str) -> Result { } } +#[derive(Debug)] +pub(crate) struct InvalidUintValue { + value: String, +} + +impl fmt::Display for InvalidUintValue { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{} is not a valid u32", self.value) + } +} + +impl Error for InvalidUintValue {} + +pub(crate) fn parse_uint(value: &str) -> Result { + value.parse::().map_err(|_| InvalidUintValue { + value: value.to_string(), + }) +} + #[derive(Debug)] pub(crate) struct InvalidUrlValue { value: String, diff --git a/aws/rust-runtime/aws-config/src/lib.rs b/aws/rust-runtime/aws-config/src/lib.rs index 8d7adc10bf..cfdf6e5ad2 100644 --- a/aws/rust-runtime/aws-config/src/lib.rs +++ b/aws/rust-runtime/aws-config/src/lib.rs @@ -230,7 +230,8 @@ mod loader { use aws_types::SdkConfig; use crate::default_provider::{ - app_name, credentials, endpoint_url, ignore_configured_endpoint_urls as ignore_ep, region, + app_name, credentials, disable_request_compression, endpoint_url, + ignore_configured_endpoint_urls as ignore_ep, region, request_min_compression_size_bytes, retry_config, timeout_config, use_dual_stack, use_fips, }; use crate::meta::region::ProvideRegion; @@ -274,6 +275,8 @@ mod loader { use_fips: Option, use_dual_stack: Option, time_source: Option, + disable_request_compression: Option, + request_min_compression_size_bytes: Option, stalled_stream_protection_config: Option, env: Option, fs: Option, @@ -661,6 +664,18 @@ mod loader { self } + #[doc = docs_for!(disable_request_compression)] + pub fn disable_request_compression(mut self, disable_request_compression: bool) -> Self { + self.disable_request_compression = Some(disable_request_compression); + self + } + + #[doc = docs_for!(request_min_compression_size_bytes)] + pub fn request_min_compression_size_bytes(mut self, size: u32) -> Self { + self.request_min_compression_size_bytes = Some(size); + self + } + /// Override the [`StalledStreamProtectionConfig`] used to build [`SdkConfig`]. /// /// This configures stalled stream protection. When enabled, download streams @@ -778,6 +793,22 @@ mod loader { .await }; + let disable_request_compression = if self.disable_request_compression.is_some() { + self.disable_request_compression + } else { + disable_request_compression::disable_request_compression_provider(&conf).await + }; + + let request_min_compression_size_bytes = + if self.request_min_compression_size_bytes.is_some() { + self.request_min_compression_size_bytes + } else { + request_min_compression_size_bytes::request_min_compression_size_bytes_provider( + &conf, + ) + .await + }; + let base_config = timeout_config::default_provider() .configure(&conf) .timeout_config() @@ -853,8 +884,8 @@ mod loader { v } }; - builder.set_endpoint_url(endpoint_url); + builder.set_endpoint_url(endpoint_url); builder.set_behavior_version(self.behavior_version); builder.set_http_client(self.http_client); builder.set_app_name(app_name); @@ -875,6 +906,8 @@ mod loader { builder.set_sleep_impl(sleep_impl); builder.set_use_fips(use_fips); builder.set_use_dual_stack(use_dual_stack); + builder.set_disable_request_compression(disable_request_compression); + builder.set_request_min_compression_size_bytes(request_min_compression_size_bytes); builder.set_stalled_stream_protection(self.stalled_stream_protection_config); builder.build() } @@ -1045,7 +1078,7 @@ mod loader { } #[tokio::test] - async fn load_fips() { + async fn load_use_fips() { let conf = base_conf().use_fips(true).load().await; assert_eq!(Some(true), conf.use_fips()); } @@ -1059,6 +1092,27 @@ mod loader { assert_eq!(None, conf.use_dual_stack()); } + #[tokio::test] + async fn load_disable_request_compression() { + let conf = base_conf().disable_request_compression(true).load().await; + assert_eq!(Some(true), conf.disable_request_compression()); + + let conf = base_conf().load().await; + assert_eq!(None, conf.disable_request_compression()); + } + + #[tokio::test] + async fn load_request_min_compression_size_bytes() { + let conf = base_conf() + .request_min_compression_size_bytes(99) + .load() + .await; + assert_eq!(Some(99), conf.request_min_compression_size_bytes()); + + let conf = base_conf().load().await; + assert_eq!(None, conf.request_min_compression_size_bytes()); + } + #[tokio::test] async fn app_name() { let app_name = AppName::new("my-app-name").unwrap(); diff --git a/aws/rust-runtime/aws-types/Cargo.toml b/aws/rust-runtime/aws-types/Cargo.toml index c8f6870b41..85034cc354 100644 --- a/aws/rust-runtime/aws-types/Cargo.toml +++ b/aws/rust-runtime/aws-types/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-types" -version = "1.2.1" +version = "1.3.0" authors = ["AWS Rust SDK Team ", "Russell Cohen "] description = "Cross-service types for the AWS SDK." edition = "2021" diff --git a/aws/rust-runtime/aws-types/src/sdk_config.rs b/aws/rust-runtime/aws-types/src/sdk_config.rs index d31da2249a..c26d8741be 100644 --- a/aws/rust-runtime/aws-types/src/sdk_config.rs +++ b/aws/rust-runtime/aws-types/src/sdk_config.rs @@ -48,8 +48,25 @@ If no dual-stack endpoint is available the request MAY return an error. **Note**: Some services do not offer dual-stack as a configurable parameter (e.g. Code Catalyst). For these services, this setting has no effect" }; + (time_source) => { +"The time source use to use for this client. - (time_source) => { "The time source use to use for this client. This only needs to be required for creating deterministic tests or platforms where `SystemTime::now()` is not supported." }; +This only needs to be required for creating deterministic tests or platforms where `SystemTime::now()` is not supported."}; + (disable_request_compression) => { +"When `true`, disable request compression. Defaults to `false`. + +**Only some services support request compression.** For services +that don't support request compression, this setting does nothing. +" }; + (request_min_compression_size_bytes) => { +"The minimum size of request that should be compressed. Defaults to `10240` bytes. + +When a request body's size is lower than this, request compression will be skipped. +This is useful for request bodies because, for small request bodies, compression may actually increase their size. + +**Only some services support request compression.** For services +that don't support request compression, this setting does nothing. +" }; } } @@ -73,6 +90,8 @@ pub struct SdkConfig { behavior_version: Option, service_config: Option>, config_origins: HashMap<&'static str, Origin>, + disable_request_compression: Option, + request_min_compression_size_bytes: Option, } /// Builder for AWS Shared Configuration @@ -99,6 +118,8 @@ pub struct Builder { behavior_version: Option, service_config: Option>, config_origins: HashMap<&'static str, Origin>, + disable_request_compression: Option, + request_min_compression_size_bytes: Option, } impl Builder { @@ -601,6 +622,39 @@ impl Builder { self } + #[doc = docs_for!(disable_request_compression)] + pub fn disable_request_compression(mut self, disable_request_compression: bool) -> Self { + self.set_disable_request_compression(Some(disable_request_compression)); + self + } + + #[doc = docs_for!(disable_request_compression)] + pub fn set_disable_request_compression( + &mut self, + disable_request_compression: Option, + ) -> &mut Self { + self.disable_request_compression = disable_request_compression; + self + } + + #[doc = docs_for!(request_min_compression_size_bytes)] + pub fn request_min_compression_size_bytes( + mut self, + request_min_compression_size_bytes: u32, + ) -> Self { + self.set_request_min_compression_size_bytes(Some(request_min_compression_size_bytes)); + self + } + + #[doc = docs_for!(request_min_compression_size_bytes)] + pub fn set_request_min_compression_size_bytes( + &mut self, + request_min_compression_size_bytes: Option, + ) -> &mut Self { + self.request_min_compression_size_bytes = request_min_compression_size_bytes; + self + } + /// Sets the [`BehaviorVersion`] for the [`SdkConfig`] pub fn behavior_version(mut self, behavior_version: BehaviorVersion) -> Self { self.set_behavior_version(Some(behavior_version)); @@ -664,6 +718,8 @@ impl Builder { stalled_stream_protection_config: self.stalled_stream_protection_config, service_config: self.service_config, config_origins: self.config_origins, + disable_request_compression: self.disable_request_compression, + request_min_compression_size_bytes: self.request_min_compression_size_bytes, } } } @@ -805,6 +861,16 @@ impl SdkConfig { self.use_dual_stack } + /// When true, request compression is disabled. + pub fn disable_request_compression(&self) -> Option { + self.disable_request_compression + } + + /// Configured minimum request compression size. + pub fn request_min_compression_size_bytes(&self) -> Option { + self.request_min_compression_size_bytes + } + /// Configured stalled stream protection pub fn stalled_stream_protection(&self) -> Option { self.stalled_stream_protection_config.clone() @@ -865,6 +931,8 @@ impl SdkConfig { stalled_stream_protection_config: self.stalled_stream_protection_config, service_config: self.service_config, config_origins: self.config_origins, + disable_request_compression: self.disable_request_compression, + request_min_compression_size_bytes: self.request_min_compression_size_bytes, } } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt index 9facd1ede9..dc628c9af2 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt @@ -59,6 +59,7 @@ val DECORATORS: List = RemoveDefaultsDecorator(), TokenProvidersDecorator(), ServiceEnvConfigDecorator(), + HttpRequestCompressionDecorator(), ), // Service specific decorators ApiGatewayDecorator().onlyApplyTo("com.amazonaws.apigateway#BackplaneControlService"), diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestCompressionDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestCompressionDecorator.kt new file mode 100644 index 0000000000..68ce154968 --- /dev/null +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestCompressionDecorator.kt @@ -0,0 +1,141 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rustsdk + +import software.amazon.smithy.model.knowledge.TopDownIndex +import software.amazon.smithy.model.traits.RequestCompressionTrait +import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext +import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization +import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.preludeScope +import software.amazon.smithy.rust.codegen.core.smithy.customize.AdHocCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.adhocCustomization +import software.amazon.smithy.rust.codegen.core.util.thenSingletonListOf + +class HttpRequestCompressionDecorator : ClientCodegenDecorator { + override val name: String = "HttpRequestCompression" + override val order: Byte = 0 + + private fun usesRequestCompression(codegenContext: ClientCodegenContext): Boolean { + val index = TopDownIndex.of(codegenContext.model) + val ops = index.getContainedOperations(codegenContext.serviceShape.id) + return ops.any { it.hasTrait(RequestCompressionTrait.ID) } + } + + override fun configCustomizations( + codegenContext: ClientCodegenContext, + baseCustomizations: List, + ): List { + return baseCustomizations + + usesRequestCompression(codegenContext).thenSingletonListOf { + HttpRequestCompressionConfigCustomization(codegenContext) + } + } + + override fun extraSections(codegenContext: ClientCodegenContext): List { + return usesRequestCompression(codegenContext).thenSingletonListOf { + adhocCustomization { section -> + rust( + """ + ${section.serviceConfigBuilder} = ${section.serviceConfigBuilder} + .disable_request_compression(${section.sdkConfig}.disable_request_compression()); + ${section.serviceConfigBuilder} = ${section.serviceConfigBuilder} + .request_min_compression_size_bytes(${section.sdkConfig}.request_min_compression_size_bytes()); + """, + ) + } + } + } +} + +class HttpRequestCompressionConfigCustomization(codegenContext: ClientCodegenContext) : ConfigCustomization() { + private val runtimeConfig = codegenContext.runtimeConfig + private val codegenScope = + arrayOf( + "DisableRequestCompression" to RuntimeType.clientRequestCompression(runtimeConfig).resolve("DisableRequestCompression"), + "RequestMinCompressionSizeBytes" to RuntimeType.clientRequestCompression(runtimeConfig).resolve("RequestMinCompressionSizeBytes"), + "Storable" to RuntimeType.smithyTypes(runtimeConfig).resolve("config_bag::Storable"), + "StoreReplace" to RuntimeType.smithyTypes(runtimeConfig).resolve("config_bag::StoreReplace"), + *preludeScope, + ) + + override fun section(section: ServiceConfig) = + writable { + when (section) { + ServiceConfig.ConfigImpl -> { + rustTemplate( + """ + /// Returns the `disable request compression` setting, if it was provided. + pub fn disable_request_compression(&self) -> #{Option} { + self.config.load::<#{DisableRequestCompression}>().map(|it| it.0) + } + + /// Returns the `request minimum compression size in bytes`, if it was provided. + pub fn request_min_compression_size_bytes(&self) -> #{Option} { + self.config.load::<#{RequestMinCompressionSizeBytes}>().map(|it| it.0) + } + """, + *codegenScope, + ) + } + + ServiceConfig.BuilderImpl -> { + rustTemplate( + """ + /// Sets the `disable request compression` used when making requests. + pub fn disable_request_compression(mut self, disable_request_compression: impl #{Into}<#{Option}>) -> Self { + self.set_disable_request_compression(disable_request_compression.into()); + self + } + + /// Sets the `request minimum compression size in bytes` used when making requests. + pub fn request_min_compression_size_bytes(mut self, request_min_compression_size_bytes: impl #{Into}<#{Option}>) -> Self { + self.set_request_min_compression_size_bytes(request_min_compression_size_bytes.into()); + self + } + """, + *codegenScope, + ) + + rustTemplate( + """ + /// Sets the `disable request compression` used when making requests. + pub fn set_disable_request_compression(&mut self, disable_request_compression: #{Option}) -> &mut Self { + self.config.store_or_unset::<#{DisableRequestCompression}>(disable_request_compression.map(Into::into)); + self + } + + /// Sets the `request minimum compression size in bytes` used when making requests. + pub fn set_request_min_compression_size_bytes(&mut self, request_min_compression_size_bytes: #{Option}) -> &mut Self { + self.config.store_or_unset::<#{RequestMinCompressionSizeBytes}>(request_min_compression_size_bytes.map(Into::into)); + self + } + """, + *codegenScope, + ) + } + + is ServiceConfig.BuilderFromConfigBag -> { + rustTemplate( + """ + ${section.builder}.set_disable_request_compression( + ${section.configBag}.load::<#{DisableRequestCompression}>().cloned().map(|it| it.0)); + ${section.builder}.set_request_min_compression_size_bytes( + ${section.configBag}.load::<#{RequestMinCompressionSizeBytes}>().cloned().map(|it| it.0)); + """, + *codegenScope, + ) + } + + else -> emptySection + } + } +} diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/HttpRequestCompressionDecoratorTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/HttpRequestCompressionDecoratorTest.kt new file mode 100644 index 0000000000..4fadca51ef --- /dev/null +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/HttpRequestCompressionDecoratorTest.kt @@ -0,0 +1,321 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rustsdk + +import org.junit.jupiter.api.Test +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.preludeScope +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.integrationTest + +class HttpRequestCompressionDecoratorTest { + companion object { + // Can't use the dollar sign in a multiline string with doing it like this. + private const val PREFIX = "\$version: \"2\"" + val model = + """ + $PREFIX + namespace test + + use aws.api#service + use aws.auth#sigv4 + use aws.protocols#restJson1 + use smithy.rules#endpointRuleSet + + @service(sdkId: "dontcare") + @restJson1 + @sigv4(name: "dontcare") + @auth([sigv4]) + @endpointRuleSet({ + "version": "1.0", + "rules": [{ "type": "endpoint", "conditions": [], "endpoint": { "url": "https://example.com" } }], + "parameters": { + "Region": { "required": false, "type": "String", "builtIn": "AWS::Region" }, + } + }) + service TestService { + version: "2023-01-01", + operations: [SomeOperation, SomeStreamingOperation, NotACompressibleOperation] + } + + @streaming + blob StreamingBlob + + blob NonStreamingBlob + + @http(uri: "/SomeOperation", method: "POST") + @optionalAuth + @requestCompression(encodings: ["gzip"]) + operation SomeOperation { + input: SomeInput, + output: SomeOutput + } + + @input + structure SomeInput { + @httpPayload + @required + body: NonStreamingBlob + } + + @output + structure SomeOutput {} + + @http(uri: "/SomeStreamingOperation", method: "POST") + @optionalAuth + @requestCompression(encodings: ["gzip"]) + operation SomeStreamingOperation { + input: SomeStreamingInput, + output: SomeStreamingOutput + } + + @input + structure SomeStreamingInput { + @httpPayload + @required + body: StreamingBlob + } + + @output + structure SomeStreamingOutput {} + + @http(uri: "/NotACompressibleOperation", method: "PUT") + @optionalAuth + operation NotACompressibleOperation { + input: SomeIncompressibleInput, + output: SomeIncompressibleOutput + } + + @input + structure SomeIncompressibleInput { + @httpPayload + @required + body: NonStreamingBlob + } + + @output + structure SomeIncompressibleOutput {} + """.asSmithyModel() + } + + @Test + fun smokeTestSdkCodegen() { + awsSdkIntegrationTest(model) { _, _ -> + // it should compile + } + } + + @Test + fun requestCompressionWorks() { + awsSdkIntegrationTest(model) { context, rustCrate -> + val rc = context.runtimeConfig + val moduleName = context.moduleUseName() + rustCrate.integrationTest("request_compression") { + rustTemplate( + """ + ##![cfg(feature = "test-util")] + + use #{ByteStream}; + use #{Blob}; + use #{Region}; + use #{pretty_assertions}::{assert_eq, assert_ne}; + + const UNCOMPRESSED_INPUT: &[u8] = b"Action=PutMetricData&Version=2010-08-01&Namespace=Namespace&MetricData.member.1.MetricName=metric&MetricData.member.1.Unit=Bytes&MetricData.member.1.Value=128"; + // This may break if we ever change the default compression level. + const COMPRESSED_OUTPUT: &[u8] = &[ + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 109, 139, 49, 14, 128, 32, 16, 4, 127, 67, 39, 1, 43, 155, + 43, 52, 182, 26, 27, 233, 79, 114, 5, 137, 160, 129, 163, 240, 247, 6, 77, 180, 161, 155, 204, + 206, 246, 150, 221, 17, 96, 201, 60, 17, 71, 103, 71, 100, 20, 134, 98, 42, 182, 85, 90, 53, + 170, 107, 148, 22, 51, 122, 74, 39, 90, 130, 143, 196, 255, 144, 158, 252, 70, 81, 106, 249, + 186, 210, 128, 127, 176, 90, 173, 193, 49, 12, 23, 83, 170, 206, 6, 247, 76, 160, 219, 238, 6, + 30, 221, 9, 253, 158, 0, 0, 0, + ]; + + ##[#{tokio}::test] + async fn test_request_compression_isnt_applied_unless_modeled() { + let (http_client, rx) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); + let config = $moduleName::Config::builder() + .region(Region::from_static("doesntmatter")) + .with_test_defaults() + .http_client(http_client) + .disable_request_compression(true) + .build(); + + let client = $moduleName::Client::from_conf(config); + let _ = client.not_a_compressible_operation().body(Blob::new(UNCOMPRESSED_INPUT)).send().await; + let request = rx.expect_request(); + // Check that the content-encoding header is not set. + assert_eq!(None, request.headers().get("content-encoding")); + + let compressed_body = ByteStream::from(request.into_body()).collect().await.unwrap().to_vec(); + // Assert input body was not compressed + assert_eq!(UNCOMPRESSED_INPUT, compressed_body.as_slice()) + } + + ##[#{tokio}::test] + async fn test_request_compression_can_be_disabled() { + let (http_client, rx) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); + let config = $moduleName::Config::builder() + .region(Region::from_static("doesntmatter")) + .with_test_defaults() + .http_client(http_client) + .disable_request_compression(true) + .build(); + + let client = $moduleName::Client::from_conf(config); + let _ = client.some_operation().body(Blob::new(UNCOMPRESSED_INPUT)).send().await; + let request = rx.expect_request(); + // Check that the content-encoding header is not set to "gzip" + assert_ne!(Some("gzip"), request.headers().get("content-encoding")); + + let compressed_body = ByteStream::from(request.into_body()).collect().await.unwrap().to_vec(); + // Assert input body was not compressed + assert_eq!(UNCOMPRESSED_INPUT, compressed_body.as_slice()) + } + + ##[#{tokio}::test] + async fn test_request_min_size_body_over_minimum() { + let (http_client, rx) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); + let config = $moduleName::Config::builder() + .region(Region::from_static("doesntmatter")) + .with_test_defaults() + .http_client(http_client) + .disable_request_compression(false) + .request_min_compression_size_bytes(128) + .build(); + + let client = $moduleName::Client::from_conf(config); + let _ = client.some_operation().body(Blob::new(UNCOMPRESSED_INPUT)).send().await; + let request = rx.expect_request(); + // Check that the content-encoding header is set to "gzip" + assert_eq!(Some("gzip"), request.headers().get("content-encoding")); + + let compressed_body = ByteStream::from(request.into_body()).collect().await.unwrap().to_vec(); + // Assert input body was compressed + assert_eq!(COMPRESSED_OUTPUT, compressed_body.as_slice()) + } + + ##[#{tokio}::test] + async fn test_request_min_size_body_under_minimum() { + let (http_client, rx) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); + let config = $moduleName::Config::builder() + .region(Region::from_static("doesntmatter")) + .with_test_defaults() + .http_client(http_client) + .disable_request_compression(false) + .request_min_compression_size_bytes(256) + .build(); + + let client = $moduleName::Client::from_conf(config); + let _ = client.some_operation().body(Blob::new(UNCOMPRESSED_INPUT)).send().await; + let request = rx.expect_request(); + // Check that the content-encoding header is not set to "gzip" + assert_ne!(Some("gzip"), request.headers().get("content-encoding")); + + let compressed_body = ByteStream::from(request.into_body()).collect().await.unwrap().to_vec(); + // Assert input body was not compressed + assert_eq!(UNCOMPRESSED_INPUT, compressed_body.as_slice()) + } + + ##[#{tokio}::test] + async fn test_request_compression_implicitly_enabled() { + let (http_client, rx) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); + let config = $moduleName::Config::builder() + .region(Region::from_static("doesntmatter")) + .with_test_defaults() + .http_client(http_client) + .request_min_compression_size_bytes(128) + .build(); + + let client = $moduleName::Client::from_conf(config); + let _ = client.some_operation().body(Blob::new(UNCOMPRESSED_INPUT)).send().await; + let request = rx.expect_request(); + // Check that the content-encoding header is set to "gzip" + assert_eq!(Some("gzip"), request.headers().get("content-encoding")); + + let compressed_body = ByteStream::from(request.into_body()).collect().await.unwrap().to_vec(); + // Assert input body was compressed + assert_eq!(COMPRESSED_OUTPUT, compressed_body.as_slice()) + } + + ##[#{tokio}::test] + async fn test_request_compression_min_size_default() { + let (http_client, rx) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); + let config = $moduleName::Config::builder() + .region(Region::from_static("doesntmatter")) + .with_test_defaults() + .http_client(http_client) + .disable_request_compression(false) + .build(); + + let client = $moduleName::Client::from_conf(config); + let _ = client.some_operation().body(Blob::new(UNCOMPRESSED_INPUT)).send().await; + let request = rx.expect_request(); + // Check that the content-encoding header is not set to "gzip" + assert_ne!(Some("gzip"), request.headers().get("content-encoding")); + + let compressed_body = ByteStream::from(request.into_body()).collect().await.unwrap().to_vec(); + // Assert input body was not compressed + assert_eq!(UNCOMPRESSED_INPUT, compressed_body.as_slice()) + } + + ##[#{tokio}::test] + async fn test_request_compression_streaming_body() { + let (http_client, rx) = ::aws_smithy_runtime::client::http::test_util::capture_request(None); + let config = $moduleName::Config::builder() + .region(Region::from_static("doesntmatter")) + .with_test_defaults() + .http_client(http_client) + .disable_request_compression(false) + // Since our streaming body is sized, we have to set this. + .request_min_compression_size_bytes(128) + .build(); + + let client = $moduleName::Client::from_conf(config); + // ByteStreams created from a file are streaming and have a known size + let mut file = #{tempfile}::NamedTempFile::new().unwrap(); + use std::io::Write; + file.write_all(UNCOMPRESSED_INPUT).unwrap(); + + let body = ByteStream::read_from() + .path(file.path()) + .buffer_size(1024) + .length(#{Length}::Exact(UNCOMPRESSED_INPUT.len() as u64)) + .build() + .await + .unwrap(); + let _ = client + .some_streaming_operation() + .body(body) + .send() + .await; + let request = rx.expect_request(); + // Check that the content-encoding header is set to "gzip" + assert_eq!(Some("gzip"), request.headers().get("content-encoding")); + + let compressed_body = ByteStream::from(request.into_body()).collect().await.unwrap().to_vec(); + // Assert input body is different from uncompressed input + assert_ne!(UNCOMPRESSED_INPUT, compressed_body.as_slice()); + // Assert input body was compressed + assert_eq!(COMPRESSED_OUTPUT, compressed_body.as_slice()); + } + """, + *preludeScope, + "ByteStream" to RuntimeType.smithyTypes(rc).resolve("byte_stream::ByteStream"), + "Blob" to RuntimeType.smithyTypes(rc).resolve("Blob"), + "Region" to AwsRuntimeType.awsTypes(rc).resolve("region::Region"), + "tokio" to CargoDependency.Tokio.toType(), + "capture_request" to RuntimeType.captureRequest(rc), + "pretty_assertions" to CargoDependency.PrettyAssertions.toType(), + "tempfile" to CargoDependency.TempFile.toType(), + "Length" to RuntimeType.smithyTypes(rc).resolve("byte_stream::Length"), + ) + } + } + } +} diff --git a/aws/sdk/integration-tests/webassembly/Cargo.toml b/aws/sdk/integration-tests/webassembly/Cargo.toml index 66c06fd06e..5163eb6884 100644 --- a/aws/sdk/integration-tests/webassembly/Cargo.toml +++ b/aws/sdk/integration-tests/webassembly/Cargo.toml @@ -38,7 +38,6 @@ tokio = { version = "1.32.0", features = ["macros", "rt"] } [target.'cfg(all(target_family = "wasm", target_os = "wasi"))'.dependencies] wit-bindgen = { version = "0.16.0", features = ["macros", "realloc"] } - [lib] crate-type = ["cdylib"] diff --git a/buildSrc/src/main/kotlin/CodegenTestCommon.kt b/buildSrc/src/main/kotlin/CodegenTestCommon.kt index ac98c3d193..b7681a5b56 100644 --- a/buildSrc/src/main/kotlin/CodegenTestCommon.kt +++ b/buildSrc/src/main/kotlin/CodegenTestCommon.kt @@ -83,6 +83,7 @@ private fun generateCargoWorkspace( ) = ( """ [workspace] + resolver = "2" members = [ ${tests.joinToString(",") { "\"${it.module}/$pluginName\"" }} ] diff --git a/buildSrc/src/main/kotlin/CrateSet.kt b/buildSrc/src/main/kotlin/CrateSet.kt index c134beb9b4..bc90115443 100644 --- a/buildSrc/src/main/kotlin/CrateSet.kt +++ b/buildSrc/src/main/kotlin/CrateSet.kt @@ -57,6 +57,7 @@ object CrateSet { listOf( "aws-smithy-async", "aws-smithy-checksums", + "aws-smithy-compression", "aws-smithy-client", "aws-smithy-eventstream", "aws-smithy-http", diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/RequestCompressionGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/RequestCompressionGenerator.kt new file mode 100644 index 0000000000..d02efbb477 --- /dev/null +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/RequestCompressionGenerator.kt @@ -0,0 +1,59 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rust.codegen.client.smithy.customizations + +import software.amazon.smithy.model.shapes.OperationShape +import software.amazon.smithy.model.traits.RequestCompressionTrait +import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationCustomization +import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationSection +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.util.getTrait +import java.util.logging.Logger + +// Currently, gzip is the only supported encoding. +fun isSupportedEncoding(encoding: String): Boolean = encoding == "gzip" + +fun firstSupportedEncoding(encodings: List): String? = encodings.firstOrNull { isSupportedEncoding(it) } + +// This generator was implemented based on this spec: +// https://smithy.io/2.0/spec/behavior-traits.html#requestcompression-trait +class RequestCompressionGenerator( + private val codegenContext: CodegenContext, + private val operationShape: OperationShape, +) : OperationCustomization() { + override fun section(section: OperationSection): Writable { + operationShape.getTrait()?.let { requestCompressionTrait -> + val logger = Logger.getLogger("SdkSettings") + if (requestCompressionTrait.encodings.isEmpty()) { + logger.warning { "No encodings were specified for the requestCompressionTrait on ${operationShape.id}" } + return emptySection + } + val encoding = firstSupportedEncoding(requestCompressionTrait.encodings) ?: return emptySection + // We can remove this once we start supporting other algorithms. + // Until then, we shouldn't see anything else coming up here. + assert(encoding == "gzip") { "Only gzip is supported but encoding was `$encoding`" } + val runtimeConfig = codegenContext.runtimeConfig + val compression = RuntimeType.clientRequestCompression(runtimeConfig) + + return writable { + when (section) { + is OperationSection.AdditionalRuntimePlugins -> + section.addOperationRuntimePlugin(this) { + rust("#T::new()", compression.resolve("RequestCompressionRuntimePlugin")) + } + + else -> {} + } + } + } + + return emptySection + } +} diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt index 85cdb1d144..a16f878002 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt @@ -13,6 +13,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.customizations.HttpChec import software.amazon.smithy.rust.codegen.client.smithy.customizations.IdentityCacheConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.customizations.InterceptorConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.customizations.MetadataCustomization +import software.amazon.smithy.rust.codegen.client.smithy.customizations.RequestCompressionGenerator import software.amazon.smithy.rust.codegen.client.smithy.customizations.ResiliencyConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.customizations.ResiliencyReExportCustomization import software.amazon.smithy.rust.codegen.client.smithy.customizations.RetryClassifierConfigCustomization @@ -52,7 +53,8 @@ class RequiredCustomizations : ClientCodegenDecorator { baseCustomizations + MetadataCustomization(codegenContext, operation) + HttpChecksumRequiredGenerator(codegenContext, operation) + - RetryClassifierOperationCustomization(codegenContext, operation) + RetryClassifierOperationCustomization(codegenContext, operation) + + RequestCompressionGenerator(codegenContext, operation) override fun configCustomizations( codegenContext: ClientCodegenContext, diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt index ad1ce67620..cb961cbd19 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt @@ -592,21 +592,6 @@ class DefaultProtocolTestGenerator( // These tests are not even attempted to be generated, either because they will not compile // or because they are flaky - private val DisableTests = - setOf( - // TODO(https://github.com/smithy-lang/smithy-rs/issues/2891): Implement support for `@requestCompression` - "SDKAppendedGzipAfterProvidedEncoding_restJson1", - "SDKAppendedGzipAfterProvidedEncoding_restXml", - "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsJson1_0", - "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsJson1_1", - "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsQuery", - "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_ec2Query", - "SDKAppliedContentEncoding_awsJson1_0", - "SDKAppliedContentEncoding_awsJson1_1", - "SDKAppliedContentEncoding_awsQuery", - "SDKAppliedContentEncoding_ec2Query", - "SDKAppliedContentEncoding_restJson1", - "SDKAppliedContentEncoding_restXml", - ) + private val DisableTests: Set = setOf() } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt index 180d7cf4e7..3eb64aa6c7 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt @@ -122,6 +122,19 @@ class InlineDependency( CargoDependency.Http, ) + fun clientRequestCompression(runtimeConfig: RuntimeConfig) = + forInlineableRustFile( + "client_request_compression", + CargoDependency.Http, + CargoDependency.HttpBody, + CargoDependency.Tracing, + CargoDependency.Flate2, + CargoDependency.Tokio.toDevDependency(), + CargoDependency.smithyCompression(runtimeConfig).withFeature("http-body-0-4-x"), + CargoDependency.smithyRuntimeApiClient(runtimeConfig), + CargoDependency.smithyTypes(runtimeConfig).withFeature("http-body-0-4-x"), + ) + fun idempotencyToken(runtimeConfig: RuntimeConfig) = forInlineableRustFile( "idempotency_token", @@ -245,11 +258,10 @@ data class CargoDependency( // Forces AHash to be a later version that avoids // https://github.com/tkaitchuck/aHash/issues/200 val AHash: CargoDependency = CargoDependency("ahash", CratesIo("0.8.11"), defaultFeatures = false) - val OnceCell: CargoDependency = CargoDependency("once_cell", CratesIo("1.16")) - val Url: CargoDependency = CargoDependency("url", CratesIo("2.3.1")) - val Bytes: CargoDependency = CargoDependency("bytes", CratesIo("1.0.0")) + val Bytes: CargoDependency = CargoDependency("bytes", CratesIo("1.4.0")) val BytesUtils: CargoDependency = CargoDependency("bytes-utils", CratesIo("0.1.0")) val FastRand: CargoDependency = CargoDependency("fastrand", CratesIo("2.0.0")) + val Flate2: CargoDependency = CargoDependency("flate2", CratesIo("1.0.30")) val Hex: CargoDependency = CargoDependency("hex", CratesIo("0.4.3")) val Hmac: CargoDependency = CargoDependency("hmac", CratesIo("0.12")) val Http: CargoDependency = CargoDependency("http", CratesIo("0.2.9")) @@ -259,6 +271,7 @@ data class CargoDependency( val LazyStatic: CargoDependency = CargoDependency("lazy_static", CratesIo("1.4.0")) val Lru: CargoDependency = CargoDependency("lru", CratesIo("0.12.2")) val Md5: CargoDependency = CargoDependency("md-5", CratesIo("0.10.0"), rustName = "md5") + val OnceCell: CargoDependency = CargoDependency("once_cell", CratesIo("1.16")) val PercentEncoding: CargoDependency = CargoDependency("percent-encoding", CratesIo("2.0.0")) val Regex: CargoDependency = CargoDependency("regex", CratesIo("1.5.5")) val RegexLite: CargoDependency = CargoDependency("regex-lite", CratesIo("0.1.5")) @@ -267,6 +280,7 @@ data class CargoDependency( val TokioStream: CargoDependency = CargoDependency("tokio-stream", CratesIo("0.1.7")) val Tower: CargoDependency = CargoDependency("tower", CratesIo("0.4")) val Tracing: CargoDependency = CargoDependency("tracing", CratesIo("0.1")) + val Url: CargoDependency = CargoDependency("url", CratesIo("2.3.1")) // Test-only dependencies val Approx: CargoDependency = CargoDependency("approx", CratesIo("0.5.1"), DependencyScope.Dev) @@ -315,6 +329,8 @@ data class CargoDependency( fun smithyChecksums(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-checksums") + fun smithyCompression(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-compression") + fun smithyEventStream(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-eventstream") fun smithyHttp(runtimeConfig: RuntimeConfig) = runtimeConfig.smithyRuntimeCrate("smithy-http") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt index 26ff35a64f..da5d742647 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt @@ -309,6 +309,8 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null) fun smithyChecksums(runtimeConfig: RuntimeConfig) = CargoDependency.smithyChecksums(runtimeConfig).toType() + fun smithyCompression(runtimeConfig: RuntimeConfig) = CargoDependency.smithyCompression(runtimeConfig).toType() + fun smithyEventStream(runtimeConfig: RuntimeConfig) = CargoDependency.smithyEventStream(runtimeConfig).toType() fun smithyHttp(runtimeConfig: RuntimeConfig) = CargoDependency.smithyHttp(runtimeConfig).toType() @@ -525,5 +527,8 @@ data class RuntimeType(val path: String, val dependency: RustDependency? = null) fun idempotencyToken(runtimeConfig: RuntimeConfig) = forInlineDependency(InlineDependency.idempotencyToken(runtimeConfig)) + + fun clientRequestCompression(runtimeConfig: RuntimeConfig) = + forInlineDependency(InlineDependency.clientRequestCompression(runtimeConfig)) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 8cb54bcdf6..1693685332 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -97,6 +97,7 @@ object TestWorkspace { mapOf( "workspace" to mapOf( + "resolver" to "2", "members" to subprojects, ), ), diff --git a/rust-runtime/Cargo.toml b/rust-runtime/Cargo.toml index d287e7c878..3a618e6bbe 100644 --- a/rust-runtime/Cargo.toml +++ b/rust-runtime/Cargo.toml @@ -4,6 +4,7 @@ members = [ "inlineable", "aws-smithy-async", "aws-smithy-checksums", + "aws-smithy-compression", "aws-smithy-client", "aws-smithy-eventstream", "aws-smithy-http", diff --git a/rust-runtime/aws-smithy-checksums/Cargo.toml b/rust-runtime/aws-smithy-checksums/Cargo.toml index 3935deac3a..217a73b45f 100644 --- a/rust-runtime/aws-smithy-checksums/Cargo.toml +++ b/rust-runtime/aws-smithy-checksums/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-smithy-checksums" -version = "0.60.7" +version = "0.60.8" authors = [ "AWS Rust SDK Team ", "Zelda Hessler ", diff --git a/rust-runtime/aws-smithy-checksums/README.md b/rust-runtime/aws-smithy-checksums/README.md index 94909aa8be..e6a4765691 100644 --- a/rust-runtime/aws-smithy-checksums/README.md +++ b/rust-runtime/aws-smithy-checksums/README.md @@ -1,4 +1,4 @@ -# aws-smithy-checksum-callbacks +# aws-smithy-checksums Checksum calculation and verification callbacks for HTTP request and response bodies sent by service clients generated by [smithy-rs](https://github.com/smithy-lang/smithy-rs). diff --git a/rust-runtime/aws-smithy-compression/Cargo.toml b/rust-runtime/aws-smithy-compression/Cargo.toml new file mode 100644 index 0000000000..95ecba68f0 --- /dev/null +++ b/rust-runtime/aws-smithy-compression/Cargo.toml @@ -0,0 +1,51 @@ +[package] +name = "aws-smithy-compression" +version = "0.0.1" +authors = [ + "AWS Rust SDK Team ", + "Zelda Hessler ", +] +description = "Request compression for smithy clients." +edition = "2021" +license = "Apache-2.0" +repository = "https://github.com/smithy-lang/smithy-rs" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[features] +http-body-0-4-x = [ + "dep:http-body-0-4", + "dep:http-0-2", + "aws-smithy-types/http-body-0-4-x", +] +http-body-1-x = [ + "dep:http-body-1-0", + "dep:http-1-0", + "dep:http-body-util", + "aws-smithy-types/http-body-1-x", +] + +[dependencies] +aws-smithy-types = { path = "../aws-smithy-types" } +aws-smithy-runtime-api = { path = "../aws-smithy-runtime-api" } +bytes = "1.4.0" +flate2 = "1.0.30" +pin-project-lite = "0.2.14" +tracing = "0.1.40" +http-0-2 = { package = "http", version = "0.2.9", optional = true } +http-1-0 = { package = "http", version = "1", optional = true } +http-body-0-4 = { package = "http-body", version = "0.4.5", optional = true } +http-body-1-0 = { package = "http-body", version = "1", optional = true } +http-body-util = { version = "0.1.1", optional = true } + +[dev-dependencies] +bytes-utils = "0.1.2" +pretty_assertions = "1.3" +tokio = { version = "1.23.1", features = ["macros", "rt"] } + +[package.metadata.docs.rs] +all-features = true +targets = ["x86_64-unknown-linux-gnu"] +cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"] +rustdoc-args = ["--cfg", "docsrs"] +# End of docs.rs metadata diff --git a/rust-runtime/aws-smithy-compression/LICENSE b/rust-runtime/aws-smithy-compression/LICENSE new file mode 100644 index 0000000000..67db858821 --- /dev/null +++ b/rust-runtime/aws-smithy-compression/LICENSE @@ -0,0 +1,175 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. diff --git a/rust-runtime/aws-smithy-compression/README.md b/rust-runtime/aws-smithy-compression/README.md new file mode 100644 index 0000000000..9464dc035b --- /dev/null +++ b/rust-runtime/aws-smithy-compression/README.md @@ -0,0 +1,7 @@ +# aws-smithy-compression + +Compression for HTTP request and response bodies. + + +This crate is part of the [AWS SDK for Rust](https://awslabs.github.io/aws-sdk-rust/) and the [smithy-rs](https://github.com/smithy-lang/smithy-rs) code generator. In most cases, it should not be used directly. + diff --git a/rust-runtime/aws-smithy-compression/external-types.toml b/rust-runtime/aws-smithy-compression/external-types.toml new file mode 100644 index 0000000000..37f9ea161a --- /dev/null +++ b/rust-runtime/aws-smithy-compression/external-types.toml @@ -0,0 +1,11 @@ +allowed_external_types = [ + "aws_smithy_types::body::SdkBody", + "aws_smithy_types::config_bag::storable::StoreReplace", + "aws_smithy_types::config_bag::storable::Storable", + "aws_smithy_runtime_api::box_error::BoxError", + "bytes::bytes::Bytes", + "http::header::map::HeaderMap", + "http::header::name::HeaderName", + "http::header::value::HeaderValue", + "http_body::Body", +] diff --git a/rust-runtime/aws-smithy-compression/src/body.rs b/rust-runtime/aws-smithy-compression/src/body.rs new file mode 100644 index 0000000000..a91b3f76ed --- /dev/null +++ b/rust-runtime/aws-smithy-compression/src/body.rs @@ -0,0 +1,217 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +//! HTTP body-wrappers that perform request compression + +// Putting this in a `mod` since I expect we'll have to handle response +// decompression some day. +/// Functionality for compressing an HTTP request body. +pub mod compress { + use aws_smithy_types::body::SdkBody; + use pin_project_lite::pin_project; + + pin_project! { + /// A `Body` that may compress its data with a `CompressRequest` implementor. + /// + /// Compression options may disable request compression for small data payload, or entirely. + /// Additionally, some services may not support compression. + pub struct CompressedBody { + #[pin] + body: InnerBody, + compress_request: CompressionImpl, + } + } + + impl CompressedBody { + /// Given an [`SdkBody`] and a `Box`, create a new `CompressedBody`. + pub fn new(body: SdkBody, compress_request: CR) -> Self { + Self { + body, + compress_request, + } + } + } + + /// Support for the `http-body-0-4` and `http-0-2` crates. + #[cfg(feature = "http-body-0-4-x")] + pub mod http_body_0_4_x { + use super::CompressedBody; + use crate::http::http_body_0_4_x::CompressRequest; + use aws_smithy_types::body::SdkBody; + use http_0_2::HeaderMap; + use http_body_0_4::{Body, SizeHint}; + use std::pin::Pin; + use std::task::{Context, Poll}; + + impl Body for CompressedBody> { + type Data = bytes::Bytes; + type Error = aws_smithy_types::body::Error; + + fn poll_data( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll>> { + let this = self.project(); + match this.body.poll_data(cx)? { + Poll::Ready(Some(data)) => { + let mut out = Vec::new(); + this.compress_request.compress_bytes(&data[..], &mut out)?; + Poll::Ready(Some(Ok(out.into()))) + } + Poll::Ready(None) => Poll::Ready(None), + Poll::Pending => Poll::Pending, + } + } + + fn poll_trailers( + self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll, Self::Error>> { + let this = self.project(); + this.body.poll_trailers(cx) + } + + fn is_end_stream(&self) -> bool { + self.body.is_end_stream() + } + + fn size_hint(&self) -> SizeHint { + self.body.size_hint() + } + } + } + + /// Support for the `http-body-1-0` and `http-1-0` crates. + #[cfg(feature = "http-body-1-x")] + pub mod http_body_1_x { + use super::CompressedBody; + use crate::http::http_body_1_x::CompressRequest; + use aws_smithy_types::body::SdkBody; + use http_body_1_0::{Body, Frame, SizeHint}; + use std::pin::Pin; + use std::task::{ready, Context, Poll}; + + impl Body for CompressedBody> { + type Data = bytes::Bytes; + type Error = aws_smithy_types::body::Error; + + fn poll_frame( + mut self: Pin<&mut Self>, + cx: &mut Context<'_>, + ) -> Poll, Self::Error>>> { + let this = self.as_mut().project(); + Poll::Ready(match ready!(this.body.poll_frame(cx)) { + Some(Ok(f)) => { + if f.is_data() { + let d = f.into_data().expect("we checked for data first"); + let mut out = Vec::new(); + this.compress_request.compress_bytes(&d, &mut out)?; + Some(Ok(Frame::data(out.into()))) + } else if f.is_trailers() { + // Trailers don't get compressed. + Some(Ok(f)) + } else { + unreachable!("Frame is either data or trailers") + } + } + other => other, + }) + } + + fn is_end_stream(&self) -> bool { + self.body.is_end_stream() + } + + fn size_hint(&self) -> SizeHint { + self.body.size_hint() + } + } + } +} + +#[cfg(any(feature = "http-body-0-4-x", feature = "http-body-1-x"))] +#[cfg(test)] +mod test { + const UNCOMPRESSED_INPUT: &[u8] = b"hello world"; + const COMPRESSED_OUTPUT: &[u8] = &[ + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 203, 72, 205, 201, 201, 87, 40, 207, 47, 202, 73, 1, 0, + 133, 17, 74, 13, 11, 0, 0, 0, + ]; + + #[cfg(feature = "http-body-0-4-x")] + #[tokio::test] + async fn test_compressed_body_http_body_0_4_x() { + use super::super::{CompressionAlgorithm, CompressionOptions}; + use crate::body::compress::CompressedBody; + use aws_smithy_types::body::SdkBody; + use bytes::Buf; + use bytes_utils::SegmentedBuf; + use http_body_0_4::Body; + use std::io::Read; + + let compression_algorithm = CompressionAlgorithm::Gzip; + let compression_options = CompressionOptions::default() + .with_min_compression_size_bytes(0) + .unwrap(); + let compress_request = + compression_algorithm.into_impl_http_body_0_4_x(&compression_options); + let body = SdkBody::from(UNCOMPRESSED_INPUT); + let mut compressed_body = CompressedBody::new(body, compress_request); + + let mut output = SegmentedBuf::new(); + while let Some(buf) = compressed_body.data().await { + output.push(buf.unwrap()); + } + + let mut actual_output = Vec::new(); + output + .reader() + .read_to_end(&mut actual_output) + .expect("Doesn't cause IO errors"); + // Verify data is compressed as expected + assert_eq!(COMPRESSED_OUTPUT, actual_output); + } + + #[cfg(feature = "http-body-1-x")] + #[tokio::test] + async fn test_compressed_body_http_body_1_x() { + use super::super::{CompressionAlgorithm, CompressionOptions}; + use crate::body::compress::CompressedBody; + use aws_smithy_types::body::SdkBody; + use bytes::Buf; + use bytes_utils::SegmentedBuf; + use http_body_util::BodyExt; + use std::io::Read; + + let compression_algorithm = CompressionAlgorithm::Gzip; + let compression_options = CompressionOptions::default() + .with_min_compression_size_bytes(0) + .unwrap(); + let compress_request = compression_algorithm.into_impl_http_body_1_x(&compression_options); + let body = SdkBody::from(UNCOMPRESSED_INPUT); + let mut compressed_body = CompressedBody::new(body, compress_request); + + let mut output = SegmentedBuf::new(); + + loop { + let data = match compressed_body.frame().await { + Some(Ok(frame)) => frame.into_data(), + Some(Err(e)) => panic!("Error: {}", e), + // No more frames, break out of loop + None => break, + } + .expect("frame is OK"); + output.push(data); + } + + let mut actual_output = Vec::new(); + output + .reader() + .read_to_end(&mut actual_output) + .expect("Doesn't cause IO errors"); + // Verify data is compressed as expected + assert_eq!(COMPRESSED_OUTPUT, actual_output); + } +} diff --git a/rust-runtime/aws-smithy-compression/src/gzip.rs b/rust-runtime/aws-smithy-compression/src/gzip.rs new file mode 100644 index 0000000000..016423ce55 --- /dev/null +++ b/rust-runtime/aws-smithy-compression/src/gzip.rs @@ -0,0 +1,113 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +use crate::{Compress, CompressionOptions}; +use aws_smithy_runtime_api::box_error::BoxError; +use flate2::write::GzEncoder; +use std::io::prelude::*; + +#[derive(Debug, Default, Clone, PartialEq, Eq)] +pub(crate) struct Gzip { + compression: flate2::Compression, +} + +impl Gzip { + fn compress_bytes(&self, bytes: &[u8], writer: impl Write) -> Result<(), BoxError> { + let mut encoder = GzEncoder::new(writer, self.compression); + encoder.write_all(bytes)?; + encoder.try_finish()?; + + Ok(()) + } +} + +impl Compress for Gzip { + fn compress_bytes(&mut self, bytes: &[u8], writer: &mut dyn Write) -> Result<(), BoxError> { + Gzip::compress_bytes(self, bytes, writer).map_err(Into::into) + } +} + +#[cfg(feature = "http-body-0-4-x")] +mod http_body_0_4_x { + use crate::http::http_body_0_4_x::CompressRequest; + + impl CompressRequest for super::Gzip { + fn header_value(&self) -> http_0_2::HeaderValue { + http_0_2::HeaderValue::from_static("gzip") + } + } +} + +#[cfg(feature = "http-body-1-x")] +mod http_body_1_x { + use crate::http::http_body_1_x::CompressRequest; + + impl CompressRequest for super::Gzip { + fn header_value(&self) -> http_1_0::HeaderValue { + http_1_0::HeaderValue::from_static("gzip") + } + } +} + +impl From<&CompressionOptions> for Gzip { + fn from(options: &CompressionOptions) -> Self { + Gzip { + compression: flate2::Compression::new(options.level), + } + } +} + +impl From for Gzip { + fn from(options: CompressionOptions) -> Self { + Gzip { + compression: flate2::Compression::new(options.level), + } + } +} + +// Windows line-endings will cause the compression test to fail. +#[cfg(all(test, not(windows)))] +mod tests { + use super::Gzip; + use crate::CompressionOptions; + use flate2::read::GzDecoder; + use pretty_assertions::assert_eq; + use std::io::Read; + + fn gettysburg_address() -> &'static [u8] { + include_bytes!("../test-data/gettysburg_address.txt") + } + + fn gzip_compressed_gettysburg_address() -> &'static [u8] { + // This file was compressed using Apple gzip with the following command: + // `gzip -k gettysburg_address.txt -6` + include_bytes!("../test-data/gettysburg_address.txt.gz") + } + + #[test] + fn test_gzip_compression() { + let gzip = Gzip::from(&CompressionOptions::default()); + let mut compressed_output = Vec::new(); + gzip.compress_bytes(gettysburg_address(), &mut compressed_output) + .expect("compression succeeds"); + + let uncompressed_expected = { + let mut s = String::new(); + GzDecoder::new(gzip_compressed_gettysburg_address()) + .read_to_string(&mut s) + .unwrap(); + s + }; + let uncompressed_actual = { + let mut s = String::new(); + GzDecoder::new(&compressed_output[..]) + .read_to_string(&mut s) + .unwrap(); + s + }; + + assert_eq!(uncompressed_expected, uncompressed_actual); + } +} diff --git a/rust-runtime/aws-smithy-compression/src/http.rs b/rust-runtime/aws-smithy-compression/src/http.rs new file mode 100644 index 0000000000..8cec9c215a --- /dev/null +++ b/rust-runtime/aws-smithy-compression/src/http.rs @@ -0,0 +1,84 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +//! Checksum support for HTTP requests and responses. + +/// Support for the `http-body-0-4` and `http-0-2` crates. +#[cfg(feature = "http-body-0-4-x")] +pub mod http_body_0_4_x { + use crate::Compress; + use http_0_2::header::{HeaderName, HeaderValue}; + + /// Implementors of this trait can be used to compress HTTP requests. + pub trait CompressRequest: Compress + CloneCompressRequest { + /// Return the header name for the content-encoding header. + fn header_name(&self) -> HeaderName { + HeaderName::from_static("content-encoding") + } + + /// Return the header value for the content-encoding header. + fn header_value(&self) -> HeaderValue; + } + + /// Enables CompressRequest implementors to be cloned. + pub trait CloneCompressRequest { + /// Clone this request compressor. + fn clone_request_compressor(&self) -> Box; + } + + impl CloneCompressRequest for T + where + T: CompressRequest + Clone + 'static, + { + fn clone_request_compressor(&self) -> Box { + Box::new(self.clone()) + } + } + + impl Clone for Box { + fn clone(&self) -> Self { + self.clone_request_compressor() + } + } +} + +/// Support for the `http-body-1-0` and `http-1-0` crates. +#[cfg(feature = "http-body-1-x")] +pub mod http_body_1_x { + use crate::Compress; + use http_1_0::header::{HeaderName, HeaderValue}; + + /// Implementors of this trait can be used to compress HTTP requests. + pub trait CompressRequest: Compress + CloneCompressRequest { + /// Return the header name for the content-encoding header. + fn header_name(&self) -> HeaderName { + HeaderName::from_static("content-encoding") + } + + /// Return the header value for the content-encoding header. + fn header_value(&self) -> HeaderValue; + } + + /// Enables CompressRequest implementors to be cloned. + pub trait CloneCompressRequest { + /// Clone this request compressor. + fn clone_request_compressor(&self) -> Box; + } + + impl CloneCompressRequest for T + where + T: CompressRequest + Clone + 'static, + { + fn clone_request_compressor(&self) -> Box { + Box::new(self.clone()) + } + } + + impl Clone for Box { + fn clone(&self) -> Self { + self.clone_request_compressor() + } + } +} diff --git a/rust-runtime/aws-smithy-compression/src/lib.rs b/rust-runtime/aws-smithy-compression/src/lib.rs new file mode 100644 index 0000000000..88e673761d --- /dev/null +++ b/rust-runtime/aws-smithy-compression/src/lib.rs @@ -0,0 +1,220 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +/* Automatically managed default lints */ +#![cfg_attr(docsrs, feature(doc_auto_cfg))] +/* End of automatically managed default lints */ +#![allow(clippy::derive_partial_eq_without_eq)] +#![warn( + missing_docs, + rustdoc::missing_crate_level_docs, + unreachable_pub, + rust_2018_idioms +)] + +//! Compression-related code. + +use aws_smithy_runtime_api::box_error::BoxError; +use aws_smithy_types::config_bag::{Storable, StoreReplace}; +use std::io::Write; +use std::str::FromStr; + +pub mod body; +mod gzip; +pub mod http; + +// Valid compression algorithm names +/// The name of the `gzip` algorithm. +pub const GZIP_NAME: &str = "gzip"; + +/// The maximum-allowable value per internal standards is 10 Megabytes. +const MAX_MIN_COMPRESSION_SIZE_BYTES: u32 = 10_485_760; + +/// Types implementing this trait can compress data. +/// +/// Compression algorithms are used reduce the size of data. This trait +/// requires Send + Sync because trait implementors are often used in an +/// async context. +pub trait Compress: Send + Sync { + /// Given a slice of bytes, and a [Write] implementor, compress and write + /// bytes to the writer until done. + // I wanted to use `impl Write` but that's not object-safe + fn compress_bytes(&mut self, bytes: &[u8], writer: &mut dyn Write) -> Result<(), BoxError>; +} + +/// Options for configuring request compression. +#[derive(Debug, Clone, PartialEq, Eq)] +#[non_exhaustive] +pub struct CompressionOptions { + /// Valid values are 0-9 with lower values configuring less (but faster) compression + level: u32, + min_compression_size_bytes: u32, + enabled: bool, +} + +impl Default for CompressionOptions { + fn default() -> Self { + Self { + level: 6, + min_compression_size_bytes: 10240, + enabled: true, + } + } +} + +impl CompressionOptions { + /// The compression level to use. + pub fn level(&self) -> u32 { + self.level + } + + /// The minimum size of data to compress. + /// + /// Data smaller than this will not be compressed. + pub fn min_compression_size_bytes(&self) -> u32 { + self.min_compression_size_bytes + } + + /// Whether compression is enabled. + pub fn is_enabled(&self) -> bool { + self.enabled + } + + /// Set whether compression is enabled. + pub fn with_enabled(self, enabled: bool) -> Self { + Self { enabled, ..self } + } + + /// Set the compression level. + /// + /// Valid values are `0..=9` with lower values configuring less _(but faster)_ compression + pub fn with_level(self, level: u32) -> Result { + Self::validate_level(level)?; + Ok(Self { level, ..self }) + } + + /// Set the minimum size of data to compress. + /// + /// Data smaller than this will not be compressed. + /// Valid values are `0..=10_485_760`. The default is `10_240`. + pub fn with_min_compression_size_bytes( + self, + min_compression_size_bytes: u32, + ) -> Result { + Self::validate_min_compression_size_bytes(min_compression_size_bytes)?; + Ok(Self { + min_compression_size_bytes, + ..self + }) + } + + fn validate_level(level: u32) -> Result<(), BoxError> { + if level > 9 { + return Err(format!( + "compression level `{}` is invalid, valid values are 0..=9", + level + ) + .into()); + }; + Ok(()) + } + + fn validate_min_compression_size_bytes( + min_compression_size_bytes: u32, + ) -> Result<(), BoxError> { + if min_compression_size_bytes > MAX_MIN_COMPRESSION_SIZE_BYTES { + return Err(format!( + "min compression size `{}` is invalid, valid values are 0..=10_485_760", + min_compression_size_bytes + ) + .into()); + }; + Ok(()) + } +} + +impl Storable for CompressionOptions { + type Storer = StoreReplace; +} + +/// An enum encompassing all supported compression algorithms. +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +#[non_exhaustive] +pub enum CompressionAlgorithm { + /// The [gzip](https://en.wikipedia.org/wiki/Gzip) compression algorithm + Gzip, +} + +impl FromStr for CompressionAlgorithm { + type Err = BoxError; + + /// Create a new `CompressionAlgorithm` from an algorithm name. + /// + /// Valid algorithm names are: + /// - "gzip" + /// + /// Passing an invalid name will return an error. + fn from_str(compression_algorithm: &str) -> Result { + if compression_algorithm.eq_ignore_ascii_case(GZIP_NAME) { + Ok(Self::Gzip) + } else { + Err(format!("unknown compression algorithm `{compression_algorithm}`").into()) + } + } +} + +impl CompressionAlgorithm { + #[cfg(feature = "http-body-0-4-x")] + /// Return the `HttpChecksum` implementor for this algorithm. + pub fn into_impl_http_body_0_4_x( + self, + options: &CompressionOptions, + ) -> Box { + match self { + Self::Gzip => Box::new(gzip::Gzip::from(options)), + } + } + + #[cfg(feature = "http-body-1-x")] + /// Return the `HttpChecksum` implementor for this algorithm. + pub fn into_impl_http_body_1_x( + self, + options: &CompressionOptions, + ) -> Box { + match self { + Self::Gzip => Box::new(gzip::Gzip::from(options)), + } + } + + /// Return the name of this algorithm in string form + pub fn as_str(&self) -> &'static str { + match self { + Self::Gzip { .. } => GZIP_NAME, + } + } +} + +#[cfg(test)] +mod tests { + use crate::CompressionAlgorithm; + use pretty_assertions::assert_eq; + + #[test] + fn test_compression_algorithm_from_str_unknown() { + let error = "some unknown compression algorithm" + .parse::() + .expect_err("it should error"); + assert_eq!( + "unknown compression algorithm `some unknown compression algorithm`", + error.to_string() + ); + } + + #[test] + fn test_compression_algorithm_from_str_gzip() { + let algo = "gzip".parse::().unwrap(); + assert_eq!("gzip", algo.as_str()); + } +} diff --git a/rust-runtime/aws-smithy-compression/test-data/gettysburg_address.txt b/rust-runtime/aws-smithy-compression/test-data/gettysburg_address.txt new file mode 100644 index 0000000000..9f2d713856 --- /dev/null +++ b/rust-runtime/aws-smithy-compression/test-data/gettysburg_address.txt @@ -0,0 +1,5 @@ +Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. + +Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this. + +But, in a larger sense, we can not dedicate—we can not consecrate—we can not hallow—this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us—that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion—that we here highly resolve that these dead shall not have died in vain—that this nation, under God, shall have a new birth of freedom—and that government of the people, by the people, for the people, shall not perish from the earth. diff --git a/rust-runtime/aws-smithy-compression/test-data/gettysburg_address.txt.gz b/rust-runtime/aws-smithy-compression/test-data/gettysburg_address.txt.gz new file mode 100644 index 0000000000..94eb3799a8 Binary files /dev/null and b/rust-runtime/aws-smithy-compression/test-data/gettysburg_address.txt.gz differ diff --git a/rust-runtime/inlineable/Cargo.toml b/rust-runtime/inlineable/Cargo.toml index 7cc4d120a2..8e7c0ebd79 100644 --- a/rust-runtime/inlineable/Cargo.toml +++ b/rust-runtime/inlineable/Cargo.toml @@ -16,8 +16,8 @@ repository = "https://github.com/smithy-lang/smithy-rs" gated-tests = [] default = ["gated-tests"] - [dependencies] +aws-smithy-compression = { path = "../aws-smithy-compression", features = ["http-body-0-4-x"] } aws-smithy-http = { path = "../aws-smithy-http", features = ["event-stream"] } aws-smithy-json = { path = "../aws-smithy-json" } aws-smithy-runtime-api = { path = "../aws-smithy-runtime-api", features = ["client"] } @@ -27,15 +27,18 @@ bytes = "1" fastrand = "2.0.0" futures-util = "0.3.29" http = "0.2.1" +http-body = "0.4" md-5 = "0.10.0" once_cell = "1.16.0" percent-encoding = "2.2.0" pin-project-lite = "0.2" regex-lite = "0.1.5" +tracing = "0.1.37" url = "2.3.1" [dev-dependencies] proptest = "1" +tokio = { version = "1.26", features = ["full", "test-util"] } [package.metadata.docs.rs] all-features = true diff --git a/rust-runtime/inlineable/src/client_request_compression.rs b/rust-runtime/inlineable/src/client_request_compression.rs new file mode 100644 index 0000000000..2ea9c26e64 --- /dev/null +++ b/rust-runtime/inlineable/src/client_request_compression.rs @@ -0,0 +1,260 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +use aws_smithy_compression::body::compress::CompressedBody; +use aws_smithy_compression::http::http_body_0_4_x::CompressRequest; +use aws_smithy_compression::{CompressionAlgorithm, CompressionOptions}; +use aws_smithy_runtime_api::box_error::BoxError; +use aws_smithy_runtime_api::client::interceptors::context::{ + BeforeSerializationInterceptorContextRef, BeforeTransmitInterceptorContextMut, +}; +use aws_smithy_runtime_api::client::interceptors::{Intercept, SharedInterceptor}; +use aws_smithy_runtime_api::client::orchestrator::HttpRequest; +use aws_smithy_runtime_api::client::runtime_components::{ + RuntimeComponents, RuntimeComponentsBuilder, +}; +use aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin; +use aws_smithy_types::body::SdkBody; +use aws_smithy_types::config_bag::{ConfigBag, Layer, Storable, StoreReplace}; +use aws_smithy_types::error::operation::BuildError; +use std::borrow::Cow; +use std::{fmt, mem}; + +#[derive(Debug)] +pub(crate) struct RequestCompressionRuntimePlugin { + runtime_components: RuntimeComponentsBuilder, +} + +impl RequestCompressionRuntimePlugin { + pub(crate) fn new() -> Self { + Self { + runtime_components: RuntimeComponentsBuilder::new("RequestCompressionRuntimePlugin") + .with_interceptor(SharedInterceptor::new(RequestCompressionInterceptor::new())), + } + } +} + +impl RuntimePlugin for RequestCompressionRuntimePlugin { + fn runtime_components( + &self, + _: &RuntimeComponentsBuilder, + ) -> Cow<'_, RuntimeComponentsBuilder> { + Cow::Borrowed(&self.runtime_components) + } +} + +#[derive(Debug)] +struct RequestCompressionInterceptorState { + options: Option, +} + +impl Storable for RequestCompressionInterceptorState { + type Storer = StoreReplace; +} + +/// Interceptor for Smithy [`@requestCompression`][spec]. +/// +/// [spec]: https://smithy.io/2.0/spec/behavior-traits.html#requestcompression-trait +pub(crate) struct RequestCompressionInterceptor {} + +impl fmt::Debug for RequestCompressionInterceptor { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("RequestCompressionInterceptor").finish() + } +} + +impl RequestCompressionInterceptor { + pub(crate) fn new() -> Self { + Self {} + } +} + +impl Intercept for RequestCompressionInterceptor { + fn name(&self) -> &'static str { + "RequestCompressionInterceptor" + } + + fn read_before_serialization( + &self, + _context: &BeforeSerializationInterceptorContextRef<'_>, + _runtime_components: &RuntimeComponents, + cfg: &mut ConfigBag, + ) -> Result<(), BoxError> { + let disable_request_compression = cfg + .load::() + .cloned() + .unwrap_or_default(); + let request_min_compression_size_bytes = cfg + .load::() + .cloned() + .unwrap_or_default(); + let options = CompressionOptions::default() + .with_min_compression_size_bytes(request_min_compression_size_bytes.0)? + .with_enabled(!disable_request_compression.0); + + let mut layer = Layer::new("RequestCompressionInterceptor"); + layer.store_put(RequestCompressionInterceptorState { + options: Some(options), + }); + cfg.push_layer(layer); + + Ok(()) + } + + fn modify_before_signing( + &self, + context: &mut BeforeTransmitInterceptorContextMut<'_>, + _runtime_components: &RuntimeComponents, + cfg: &mut ConfigBag, + ) -> Result<(), BoxError> { + let state = cfg + .load::() + .expect("set in `read_before_serialization`"); + + let options = state.options.clone().unwrap(); + let request = context.request_mut(); + + // Don't wrap a body if compression is disabled. + if !options.is_enabled() { + tracing::trace!("request compression is disabled and will not be applied"); + return Ok(()); + } + + // Don't wrap a body if it's below the minimum size + // + // Because compressing small amounts of data can actually increase its size, + // we check to see if the data is big enough to make compression worthwhile. + if let Some(known_size) = http_body::Body::size_hint(request.body()).exact() { + if known_size < options.min_compression_size_bytes() as u64 { + tracing::trace!( + min_compression_size_bytes = options.min_compression_size_bytes(), + known_size, + "request body is below minimum size and will not be compressed" + ); + return Ok(()); + } + tracing::trace!("compressing non-streaming request body...") + } else { + tracing::trace!("compressing streaming request body..."); + } + + wrap_request_body_in_compressed_body( + request, + CompressionAlgorithm::Gzip.into_impl_http_body_0_4_x(&options), + )?; + + Ok(()) + } +} + +fn wrap_request_body_in_compressed_body( + request: &mut HttpRequest, + request_compress_impl: Box, +) -> Result<(), BuildError> { + request.headers_mut().append( + request_compress_impl.header_name(), + request_compress_impl.header_value(), + ); + let mut body = { + let body = mem::replace(request.body_mut(), SdkBody::taken()); + body.map(move |body| { + let body = CompressedBody::new(body, request_compress_impl.clone()); + + SdkBody::from_body_0_4(body) + }) + }; + mem::swap(request.body_mut(), &mut body); + + Ok(()) +} + +#[derive(Debug, Copy, Clone, Default)] +pub(crate) struct DisableRequestCompression(pub(crate) bool); + +impl From for DisableRequestCompression { + fn from(value: bool) -> Self { + DisableRequestCompression(value) + } +} + +impl Storable for DisableRequestCompression { + type Storer = StoreReplace; +} + +#[derive(Debug, Copy, Clone)] +pub(crate) struct RequestMinCompressionSizeBytes(pub(crate) u32); + +impl Default for RequestMinCompressionSizeBytes { + fn default() -> Self { + RequestMinCompressionSizeBytes(10240) + } +} + +impl From for RequestMinCompressionSizeBytes { + fn from(value: u32) -> Self { + RequestMinCompressionSizeBytes(value) + } +} + +impl Storable for RequestMinCompressionSizeBytes { + type Storer = StoreReplace; +} + +#[cfg(test)] +mod tests { + use super::wrap_request_body_in_compressed_body; + use aws_smithy_compression::{CompressionAlgorithm, CompressionOptions}; + use aws_smithy_runtime_api::client::orchestrator::HttpRequest; + use aws_smithy_types::body::SdkBody; + use http_body::Body; + + const UNCOMPRESSED_INPUT: &[u8] = b"hello world"; + const COMPRESSED_OUTPUT: &[u8] = &[ + 31, 139, 8, 0, 0, 0, 0, 0, 0, 255, 203, 72, 205, 201, 201, 87, 40, 207, 47, 202, 73, 1, 0, + 133, 17, 74, 13, 11, 0, 0, 0, + ]; + + #[tokio::test] + async fn test_compressed_body_is_retryable() { + let mut request: HttpRequest = http::Request::builder() + .body(SdkBody::retryable(move || { + SdkBody::from(UNCOMPRESSED_INPUT) + })) + .unwrap() + .try_into() + .unwrap(); + + // ensure original SdkBody is retryable + let mut body = request.body().try_clone().unwrap(); + let mut body_data = Vec::new(); + while let Some(data) = body.data().await { + body_data.extend_from_slice(&data.unwrap()) + } + // Not yet wrapped, should still be the same as UNCOMPRESSED_INPUT. + assert_eq!(UNCOMPRESSED_INPUT, body_data); + + let compression_algorithm = CompressionAlgorithm::Gzip; + let compression_options = CompressionOptions::default() + .with_min_compression_size_bytes(0) + .unwrap(); + + wrap_request_body_in_compressed_body( + &mut request, + compression_algorithm.into_impl_http_body_0_4_x(&compression_options), + ) + .unwrap(); + + // ensure again that wrapped SdkBody is retryable + let mut body = request.body().try_clone().expect("body is retryable"); + let mut body_data = Vec::new(); + while let Some(data) = body.data().await { + body_data.extend_from_slice(&data.unwrap()) + } + + // Since this body was wrapped, the output should be compressed data + assert_ne!(UNCOMPRESSED_INPUT, body_data.as_slice()); + assert_eq!(COMPRESSED_OUTPUT, body_data.as_slice()); + } +} diff --git a/rust-runtime/inlineable/src/lib.rs b/rust-runtime/inlineable/src/lib.rs index bcb9a1e7fe..cf0d8705d1 100644 --- a/rust-runtime/inlineable/src/lib.rs +++ b/rust-runtime/inlineable/src/lib.rs @@ -35,6 +35,9 @@ mod endpoint_lib; #[allow(unused)] mod auth_plugin; +#[allow(unused)] +mod client_request_compression; + // This test is outside of uuid.rs to enable copying the entirety of uuid.rs into the SDK without // requiring a proptest dependency #[cfg(test)]