pub struct Compression { /* private fields */ }Expand description
The response compression plugin.
Construct with Compression::new and refine with the builder methods.
Also usable as scoped middleware through RouteBuilder::intercept.
Implementations§
Source§impl Compression
impl Compression
Sourcepub fn new() -> Compression
pub fn new() -> Compression
Brotli, then gzip, then deflate, for text-like bodies of at least 1 KiB.
Sourcepub fn min_size(self, bytes: usize) -> Compression
pub fn min_size(self, bytes: usize) -> Compression
Only compress buffered bodies of at least bytes.
A streamed body has no length until it ends, so it is always compressed regardless of this setting.
Sourcepub fn level(self, level: Level) -> Compression
pub fn level(self, level: Level) -> Compression
Set how hard the encoder works.
Sourcepub fn encodings(
self,
encodings: impl IntoIterator<Item = Encoding>,
) -> Compression
pub fn encodings( self, encodings: impl IntoIterator<Item = Encoding>, ) -> Compression
Restrict and order the codings this server is willing to produce, most preferred first.
Client preference wins on q value; this order only breaks ties. Use it
to drop brotli on a CPU-bound service:
use churust_compression::{Compression, Encoding};
let plugin = Compression::new().encodings([Encoding::Gzip]);§Panics
If the list is empty, which would install a plugin that can never do anything.
Sourcepub fn compressible<F>(self, f: F) -> Compression
pub fn compressible<F>(self, f: F) -> Compression
Replace the media-type predicate.
use churust_compression::{compressible_by_default, Compression};
// Also compress a bespoke binary format that happens to be repetitive.
let plugin = Compression::new().compressible(|ct| {
compressible_by_default(ct) || ct.starts_with("application/x-telemetry")
});Trait Implementations§
Source§impl Clone for Compression
impl Clone for Compression
Source§fn clone(&self) -> Compression
fn clone(&self) -> Compression
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Compression
impl Debug for Compression
Source§impl Default for Compression
impl Default for Compression
Source§fn default() -> Compression
fn default() -> Compression
Source§impl Middleware for Compression
impl Middleware for Compression
Source§fn handle<'life0, 'async_trait>(
&'life0 self,
call: Call,
next: Next,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
'life0: 'async_trait,
Compression: 'async_trait,
fn handle<'life0, 'async_trait>(
&'life0 self,
call: Call,
next: Next,
) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>where
'life0: 'async_trait,
Compression: 'async_trait,
next.run(call) to
proceed, and return the (possibly post-processed) response.Source§impl Plugin for Compression
impl Plugin for Compression
Source§fn install(self: Box<Compression>, app: &mut AppBuilder)
fn install(self: Box<Compression>, app: &mut AppBuilder)
Installed in Phase::Plugins. Anything that inspects a response body
must sit inside this layer, since outside it the body is compressed.