pub trait MiddlewarePlugin: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn on_request(
&self,
ctx: &mut RequestContext,
) -> Result<RequestAction, String>;
fn on_response(
&self,
ctx: &RequestContext,
headers: &mut ResponseHeaders,
) -> Result<(), String>;
// Provided method
fn priority(&self) -> u32 { ... }
}Expand description
A plugin that hooks into the HTTP request/response lifecycle.
Compile-time only — no WASM overhead on every request.
Priority determines stack position. Built-in priorities: CORS=100, RateLimit=200, Auth=300, Tenant=400, Tracing=500. Plugin middlewares default to 600.
Required Methods§
Sourcefn on_request(&self, ctx: &mut RequestContext) -> Result<RequestAction, String>
fn on_request(&self, ctx: &mut RequestContext) -> Result<RequestAction, String>
Called on each incoming request before the handler.
Return Ok(RequestAction::Continue) to proceed, or
Ok(RequestAction::Respond(..)) to short-circuit.
Sourcefn on_response(
&self,
ctx: &RequestContext,
headers: &mut ResponseHeaders,
) -> Result<(), String>
fn on_response( &self, ctx: &RequestContext, headers: &mut ResponseHeaders, ) -> Result<(), String>
Called after the handler produces a response.
Use this to inject headers, modify status, etc.