pub trait Plugin: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn info(&self) -> PluginInfo;
fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
context: &'life1 HttpContext,
config: &'life2 Value,
) -> Pin<Box<dyn Future<Output = Result<Value, PluginError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
}Expand description
插件定义
- name
插件的名称,原则上不要重复。在PluginManager中,如果重复了,后添加的将被覆盖。
- execute
execute接收HttpContext参数,该HttpContext是可变的(内部可变性),可在插件逻辑内部修改请求和响应。
注意:当多个插件修改HttpContext的同一个属性时,后执行的插件会覆盖前一个插件的修改。
插件实现方应该自行决定插件运行阶段(请求阶段或者响应阶段),从而获取或修改request或response的数据。
- 返回值 返回[serde_json:Value]
Required Methods§
Sourcefn info(&self) -> PluginInfo
fn info(&self) -> PluginInfo
插件信息
Sourcefn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
context: &'life1 HttpContext,
config: &'life2 Value,
) -> Pin<Box<dyn Future<Output = Result<Value, PluginError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn execute<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
context: &'life1 HttpContext,
config: &'life2 Value,
) -> Pin<Box<dyn Future<Output = Result<Value, PluginError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
执行插件