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: SgCtxResponse

Implementations§

source§

impl SgRoutePluginContext

source

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

source

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

source

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]

source

pub fn resp_from_error(self, error: TardisError) -> Self

source

pub fn is_resp_error(&self) -> bool

source

pub fn get_request_id(&self) -> &str

source

pub fn get_request_kind(&self) -> &SgPluginFilterKind

source

pub async fn build_response(&mut self) -> TardisResult<Response<Body>>

build response from Context

source

pub fn get_ext(&self, key: &str) -> Option<&str>

source

pub fn set_ext(&mut self, key: impl Into<String>, value: impl Into<String>)

source

pub fn remove_ext(&mut self, key: &str)

source

pub fn get_action(&self) -> &SgRouteFilterRequestAction

source

pub fn set_action(&mut self, action: SgRouteFilterRequestAction)

source

pub fn set_chose_backend(&mut self, chose_backend: &SgBackendInst)

source

pub fn get_chose_backend_name(&self) -> Option<String>

source

pub fn get_available_backend(&self) -> Vec<&AvailableBackendInst>

source

pub fn get_timeout_ms(&self) -> Option<u64>

source

pub fn get_rule_matched(&self) -> Option<SgHttpRouteMatchInst>

source

pub fn get_gateway_name(&self) -> String

source

pub fn get_cert_info(&self) -> Option<&SGIdentInfo>

source

pub fn set_cert_info(&mut self, cert_info: SGIdentInfo)

source

pub async fn cache(&self) -> TardisResult<Arc<TardisCacheClient>>

Trait Implementations§

source§

impl Debug for SgRoutePluginContext

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere 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> Same<T> for T

§

type Output = T

Should always be Self
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more