ferrotunnel-plugin-0.9.6 has been yanked.
Ferrotunnel Plugin System
This crate contains the core traits and infrastructure for the Ferrotunnel plugin system.
Plugin Developer Guide
FerroTunnel supports a powerful trait-based plugin system that allows you to intercept and modify request/response traffic, enforce authentication, rate limiting, and more.
Quick Start
To create a new plugin, implement the Plugin trait from ferrotunnel-plugin.
use ;
use async_trait;
;
Plugin Lifecycle
- Init: Called when the server starts. Use this to set up database connections or other resources.
- Hooks:
on_request: Called before the request is forwarded to the tunnel.on_response: Called after the response is received from the tunnel.on_stream_data: Called when raw data flows through the stream (TCP mode).
- Shutdown: Called when the server shuts down.
Plugin Actions
PluginAction::Continue: Allow the request to proceed to the next plugin or target.PluginAction::Reject { status, reason }: Stop processing and return an error response immediately.PluginAction::Respond { status, headers, body }: Return a custom response immediately.PluginAction::Modify: (Upcoming) Modify the request/response extensively.
Examples
See ferrotunnel-plugin/src/builtin/ for built-in plugins (Logger, TokenAuth, RateLimit).
Check the examples/ directory for more:
hello_plugin.rs: Simple header injection.header_filter.rs: Removing sensitive headers.ip_blocklist.rs: Blocking requests by IP.
Testing
You can test plugins in two ways:
-
Unit Tests: Mock
RequestContextand assert onPluginActionresults.async -
Run Examples:
Usage
Register your plugin in ferrotunnel-server/src/main.rs:
registry.register;