pub trait Plugin: Sync + Send {
// Provided methods
fn hash_key(&self) -> String { ... }
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<(bool, Option<HttpResponse>)>> + 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,
_step: PluginStep,
_session: &'life1 mut Session,
_ctx: &'life2 mut Ctx,
_upstream_response: &'life3 mut ResponseHeader,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait { ... }
fn handle_upstream_response(
&self,
_step: PluginStep,
_session: &mut Session,
_ctx: &mut Ctx,
_upstream_response: &mut ResponseHeader,
) -> Result<bool> { ... }
}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§
Sourcefn hash_key(&self) -> String
fn hash_key(&self) -> String
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.
Sourcefn 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<(bool, Option<HttpResponse>)>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
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<(bool, Option<HttpResponse>)>> + 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((executed, response))where:executed- Boolean flag:true: Plugin performed meaningful logic for this requestfalse: Plugin was skipped or did nothing for this request
response- Optional HTTP response:Some(response): Terminates request processing and returns this response to clientNone: Allows request to continue to next plugin or upstream
Err- Returns error if plugin processing failed
Sourcefn handle_response<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_step: PluginStep,
_session: &'life1 mut Session,
_ctx: &'life2 mut Ctx,
_upstream_response: &'life3 mut ResponseHeader,
) -> Pin<Box<dyn Future<Output = Result<bool>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn handle_response<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_step: PluginStep,
_session: &'life1 mut Session,
_ctx: &'life2 mut Ctx,
_upstream_response: &'life3 mut ResponseHeader,
) -> Pin<Box<dyn Future<Output = Result<bool>> + 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
_step- Current processing step in the response lifecycle_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(modified)- Boolean flag:true: Plugin modified the response in some wayfalse: Plugin did not modify the response
Err- Returns error if plugin processing failed