pub struct CompressionRegistry { /* private fields */ }Expand description
Registry of compression providers.
The registry maps encoding names to their provider implementations.
Use CompressionRegistry::default() to get a registry with all
feature-enabled built-in providers.
Implementations§
Source§impl CompressionRegistry
impl CompressionRegistry
Sourcepub fn register<P: CompressionProvider>(self, provider: P) -> Self
pub fn register<P: CompressionProvider>(self, provider: P) -> Self
Register a compression provider.
Returns self for method chaining.
§Example
use connectrpc::compression::{CompressionRegistry, GzipProvider, ZstdProvider};
let registry = CompressionRegistry::new()
.register(GzipProvider::default())
.register(ZstdProvider::default());
assert!(registry.supports("gzip"));
assert!(registry.supports("zstd"));Sourcepub fn get(&self, name: &str) -> Option<Arc<dyn CompressionProvider>>
pub fn get(&self, name: &str) -> Option<Arc<dyn CompressionProvider>>
Get a provider by encoding name.
Returns None if no provider is registered for the given name.
Sourcepub fn supports(&self, name: &str) -> bool
pub fn supports(&self, name: &str) -> bool
Check if a provider is registered for the given encoding name.
Sourcepub fn supported_encodings(&self) -> Vec<&'static str>
pub fn supported_encodings(&self) -> Vec<&'static str>
List all supported encoding names.
Sourcepub fn accept_encoding_header(&self) -> &str
pub fn accept_encoding_header(&self) -> &str
Get a comma-separated string of supported encodings.
Useful for Accept-Encoding headers. The string is computed once when providers are registered and cached, so this is a cheap lookup.
Sourcepub fn negotiate_encoding(
&self,
accept_encoding: Option<&str>,
request_encoding: Option<&str>,
) -> Option<&'static str>
pub fn negotiate_encoding( &self, accept_encoding: Option<&str>, request_encoding: Option<&str>, ) -> Option<&'static str>
Negotiate a response encoding based on the client’s accept-encoding header.
Returns the first encoding from the client’s preference list that this registry supports, or None if only identity is acceptable.
Per the Connect spec, the accept-encoding header is treated as an ordered list with most preferred first (no quality values).
If the client omits accept-encoding, the spec says the server may assume the client accepts the same encoding used for the request (if any), plus identity.
Sourcepub fn decompress_with_limit(
&self,
encoding: &str,
data: Bytes,
max_size: usize,
) -> Result<Bytes, ConnectError>
pub fn decompress_with_limit( &self, encoding: &str, data: Bytes, max_size: usize, ) -> Result<Bytes, ConnectError>
Decompress data using the specified encoding with a size limit.
Returns an error if the encoding is not supported or if the decompressed
data exceeds max_size. This protects against compression bomb attacks.
For identity encoding, returns the data without copying.
Sourcepub fn compress(
&self,
encoding: &str,
data: &[u8],
) -> Result<Bytes, ConnectError>
pub fn compress( &self, encoding: &str, data: &[u8], ) -> Result<Bytes, ConnectError>
Compress data using the specified encoding.
Returns an error if the encoding is not supported.
Sourcepub fn register_streaming<P: StreamingCompressionProvider>(
self,
provider: P,
) -> Self
Available on crate feature streaming only.
pub fn register_streaming<P: StreamingCompressionProvider>( self, provider: P, ) -> Self
streaming only.Register a streaming compression provider.
This also registers the provider for buffered compression. Returns self for method chaining.
Available when the streaming feature is enabled.
Sourcepub fn get_streaming(
&self,
name: &str,
) -> Option<Arc<dyn StreamingCompressionProvider>>
Available on crate feature streaming only.
pub fn get_streaming( &self, name: &str, ) -> Option<Arc<dyn StreamingCompressionProvider>>
streaming only.Get a streaming provider by encoding name.
Returns None if no streaming provider is registered for the given name.
Sourcepub fn supports_streaming(&self, name: &str) -> bool
Available on crate feature streaming only.
pub fn supports_streaming(&self, name: &str) -> bool
streaming only.Check if streaming compression is supported for the given encoding name.
Sourcepub fn decompress_stream(
&self,
encoding: &str,
reader: BoxedAsyncBufRead,
) -> Result<BoxedAsyncRead, ConnectError>
Available on crate feature streaming only.
pub fn decompress_stream( &self, encoding: &str, reader: BoxedAsyncBufRead, ) -> Result<BoxedAsyncRead, ConnectError>
streaming only.Create a streaming decompressor for the specified encoding.
Returns an AsyncRead that decompresses data from the input reader.
Returns an error if the encoding is not supported for streaming.
Sourcepub fn compress_stream(
&self,
encoding: &str,
reader: BoxedAsyncBufRead,
) -> Result<BoxedAsyncRead, ConnectError>
Available on crate feature streaming only.
pub fn compress_stream( &self, encoding: &str, reader: BoxedAsyncBufRead, ) -> Result<BoxedAsyncRead, ConnectError>
streaming only.Create a streaming compressor for the specified encoding.
Returns an AsyncRead that compresses data from the input reader.
Returns an error if the encoding is not supported for streaming.
Trait Implementations§
Source§impl Clone for CompressionRegistry
impl Clone for CompressionRegistry
Source§fn clone(&self) -> CompressionRegistry
fn clone(&self) -> CompressionRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more