Skip to main content

Ctx

Struct Ctx 

Source
pub struct Ctx {
    pub conn: ConnectionInfo,
    pub upstream: UpstreamInfo,
    pub timing: Timing,
    pub state: RequestState,
    pub cache: Option<CacheInfo>,
    pub features: Option<Features>,
    pub plugins: Option<Vec<(String, Arc<dyn Plugin>)>>,
}
Expand description

Represents the state of a request/response cycle, tracking various metrics and properties including connection details, caching information, and upstream server interactions.

Fields§

§conn: ConnectionInfo

Information about the client connection.

§upstream: UpstreamInfo

Information about the upstream server.

§timing: Timing

Timing metrics for the request lifecycle.

§state: RequestState

State related to the current request.

§cache: Option<CacheInfo>

Cache-related information. Wrapped in Option to save memory when not in use.

§features: Option<Features>

Optional features. Wrapped in Option to save memory when not in use.

§plugins: Option<Vec<(String, Arc<dyn Plugin>)>>

Plugins for the current location

Implementations§

Source§

impl Ctx

Source

pub fn new() -> Self

Creates a new Ctx instance with the current timestamp and default values.

Returns a new Ctx struct initialized with the current timestamp and all other fields set to their default values.

Source

pub fn add_variable(&mut self, key: &str, value: &str)

Adds a variable to the state’s variables map with the given key and value.

§Arguments
  • key - The variable name.
  • value - The value to store for this variable.
Source

pub fn extend_variables(&mut self, values: AHashMap<String, String>)

Extends the variables map with the given key-value pairs.

§Arguments
  • values - A HashMap containing the key-value pairs to add.
Source

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

Returns the value of a variable by key.

§Arguments
  • key - The key of the variable to retrieve.

Returns: Option<&str> representing the value of the variable, or None if the variable does not exist.

Source

pub fn add_modify_body_handler( &mut self, name: &str, handler: Box<dyn ModifyResponseBody>, )

Adds a modify body handler to the context.

§Arguments
  • name - The name of the handler.
  • handler - The handler to add.
Source

pub fn get_modify_body_handler( &mut self, name: &str, ) -> Option<&mut Box<dyn ModifyResponseBody>>

Returns the modify body handler by name.

Source

pub fn get_upstream_response_time(&self) -> Option<u32>

Returns the upstream response time if it’s less than one hour, otherwise None. This helps filter out potentially invalid or stale timing data.

Returns: Option representing milliseconds, or None if time exceeds 1 hour.

Source

pub fn get_upstream_connect_time(&self) -> Option<u32>

Returns the upstream connect time if it’s less than one hour, otherwise None. This helps filter out potentially invalid or stale timing data.

Returns: Option representing milliseconds, or None if time exceeds 1 hour.

Source

pub fn get_upstream_processing_time(&self) -> Option<u32>

Returns the upstream processing time if it’s less than one hour, otherwise None. This helps filter out potentially invalid or stale timing data.

Returns: Option representing milliseconds, or None if time exceeds 1 hour.

Source

pub fn add_plugin_processing_time(&mut self, name: &str, time: u32)

Adds a plugin processing time to the context.

§Arguments
  • name - The name of the plugin.
  • time - The time taken by the plugin in milliseconds.
Source

pub fn append_log_value(&self, buf: &mut BytesMut, key: &str)

Appends a formatted value to the provided log buffer based on the given key. Handles various metrics including connection info, timing data, and TLS details.

§Arguments
  • buf - The BytesMut buffer to append the value to.
  • key - The key identifying which state value to format and append.

Returns: The modified BytesMut buffer.

Source

pub fn generate_server_timing(&self) -> String

Generates a Server-Timing header value based on the context’s timing metrics.

The Server-Timing header allows servers to communicate performance metrics about the request-response cycle to the client. This implementation includes various timing metrics like connection time, processing time, and cache operations.

Returns a String containing the formatted Server-Timing header value.

Source

pub fn push_cache_key(&mut self, key: String)

Pushes a single cache key component to the context.

Source

pub fn extend_cache_keys(&mut self, keys: Vec<String>)

Extends the cache key components with a vector of keys.

Source

pub fn update_upstream_timing_from_digest( &mut self, digest: &Digest, reused: bool, )

Updates the upstream timing from the digest.

Trait Implementations§

Source§

impl Default for Ctx

Source§

fn default() -> Ctx

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Ctx

§

impl !RefUnwindSafe for Ctx

§

impl Send for Ctx

§

impl Sync for Ctx

§

impl Unpin for Ctx

§

impl UnsafeUnpin for Ctx

§

impl !UnwindSafe for Ctx

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> 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 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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

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

Source§

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