ResponseModifierPlugin

Trait ResponseModifierPlugin 

Source
pub trait ResponseModifierPlugin: Send + Sync {
    // Required methods
    fn capabilities(&self) -> PluginCapabilities;
    fn initialize<'life0, 'life1, 'async_trait>(
        &'life0 self,
        config: &'life1 ResponseModifierConfig,
    ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             Self: 'async_trait;
    fn should_modify<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        &'life0 self,
        context: &'life1 PluginContext,
        request: &'life2 ResponseRequest,
        response: &'life3 ResponseData,
        config: &'life4 ResponseModifierConfig,
    ) -> Pin<Box<dyn Future<Output = Result<PluginResult<bool>, PluginError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             'life4: 'async_trait,
             Self: 'async_trait;
    fn modify_response<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        context: &'life1 PluginContext,
        request: &'life2 ResponseRequest,
        response: ResponseData,
        config: &'life3 ResponseModifierConfig,
    ) -> Pin<Box<dyn Future<Output = Result<PluginResult<ResponseData>, PluginError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait,
             Self: 'async_trait;
    fn priority(&self) -> i32;
    fn validate_config(
        &self,
        config: &ResponseModifierConfig,
    ) -> Result<(), PluginError>;
    fn cleanup<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
       where 'life0: 'async_trait,
             Self: 'async_trait;
}
Expand description

Response modifier plugin trait

Implement this trait to modify responses after they have been generated. This allows plugins to transform, enhance, or filter responses before they are sent to the client.

Use cases include:

  • Adding custom headers or metadata
  • Compressing response bodies
  • Encrypting sensitive data
  • Filtering or redacting content
  • Adding CORS headers
  • Response validation

Required Methods§

Source

fn capabilities(&self) -> PluginCapabilities

Get plugin capabilities (permissions and limits)

Source

fn initialize<'life0, 'life1, 'async_trait>( &'life0 self, config: &'life1 ResponseModifierConfig, ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Initialize the plugin with configuration

Source

fn should_modify<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, context: &'life1 PluginContext, request: &'life2 ResponseRequest, response: &'life3 ResponseData, config: &'life4 ResponseModifierConfig, ) -> Pin<Box<dyn Future<Output = Result<PluginResult<bool>, PluginError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait, Self: 'async_trait,

Check if this plugin should modify the given response

§Arguments
  • context - Plugin execution context
  • request - Original request information
  • response - Current response data
  • config - Plugin configuration
§Returns

True if this plugin should modify the response

Source

fn modify_response<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, context: &'life1 PluginContext, request: &'life2 ResponseRequest, response: ResponseData, config: &'life3 ResponseModifierConfig, ) -> Pin<Box<dyn Future<Output = Result<PluginResult<ResponseData>, PluginError>> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, Self: 'async_trait,

Modify the response

This method is called when the plugin has indicated it should modify the response. It receives the current response and returns a modified version.

§Arguments
  • context - Plugin execution context
  • request - Original request information
  • response - Current response data to modify
  • config - Plugin configuration
§Returns

Modified response data

Source

fn priority(&self) -> i32

Get plugin priority (lower numbers = higher priority, executed first)

Source

fn validate_config( &self, config: &ResponseModifierConfig, ) -> Result<(), PluginError>

Validate plugin configuration

Source

fn cleanup<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), PluginError>> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Cleanup plugin resources

Implementors§