pub trait Plugin: Send + Sync {
// Required methods
fn plugin_type(&self) -> &str;
fn execute<'life0, 'async_trait>(
&'life0 self,
ctx: Context,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
// Provided methods
fn reads_response_body(&self) -> bool { ... }
fn cache_target(&self) -> Option<CacheTarget> { ... }
}Expand description
Every plugin (native or scripted) implements this trait.
A plugin is a node in a compiled policy graph. The engine drives each node
through execute and follows the output port the result
names.
A node type’s ports are not declared on this trait: they live in the
static registry (port_spec over ports), the single source of truth
shared by the graph compiler, the admin catalog, and the UI editor. A
plugin therefore cannot drift from its own declaration.
Required Methods§
Sourcefn plugin_type(&self) -> &str
fn plugin_type(&self) -> &str
Sourcefn execute<'life0, 'async_trait>(
&'life0 self,
ctx: Context,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn execute<'life0, 'async_trait>(
&'life0 self,
ctx: Context,
) -> Pin<Box<dyn Future<Output = Result<PluginOutput, PluginExecutionError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Executes the plugin logic against the request/response context.
Contract:
ctxis taken by value: the plugin owns theContextfor the duration of the call and must hand it back in either outcome — insidePluginOutputon success, or insidePluginExecutionErroron failure. The context is never lost.- On
Ok, the engine routes the returned context through the port thePluginOutputnames:PluginOutput::successtakes the node’ssuccessport, andPluginOutput::on_porttakes a named outcome port — the node did its job and chose a deliberate alternate route (denied,redirect,limited,broken,preflight,abort,routed,hit,respond,true/false), normally with the client-facing response already prepared. The named port must be one this type declares in itsPortSpec, or the policy would not have compiled; nothing is appended toctx.errors. - On
Err, thePluginExecutionErrorcarries both the context and aGatewayError, which the engine appends toctx.errorsbefore continuing through the node’serrorport (or the policy catch-all, or a generic 500) instead of aborting the request.Erris reserved for the node could not do its job — configuration, parse, or infrastructure failure. A plugin must never nameerrorfromOk.
Provided Methods§
Sourcefn reads_response_body(&self) -> bool
fn reads_response_body(&self) -> bool
Whether this configured instance reads context.response.body.
Defaults to true: a plugin that does not opt out forces the policy to
buffer, so adding a plugin can never silently break a stream. Opting out
is a deliberate statement about a specific configuration. Consulted at
policy-compile time by infer_stream_capability (src/graph/engine.rs),
which walks an upstream node’s success path and only marks it
stream-capable when every node on that path opts out.
Sourcefn cache_target(&self) -> Option<CacheTarget>
fn cache_target(&self) -> Option<CacheTarget>
The cache backend this node writes to, if it is a proxy-cache half.
Consulted at policy-compile time so an invalidation request can find
every backend that holds entries for a pair id – the same shape as
reads_response_body: the node describes itself, the compiler
collects the answers, and there is no process-wide registry that would
have to survive hot-reloads.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".