pub struct GzipPlugin {
types: ContentTypes,
min_length: usize,
comp_level: u32,
vary: bool,
}Expand description
Compresses Context.response.body with gzip, sets
content-encoding: gzip, and drops the stale content-length so the
server layer recomputes it. Skipped (pure passthrough) when the client
does not accept gzip, the response is already content-encoded, the
content type does not match, or the body is shorter than min_length.
This plugin never fails at execution time — a codec error logs a warning
and leaves the response untouched.
Fields§
§types: ContentTypes§min_length: usize§comp_level: u32§vary: boolImplementations§
Source§impl GzipPlugin
impl GzipPlugin
Sourcepub fn from_config(config: &HashMap<String, Value>) -> Result<Self, String>
pub fn from_config(config: &HashMap<String, Value>) -> Result<Self, String>
Builds the plugin from node config.
Accepted keys (all optional):
types(array of content types, or the string"*"for any; default["text/html"]): response content types to compress. The responsecontent-typeis compared with parameters (;charset=...) stripped; a response without a content type is never compressed.min_length(integer ≥ 1, default20): bodies shorter than this are not compressed.comp_level(integer 1-9, default1): gzip compression level.vary(bool, defaultfalse): when true, appendsVary: Accept-Encodingto compressed responses.
type: gzip
config:
types: ["text/html", "application/json"]
min_length: 20
comp_level: 6
vary: trueTrait Implementations§
Source§impl Plugin for GzipPlugin
impl Plugin for GzipPlugin
Source§fn plugin_type(&self) -> &str
fn plugin_type(&self) -> &str
Unique identifier for the plugin type (e.g., “proxy-rewrite”, “upstream”).
Source§fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn execute<'life0, 'life1, 'async_trait>(
&'life0 self,
ctx: Context,
_named_inputs: &'life1 HashMap<String, Value>,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Executes the plugin logic against the request/response context. Read more
Auto Trait Implementations§
impl Freeze for GzipPlugin
impl RefUnwindSafe for GzipPlugin
impl Send for GzipPlugin
impl Sync for GzipPlugin
impl Unpin for GzipPlugin
impl UnsafeUnpin for GzipPlugin
impl UnwindSafe for GzipPlugin
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more