proxy-wasm-rust-sdk
proxy-wasm-rust-sdk copied to clipboard
how can I use plugin configuration in httpContext
My plugin configuration is quite large, and I don't want to clone the plugin configuration every time When I create an httpContext. Can I use Rc::clone() inside Wasm? (Is it may cause memory leak? Im sorry not good at rust) . Or is there any other way for me to get the plugin configuration saved in RootContext from httpContext while avoiding cloning all the data?
struct HttpHeadersRoot {
wasm_configuration: Rc<WasmConfiguration>,
}
impl RootContext for HttpHeadersRoot {
fn get_type(&self) -> Option<ContextType> {
Some(ContextType::HttpContext)
}
fn on_configure(&mut self, _: usize) -> bool {
if let Some(config_bytes) = self.get_plugin_configuration() {
if str::from_utf8(&config_bytes).is_err() {
return false;
}
let t: WasmConfiguration = serde_json::from_str(str::from_utf8(&config_bytes).unwrap()).unwrap();
self.wasm_configuration = Rc::new(t);
return true
} else {
return false;
}
}
fn create_http_context(&self, _: u32) -> Option<Box<dyn HttpContext>> {
Some(Box::new(HttpHeaders {
wasm_configuration: Rc::clone(&self.wasm_configuration),
}))
}
}
I used an Arc
@LugiaChang
I used an
Arc
@LugiaChang
Is Wasm single thread? I'm not quite sure.
单线程的,每次请求结束之后会通过 drop 把数据释放掉,所以不存在内存泄露