cardinal_plugins/
request_context.rs

1use crate::runner::PluginRunner;
2use cardinal_base::context::CardinalContext;
3use cardinal_base::destinations::container::DestinationWrapper;
4use cardinal_wasm_plugins::{ExecutionContext, SharedExecutionContext};
5use parking_lot::RwLock;
6use std::collections::HashMap;
7use std::sync::Arc;
8
9pub struct RequestContext {
10    pub cardinal_context: Arc<CardinalContext>,
11    pub backend: Arc<DestinationWrapper>,
12    pub plugin_runner: Arc<PluginRunner>,
13    pub response_headers: Option<HashMap<String, String>>,
14    pub shared_ctx: SharedExecutionContext,
15}
16
17impl RequestContext {
18    pub fn new(
19        context: Arc<CardinalContext>,
20        backend: Arc<DestinationWrapper>,
21        execution_context: ExecutionContext,
22    ) -> Self {
23        let runner = PluginRunner::new(context.clone());
24        Self {
25            cardinal_context: context,
26            backend,
27            plugin_runner: Arc::new(runner),
28            response_headers: None,
29            shared_ctx: Arc::new(RwLock::new(execution_context)),
30        }
31    }
32
33    pub fn persistent_vars(&self) -> Arc<RwLock<HashMap<String, String>>> {
34        self.shared_ctx.read().persistent_vars().clone()
35    }
36
37    pub fn shared_context(&self) -> SharedExecutionContext {
38        self.shared_ctx.clone()
39    }
40}