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§
Sourcefn config_key(&self) -> Cow<'_, str>
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.
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<RequestPluginResult>> + 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<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 requestSkipped: Plugin did not run or took no actionContinue: Plugin ran and modified the request; processing should continueRespond(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 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,
_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<'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 responseUnchanged: Plugin did not modify the responseModified: Plugin modified the response in some way
Err- Returns error if plugin processing failed
Sourcefn handle_response_body(
&self,
_session: &mut Session,
_ctx: &mut Ctx,
_body: &mut Option<Bytes>,
_end_of_stream: bool,
) -> Result<ResponseBodyPluginResult>
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 reachedfalse: The response body is still being received
§Returns
Ok(result)- The result of the plugin’s action on the response bodyUnchanged: Plugin did not modify the response bodyPartialReplaced(new_body): Plugin replaced a part of the response bodyFullyReplaced(new_body): Plugin replaced the response body with a new one
Err- Returns error if plugin processing failed
Sourcefn handle_upstream_response(
&self,
_session: &mut Session,
_ctx: &mut Ctx,
_upstream_response: &mut ResponseHeader,
) -> Result<ResponsePluginResult>
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 responseUnchanged: Plugin did not modify the responseModified: Plugin modified the response in some way
Err- Returns error if plugin processing failed
Sourcefn handle_upstream_response_body(
&self,
_session: &mut Session,
_ctx: &mut Ctx,
_body: &mut Option<Bytes>,
_end_of_stream: bool,
) -> Result<ResponseBodyPluginResult>
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 reachedfalse: The upstream response body is still being received
§Returns
Ok(result)- The result of the plugin’s action on the response bodyUnchanged: Plugin did not modify the response bodyPartialReplaced(new_body): Plugin replaced a part of the response bodyFullyReplaced(new_body): Plugin replaced the response body with a new one
Err- Returns error if plugin processing failed