Struct spacegate_kernel::plugins::context::SgRoutePluginContext
source · pub struct SgRoutePluginContext {
pub request: SgCtxRequest,
pub response: SgCtxResponse,
/* private fields */
}Expand description
The SgRoutePluginContext struct is used for communication within Spacegate. It serves as the core of the plugin system and represents a single request. When a request enters Spacegate, the information is encapsulated into a context, which is then passed to the plugin execution chain. The Spacegate kernel processes the request to the backend based on the context and stores the response back into the context before passing it back through the plugin execution chain. Ultimately, the Spacegate kernel extracts the content from the context to form the actual Spacegate response.
Clone is only available for testing purposes.
Fields§
§request: SgCtxRequest§response: SgCtxResponseImplementations§
source§impl SgRoutePluginContext
impl SgRoutePluginContext
pub fn new_http( method: Method, uri: Uri, version: Version, headers: HeaderMap<HeaderValue>, body: Body, remote_addr: SocketAddr, gateway_name: String, chose_route_rule: Option<ChosenHttpRouteRuleInst> ) -> Self
pub fn new_ws( method: Method, uri: Uri, version: Version, headers: HeaderMap<HeaderValue>, remote_addr: SocketAddr, gateway_name: String, chose_route_rule: Option<ChosenHttpRouteRuleInst> ) -> Self
sourcepub fn resp(
self,
status_code: StatusCode,
headers: HeaderMap<HeaderValue>,
body: Body
) -> Self
pub fn resp( self, status_code: StatusCode, headers: HeaderMap<HeaderValue>, body: Body ) -> Self
The following two methods can only be used to fill in the context [resp] [resp_from_error]
pub fn resp_from_error(self, error: TardisError) -> Self
pub fn is_resp_error(&self) -> bool
pub fn get_request_id(&self) -> &str
pub fn get_request_kind(&self) -> &SgPluginFilterKind
sourcepub async fn build_response(&mut self) -> TardisResult<Response<Body>>
pub async fn build_response(&mut self) -> TardisResult<Response<Body>>
build response from Context
pub fn get_ext(&self, key: &str) -> Option<&str>
pub fn set_ext(&mut self, key: impl Into<String>, value: impl Into<String>)
pub fn remove_ext(&mut self, key: &str)
pub fn get_action(&self) -> &SgRouteFilterRequestAction
pub fn set_action(&mut self, action: SgRouteFilterRequestAction)
pub fn set_chose_backend(&mut self, chose_backend: &SgBackendInst)
pub fn get_chose_backend_name(&self) -> Option<String>
pub fn get_available_backend(&self) -> Vec<&AvailableBackendInst>
pub fn get_timeout_ms(&self) -> Option<u64>
pub fn get_rule_matched(&self) -> Option<SgHttpRouteMatchInst>
pub fn get_gateway_name(&self) -> String
pub fn get_cert_info(&self) -> Option<&SGIdentInfo>
pub fn set_cert_info(&mut self, cert_info: SGIdentInfo)
pub async fn cache(&self) -> TardisResult<Arc<TardisCacheClient>>
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for SgRoutePluginContext
impl Send for SgRoutePluginContext
impl Sync for SgRoutePluginContext
impl Unpin for SgRoutePluginContext
impl !UnwindSafe for SgRoutePluginContext
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