25 releases
| 0.2.41 | Nov 28, 2025 |
|---|---|
| 0.2.40 | Nov 27, 2025 |
| 0.2.39 | Oct 27, 2025 |
| 0.2.23 | Sep 30, 2025 |
| 0.1.0 | Sep 26, 2025 |
#1442 in Development tools
22 downloads per month
Used in 3 crates
(2 directly)
175KB
4K
SLoC
cardinal-plugins
The middleware runtime.
What it does
- Tracks builtin middleware (
RestrictedRouteMiddleware, etc.) and user-supplied WASM plugins insidePluginContainer. - Executes middleware chains via
PluginRunner, respecting global order and destination-scoped middleware. - Wraps WASM modules by delegating to
cardinal-wasm-plugins.
Adding middleware
Rust
struct MyInbound;
#[async_trait::async_trait]
impl RequestMiddleware for MyInbound {
async fn on_request(&self, session: &mut Session, backend: Arc<DestinationWrapper>, ctx: Arc<CardinalContext>) -> Result<MiddlewareResult, CardinalError> {
// inspect/modify session, backend, ctx
Ok(MiddlewareResult::Continue)
}
}
Register it by inserting into PluginContainer during bootstrap (either by editing the defaults or supplying a provider factory).
WASM
- Compile an AssemblyScript or Rust-compiled WASM file.
- Add it to configuration:
[[plugins]]
wasm = { name = "my-filter", path = "filters/my_filter.wasm" }
The runner validates exports (handle, __new) and executes it in inbound or outbound mode depending on where it’s registered.
Dependencies
~36–54MB
~1M SLoC