pub trait Plugin: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn info(&self) -> PluginInfo;
// Provided methods
fn on_request<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut dyn PluginContext,
) -> Pin<Box<dyn Future<Output = PluginResult> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_request_body<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut dyn PluginContext,
) -> Pin<Box<dyn Future<Output = PluginResult> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_response<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut dyn PluginContext,
) -> Pin<Box<dyn Future<Output = PluginResult> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_response_body<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut dyn PluginContext,
) -> Pin<Box<dyn Future<Output = PluginResult> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
fn on_logging<'life0, 'life1, 'async_trait>(
&'life0 self,
_: &'life1 mut dyn PluginContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait { ... }
}Expand description
插件定义
插件开发者实现此 trait。
Required Methods§
Provided Methods§
Sourcefn on_request<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut dyn PluginContext,
) -> Pin<Box<dyn Future<Output = PluginResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_request<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut dyn PluginContext,
) -> Pin<Box<dyn Future<Output = PluginResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
请求阶段,可改写请求头
插件配置通过 ctx.config() 获取,请求头通过 ctx 读写。
Sourcefn on_request_body<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut dyn PluginContext,
) -> Pin<Box<dyn Future<Output = PluginResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_request_body<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut dyn PluginContext,
) -> Pin<Box<dyn Future<Output = PluginResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
请求体阶段,可改写请求体
请求体通过 ctx.request_body() 读取、ctx.set_request_body() 覆盖。
Sourcefn on_response<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut dyn PluginContext,
) -> Pin<Box<dyn Future<Output = PluginResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_response<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut dyn PluginContext,
) -> Pin<Box<dyn Future<Output = PluginResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
响应阶段,可改写响应头
Sourcefn on_response_body<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut dyn PluginContext,
) -> Pin<Box<dyn Future<Output = PluginResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_response_body<'life0, 'life1, 'async_trait>(
&'life0 self,
_ctx: &'life1 mut dyn PluginContext,
) -> Pin<Box<dyn Future<Output = PluginResult> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
响应体阶段,可改写响应体
响应体通过 ctx.response_body() 读取、ctx.set_response_body() 覆盖。
Sourcefn on_logging<'life0, 'life1, 'async_trait>(
&'life0 self,
_: &'life1 mut dyn PluginContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn on_logging<'life0, 'life1, 'async_trait>(
&'life0 self,
_: &'life1 mut dyn PluginContext,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
日志阶段
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".