Skip to main content

PluginContext

Trait PluginContext 

Source
pub trait PluginContext: Send {
Show 16 methods // Required methods fn request_id(&self) -> String; fn request_ts(&self) -> i64; fn is_sse(&self) -> bool; fn is_websocket(&self) -> bool; fn get_route_name(&self) -> Option<String>; fn get_routing_url(&self) -> Option<String>; fn get_response_body_size(&self) -> Option<i64>; fn set_response_body_size(&mut self, size: i64); fn log(&self, level: i32, msg: &str); fn as_any_mut(&mut self) -> &mut dyn Any; // Provided methods fn log_error(&self, msg: &str) { ... } fn log_warn(&self, msg: &str) { ... } fn log_info(&self, msg: &str) { ... } fn log_debug(&self, msg: &str) { ... } fn log_trace(&self, msg: &str) { ... } fn http_request( &self, _req: &HttpRequest, ) -> Result<HttpResponse, PluginError> { ... }
}
Expand description

插件上下文接口

宿主侧通过 HttpContext 实现,WASM 侧通过 WasmHttpContext 实现。 插件开发者面向此 trait 编程,不依赖具体实现。

Required Methods§

Source

fn request_id(&self) -> String

请求 ID

Source

fn request_ts(&self) -> i64

请求时间戳(毫秒)

Source

fn is_sse(&self) -> bool

是否为 SSE 连接

Source

fn is_websocket(&self) -> bool

是否为 WebSocket 连接

Source

fn get_route_name(&self) -> Option<String>

路由名称

Source

fn get_routing_url(&self) -> Option<String>

路由目标地址

Source

fn get_response_body_size(&self) -> Option<i64>

响应体大小

Source

fn set_response_body_size(&mut self, size: i64)

设置响应体大小

Source

fn log(&self, level: i32, msg: &str)

输出日志(底层接口,level 使用 LOG_* 常量)

Source

fn as_any_mut(&mut self) -> &mut dyn Any

类型擦除,供宿主侧 downcast 获取 HttpContext

Provided Methods§

Source

fn log_error(&self, msg: &str)

输出 ERROR 级别日志

Source

fn log_warn(&self, msg: &str)

输出 WARN 级别日志

Source

fn log_info(&self, msg: &str)

输出 INFO 级别日志

Source

fn log_debug(&self, msg: &str)

输出 DEBUG 级别日志

Source

fn log_trace(&self, msg: &str)

输出 TRACE 级别日志

Source

fn http_request(&self, _req: &HttpRequest) -> Result<HttpResponse, PluginError>

发起 HTTP 请求(默认实现返回错误,WASM 侧通过宿主函数重写)

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl PluginContext for HttpContext

Source§

fn request_id(&self) -> String

Source§

fn request_ts(&self) -> i64

Source§

fn is_sse(&self) -> bool

Source§

fn is_websocket(&self) -> bool

Source§

fn get_route_name(&self) -> Option<String>

Source§

fn get_routing_url(&self) -> Option<String>

Source§

fn get_response_body_size(&self) -> Option<i64>

Source§

fn set_response_body_size(&mut self, size: i64)

Source§

fn log(&self, level: i32, msg: &str)

Source§

fn as_any_mut(&mut self) -> &mut dyn Any

Implementors§