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§
Sourcefn request_id(&self) -> String
fn request_id(&self) -> String
请求 ID
Sourcefn request_ts(&self) -> i64
fn request_ts(&self) -> i64
请求时间戳(毫秒)
Sourcefn is_websocket(&self) -> bool
fn is_websocket(&self) -> bool
是否为 WebSocket 连接
Sourcefn get_route_name(&self) -> Option<String>
fn get_route_name(&self) -> Option<String>
路由名称
Sourcefn get_routing_url(&self) -> Option<String>
fn get_routing_url(&self) -> Option<String>
路由目标地址
Sourcefn get_response_body_size(&self) -> Option<i64>
fn get_response_body_size(&self) -> Option<i64>
响应体大小
Sourcefn set_response_body_size(&mut self, size: i64)
fn set_response_body_size(&mut self, size: i64)
设置响应体大小
Sourcefn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
类型擦除,供宿主侧 downcast 获取 HttpContext
Provided Methods§
Sourcefn http_request(&self, _req: &HttpRequest) -> Result<HttpResponse, PluginError>
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".