pub struct WasmHttpContext;Expand description
WASM 侧的插件上下文实现。
不持有任何状态,所有数据通过宿主函数按需获取。
Trait Implementations§
Source§impl PluginContext for WasmHttpContext
impl PluginContext for WasmHttpContext
Source§fn request_id(&self) -> String
fn request_id(&self) -> String
请求 ID
Source§fn request_ts(&self) -> i64
fn request_ts(&self) -> i64
请求时间戳(毫秒)
Source§fn is_websocket(&self) -> bool
fn is_websocket(&self) -> bool
是否为 WebSocket 连接
Source§fn get_request_header(&self, name: &str) -> Option<String>
fn get_request_header(&self, name: &str) -> Option<String>
获取原始请求头(从 REQUEST_RAW_PARTS 读取,跨阶段可用)
Source§fn get_response_header(&self, name: &str) -> Option<String>
fn get_response_header(&self, name: &str) -> Option<String>
获取原始响应头(从 RESPONSE_SERDE_PARTS 读取,跨阶段可用)
Source§fn get_route_name(&self) -> Option<String>
fn get_route_name(&self) -> Option<String>
路由名称
Source§fn get_routing_url(&self) -> Option<String>
fn get_routing_url(&self) -> Option<String>
路由目标地址
Source§fn get_response_body_size(&self) -> Option<i64>
fn get_response_body_size(&self) -> Option<i64>
响应体大小
Source§fn set_response_body_size(&mut self, size: i64)
fn set_response_body_size(&mut self, size: i64)
设置响应体大小
Source§fn set_request_header(&mut self, name: &str, value: &str)
fn set_request_header(&mut self, name: &str, value: &str)
覆盖写入请求头
Source§fn set_response_header(&mut self, name: &str, value: &str)
fn set_response_header(&mut self, name: &str, value: &str)
覆盖写入响应头
Source§fn append_request_header(&mut self, name: &str, value: &str)
fn append_request_header(&mut self, name: &str, value: &str)
多值追加请求头
Source§fn append_response_header(&mut self, name: &str, value: &str)
fn append_response_header(&mut self, name: &str, value: &str)
多值追加响应头
Source§fn remove_request_header(&mut self, name: &str)
fn remove_request_header(&mut self, name: &str)
移除请求头
Source§fn remove_response_header(&mut self, name: &str)
fn remove_response_header(&mut self, name: &str)
移除响应头
Source§fn http_request(&self, req: &HttpRequest) -> Result<HttpResponse, PluginError>
fn http_request(&self, req: &HttpRequest) -> Result<HttpResponse, PluginError>
发起 HTTP 请求(默认实现返回错误,WASM 侧通过宿主函数重写)
Source§fn request_body(&self) -> Option<Bytes>
fn request_body(&self) -> Option<Bytes>
当前请求体(仅
on_request_body 阶段有值)Source§fn set_request_body(&mut self, body: Vec<u8>)
fn set_request_body(&mut self, body: Vec<u8>)
设置请求体(后续插件与转发上游均可见)
Source§fn response_body(&self) -> Option<Bytes>
fn response_body(&self) -> Option<Bytes>
当前响应体(仅
on_response_body 阶段有值)Source§fn set_response_body(&mut self, body: Vec<u8>)
fn set_response_body(&mut self, body: Vec<u8>)
设置响应体
Source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
类型擦除,供宿主侧 downcast 获取
HttpContextAuto Trait Implementations§
impl Freeze for WasmHttpContext
impl RefUnwindSafe for WasmHttpContext
impl Send for WasmHttpContext
impl Sync for WasmHttpContext
impl Unpin for WasmHttpContext
impl UnsafeUnpin for WasmHttpContext
impl UnwindSafe for WasmHttpContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> PluginContextExt for Twhere
T: PluginContext + ?Sized,
impl<T> PluginContextExt for Twhere
T: PluginContext + ?Sized,
Source§fn config_as_json(&self) -> Option<Value>
fn config_as_json(&self) -> Option<Value>
解析插件配置为 JSON Value(基于
config)Source§fn config_as<T>(&self) -> Result<T, PluginError>where
T: DeserializeOwned,
fn config_as<T>(&self) -> Result<T, PluginError>where
T: DeserializeOwned,
解析插件配置到指定类型(基于
config_json)