pub struct CompressionLayer { /* private fields */ }Expand description
A response-compression policy. See the module docs.
Implementations§
Source§impl CompressionLayer
impl CompressionLayer
Sourcepub fn new() -> Self
pub fn new() -> Self
Defaults: compress responses of at least 1 KiB, prefer brotli when
the client’s Accept-Encoding offers it (brotli compresses tighter;
gzip is the universal fallback), brotli quality 4.
Sourcepub fn min_size(self, bytes: usize) -> Self
pub fn min_size(self, bytes: usize) -> Self
Don’t compress bodies smaller than bytes. Below the threshold the
encoder’s framing overhead and the CPU cost outweigh the savings (and
a small response usually fits in one packet anyway).
Sourcepub fn prefer_gzip(self) -> Self
pub fn prefer_gzip(self) -> Self
When the client offers both gzip and br, choose gzip. (Brotli is
the default — it’s tighter, especially for JSON, at a small CPU cost.)
Sourcepub fn brotli_quality(self, q: u32) -> Self
pub fn brotli_quality(self, q: u32) -> Self
Brotli compression quality (0 = fastest / least compressed, 11 = slowest / tightest). Default is 4 — the speed/ratio sweet spot for per-request dynamic content. Quality 11 is 10-100× slower for roughly 5% additional savings; it’s appropriate for pre-compressed static assets, not for per-request work.
Values above 11 are clamped to 11. Named for the codec it controls: it
has no effect on gzip (which uses flate2’s default level, 6); a
gzip_level(_) knob can be added alongside if/when needed.
Trait Implementations§
Source§impl Clone for CompressionLayer
impl Clone for CompressionLayer
Source§fn clone(&self) -> CompressionLayer
fn clone(&self) -> CompressionLayer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more