pub struct CompressionConfig {
pub default_level: u32,
pub gzip_enabled: bool,
pub gzip_level: Option<u32>,
pub brotli_enabled: bool,
pub brotli_level: Option<u32>,
pub zstd_enabled: bool,
pub zstd_level: Option<u32>,
pub min_size_bytes: usize,
pub content_types: Vec<String>,
}Expand description
Compression settings extracted from the filter for use by the protocol handler when registering Pingora’s compression module.
§Example
use praxis_filter::CompressionConfig;
let config = CompressionConfig::default();
assert_eq!(config.default_level, 6);
assert_eq!(config.min_size_bytes, 256);
assert!(config.gzip_enabled);
assert!(config.brotli_enabled);
assert!(config.zstd_enabled);Fields§
§default_level: u32Default compression level for all algorithms.
gzip_enabled: boolWhether gzip is enabled.
gzip_level: Option<u32>Gzip-specific compression level (overrides default).
brotli_enabled: boolWhether brotli is enabled.
brotli_level: Option<u32>Brotli-specific compression level (overrides default).
zstd_enabled: boolWhether zstd is enabled.
zstd_level: Option<u32>Zstd-specific compression level (overrides default).
min_size_bytes: usizeMinimum response body size in bytes; smaller responses are not compressed.
content_types: Vec<String>MIME type prefixes/values that qualify for compression.
A response whose Content-Type starts with any entry
in this list is eligible.
Implementations§
Source§impl CompressionConfig
impl CompressionConfig
Sourcepub fn matches_content_type(&self, content_type: &str) -> bool
pub fn matches_content_type(&self, content_type: &str) -> bool
Returns true if the given Content-Type value matches the
configured allowlist.
use praxis_filter::CompressionConfig;
let config = CompressionConfig::default();
assert!(config.matches_content_type("text/html; charset=utf-8"));
assert!(config.matches_content_type("application/json"));
assert!(!config.matches_content_type("image/png"));Sourcepub fn exceeds_min_size(&self, content_length: Option<usize>) -> bool
pub fn exceeds_min_size(&self, content_length: Option<usize>) -> bool
Returns true if the response body is large enough to warrant
compression, based on the Content-Length header value.
When Content-Length is absent, returns true (compress by
default for chunked/streaming responses).
use praxis_filter::CompressionConfig;
let config = CompressionConfig::default();
assert!(!config.exceeds_min_size(Some(100)));
assert!(config.exceeds_min_size(Some(1024)));
assert!(config.exceeds_min_size(None));Sourcepub fn is_already_compressed(&self, headers: &HeaderMap) -> bool
pub fn is_already_compressed(&self, headers: &HeaderMap) -> bool
Returns true if the response already has a Content-Encoding
header, indicating it is pre-compressed.
use http::HeaderMap;
use praxis_filter::CompressionConfig;
let config = CompressionConfig::default();
let empty = HeaderMap::new();
assert!(!config.is_already_compressed(&empty));
let mut headers = HeaderMap::new();
headers.insert("content-encoding", "gzip".parse().unwrap());
assert!(config.is_already_compressed(&headers));Sourcepub fn should_compress(&self, headers: &HeaderMap) -> bool
pub fn should_compress(&self, headers: &HeaderMap) -> bool
Returns true if compression should be applied to this
response based on Content-Type, Content-Length, and existing
Content-Encoding.
use http::HeaderMap;
use praxis_filter::CompressionConfig;
let config = CompressionConfig::default();
let mut headers = HeaderMap::new();
headers.insert("content-type", "text/html".parse().unwrap());
headers.insert("content-length", "1024".parse().unwrap());
assert!(config.should_compress(&headers));
let mut small = HeaderMap::new();
small.insert("content-type", "text/html".parse().unwrap());
small.insert("content-length", "10".parse().unwrap());
assert!(!config.should_compress(&small));Trait Implementations§
Source§impl Clone for CompressionConfig
impl Clone for CompressionConfig
Source§fn clone(&self) -> CompressionConfig
fn clone(&self) -> CompressionConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more