pub struct BrotliPlugin {
types: ContentTypes,
min_length: usize,
comp_level: u32,
vary: bool,
}Expand description
Compresses Context.response.body with brotli, sets
content-encoding: br, drops the stale content-length, and downgrades
a strong ETag to a weak one (as APISIX does — the compressed bytes are
not byte-identical to the original representation). Skipped (pure
passthrough) when the client does not accept br, 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 BrotliPlugin
impl BrotliPlugin
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 0-11, default6): brotli quality level (matches ngx_brotli’sbrotli_comp_leveldefault).vary(bool, defaultfalse): when true, appendsVary: Accept-Encodingto compressed responses.
type: brotli
config:
types: ["text/html", "application/json"]
min_length: 20
comp_level: 6
vary: trueTrait Implementations§
Source§impl Plugin for BrotliPlugin
impl Plugin for BrotliPlugin
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 BrotliPlugin
impl RefUnwindSafe for BrotliPlugin
impl Send for BrotliPlugin
impl Sync for BrotliPlugin
impl Unpin for BrotliPlugin
impl UnsafeUnpin for BrotliPlugin
impl UnwindSafe for BrotliPlugin
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