Skip to main content

Plugin

Trait Plugin 

Source
pub trait Plugin: Sync + Send {
    // Provided methods
    fn config_key(&self) -> Cow<'_, str> { ... }
    fn handle_request<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        _step: PluginStep,
        _session: &'life1 mut Session,
        _ctx: &'life2 mut Ctx,
    ) -> Pin<Box<dyn Future<Output = Result<RequestPluginResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait { ... }
    fn handle_response<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        _session: &'life1 mut Session,
        _ctx: &'life2 mut Ctx,
        _upstream_response: &'life3 mut ResponseHeader,
    ) -> Pin<Box<dyn Future<Output = Result<ResponsePluginResult>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait,
             'life3: 'async_trait { ... }
    fn handle_response_body(
        &self,
        _session: &mut Session,
        _ctx: &mut Ctx,
        _body: &mut Option<Bytes>,
        _end_of_stream: bool,
    ) -> Result<ResponseBodyPluginResult> { ... }
    fn handle_upstream_response(
        &self,
        _session: &mut Session,
        _ctx: &mut Ctx,
        _upstream_response: &mut ResponseHeader,
    ) -> Result<ResponsePluginResult> { ... }
    fn handle_upstream_response_body(
        &self,
        _session: &mut Session,
        _ctx: &mut Ctx,
        _body: &mut Option<Bytes>,
        _end_of_stream: bool,
    ) -> Result<ResponseBodyPluginResult> { ... }
}
Expand description

Core trait that defines the interface all plugins must implement.

Plugins can handle both requests and responses at different processing steps. The default implementations do nothing and return Ok.

Provided Methods§

Source

fn config_key(&self) -> Cow<'_, str>

Returns a unique key that identifies this specific plugin instance.

§Purpose
  • Can be used for caching plugin results
  • Helps differentiate between multiple instances of the same plugin type
  • Useful for tracking and debugging
§Default

Returns an empty string by default, which means no specific instance identification.

Source

fn handle_request<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, _step: PluginStep, _session: &'life1 mut Session, _ctx: &'life2 mut Ctx, ) -> Pin<Box<dyn Future<Output = Result<RequestPluginResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Processes an HTTP request at a specified lifecycle step.

§Parameters
  • _step - Current processing step in the request lifecycle (e.g., pre-routing, post-routing)
  • _session - Mutable reference to the HTTP session containing request data
  • _ctx - Mutable reference to the request context for storing state
§Returns
  • Ok(result) where:
    • result - The result of the plugin’s action on the request
      • Skipped: Plugin did not run or took no action
      • Continue: Plugin ran and modified the request; processing should continue
      • Respond(response): Plugin has decided to terminate the request and send an immediate response
    • response - Optional HTTP response:
      • Some(response): Terminates request processing and returns this response to client
      • None: Allows request to continue to next plugin or upstream
  • Err - Returns error if plugin processing failed
Source

fn handle_response<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, _session: &'life1 mut Session, _ctx: &'life2 mut Ctx, _upstream_response: &'life3 mut ResponseHeader, ) -> Pin<Box<dyn Future<Output = Result<ResponsePluginResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Processes an HTTP response at a specified lifecycle step.

§Parameters
  • _session - Mutable reference to the HTTP session
  • _ctx - Mutable reference to the request context
  • _upstream_response - Mutable reference to the upstream response header
§Returns
  • Ok(result) - The result of the plugin’s action on the response
    • Unchanged: Plugin did not modify the response
    • Modified: Plugin modified the response in some way
  • Err - Returns error if plugin processing failed
Source

fn handle_response_body( &self, _session: &mut Session, _ctx: &mut Ctx, _body: &mut Option<Bytes>, _end_of_stream: bool, ) -> Result<ResponseBodyPluginResult>

Processes an HTTP response body at a specified lifecycle step.

§Parameters
  • _session - Mutable reference to the HTTP session
  • _ctx - Mutable reference to the request context
  • _body - Mutable reference to the response body
  • _end_of_stream - Boolean flag:
    • true: The end of the response body has been reached
    • false: The response body is still being received
§Returns
  • Ok(result) - The result of the plugin’s action on the response body
    • Unchanged: Plugin did not modify the response body
    • PartialReplaced(new_body): Plugin replaced a part of the response body
    • FullyReplaced(new_body): Plugin replaced the response body with a new one
  • Err - Returns error if plugin processing failed
Source

fn handle_upstream_response( &self, _session: &mut Session, _ctx: &mut Ctx, _upstream_response: &mut ResponseHeader, ) -> Result<ResponsePluginResult>

Processes an upstream response at a specified lifecycle step.

§Parameters
  • _session - Mutable reference to the HTTP session
  • _ctx - Mutable reference to the request context
  • _upstream_response - Mutable reference to the upstream response header
§Returns
  • Ok(result) - The result of the plugin’s action on the response
    • Unchanged: Plugin did not modify the response
    • Modified: Plugin modified the response in some way
  • Err - Returns error if plugin processing failed
Source

fn handle_upstream_response_body( &self, _session: &mut Session, _ctx: &mut Ctx, _body: &mut Option<Bytes>, _end_of_stream: bool, ) -> Result<ResponseBodyPluginResult>

Processes an upstream response body at a specified lifecycle step.

§Parameters
  • _session - Mutable reference to the HTTP session
  • _ctx - Mutable reference to the request context
  • _body - Mutable reference to the upstream response body
  • _end_of_stream - Boolean flag:
    • true: The end of the upstream response body has been reached
    • false: The upstream response body is still being received
§Returns
  • Ok(result) - The result of the plugin’s action on the response body
    • Unchanged: Plugin did not modify the response body
    • PartialReplaced(new_body): Plugin replaced a part of the response body
    • FullyReplaced(new_body): Plugin replaced the response body with a new one
  • Err - Returns error if plugin processing failed

Implementors§