Skip to main content

WasmHttpContext

Struct WasmHttpContext 

Source
pub struct WasmHttpContext;
Expand description

WASM 侧的插件上下文实现。

不持有任何状态,所有数据通过宿主函数按需获取。

Trait Implementations§

Source§

impl PluginContext for WasmHttpContext

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_request_header(&self, name: &str) -> Option<String>

获取原始请求头(从 REQUEST_RAW_PARTS 读取,跨阶段可用)
Source§

fn get_response_header(&self, name: &str) -> Option<String>

获取原始响应头(从 RESPONSE_SERDE_PARTS 读取,跨阶段可用)
Source§

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

请求方法(仅 on_request 阶段有值)
Source§

fn uri(&self) -> Option<Uri>

请求 URI(仅 on_request 阶段有值)
Source§

fn set_uri(&mut self, uri: Uri)

覆盖写入请求 URI(仅 on_request 阶段生效,路径改写场景)
Source§

fn status(&self) -> Option<u16>

响应状态码(仅 on_response 阶段有值)
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 set_request_header(&mut self, name: &str, value: &str)

覆盖写入请求头
Source§

fn set_response_header(&mut self, name: &str, value: &str)

覆盖写入响应头
Source§

fn append_request_header(&mut self, name: &str, value: &str)

多值追加请求头
Source§

fn append_response_header(&mut self, name: &str, value: &str)

多值追加响应头
Source§

fn remove_request_header(&mut self, name: &str)

移除请求头
Source§

fn remove_response_header(&mut self, name: &str)

移除响应头
Source§

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

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

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

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

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

插件配置(JSON 字符串),由 Host 在调用前注入到上下文
Source§

fn request_body(&self) -> Option<Bytes>

当前请求体(仅 on_request_body 阶段有值)
Source§

fn set_request_body(&mut self, body: Vec<u8>)

设置请求体(后续插件与转发上游均可见)
Source§

fn response_body(&self) -> Option<Bytes>

当前响应体(仅 on_response_body 阶段有值)
Source§

fn set_response_body(&mut self, body: Vec<u8>)

设置响应体
Source§

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

类型擦除,供宿主侧 downcast 获取 HttpContext
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 级别日志

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PluginContextExt for T
where T: PluginContext + ?Sized,

Source§

fn config_as_json(&self) -> Option<Value>

解析插件配置为 JSON Value(基于 config
Source§

fn config_as<T>(&self) -> Result<T, PluginError>

解析插件配置到指定类型(基于 config_json
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.