diff --git a/tonic/src/client/grpc.rs b/tonic/src/client/grpc.rs index 0d52fb42f..09ef3e934 100644 --- a/tonic/src/client/grpc.rs +++ b/tonic/src/client/grpc.rs @@ -399,6 +399,7 @@ impl GrpcConfig { .headers_mut() .insert(CONTENT_TYPE, HeaderValue::from_static("application/grpc")); + #[cfg(any(feature = "gzip", feature = "zstd"))] if let Some(encoding) = self.send_compression_encodings { request.headers_mut().insert( crate::codec::compression::ENCODING_HEADER, diff --git a/tonic/src/codec/compression.rs b/tonic/src/codec/compression.rs index bf94ca3fd..70d758415 100644 --- a/tonic/src/codec/compression.rs +++ b/tonic/src/codec/compression.rs @@ -153,6 +153,7 @@ impl CompressionEncoding { } #[allow(missing_docs)] + #[cfg(any(feature = "gzip", feature = "zstd"))] pub(crate) fn as_str(&self) -> &'static str { match self { #[cfg(feature = "gzip")] @@ -162,6 +163,7 @@ impl CompressionEncoding { } } + #[cfg(any(feature = "gzip", feature = "zstd"))] pub(crate) fn into_header_value(self) -> http::HeaderValue { http::HeaderValue::from_static(self.as_str()) } @@ -202,6 +204,8 @@ pub(crate) fn compress( ) -> Result<(), std::io::Error> { let capacity = ((len / BUFFER_SIZE) + 1) * BUFFER_SIZE; out_buf.reserve(capacity); + + #[cfg(any(feature = "gzip", feature = "zstd"))] let mut out_writer = bytes::BufMut::writer(out_buf); match encoding { @@ -241,6 +245,8 @@ pub(crate) fn decompress( let estimate_decompressed_len = len * 2; let capacity = ((estimate_decompressed_len / BUFFER_SIZE) + 1) * BUFFER_SIZE; out_buf.reserve(capacity); + + #[cfg(any(feature = "gzip", feature = "zstd"))] let mut out_writer = bytes::BufMut::writer(out_buf); match encoding { diff --git a/tonic/src/server/grpc.rs b/tonic/src/server/grpc.rs index d8ec2a89c..ec94b97fb 100644 --- a/tonic/src/server/grpc.rs +++ b/tonic/src/server/grpc.rs @@ -443,6 +443,7 @@ where http::header::HeaderValue::from_static("application/grpc"), ); + #[cfg(any(feature = "gzip", feature = "zstd"))] if let Some(encoding) = accept_encoding { // Set the content encoding parts.headers.insert(