Struct varnish::vcl::ctx::Ctx

source ·
pub struct Ctx<'a> {
    pub raw: &'a mut vrt_ctx,
    pub http_req: Option<HTTP<'a>>,
    pub http_req_top: Option<HTTP<'a>>,
    pub http_resp: Option<HTTP<'a>>,
    pub http_bereq: Option<HTTP<'a>>,
    pub http_beresp: Option<HTTP<'a>>,
    pub ws: WS<'a>,
}
Expand description

VCL context

A mutable reference to this structure is always passed to vmod functions and provides access to the available HTTP objects, as well as the workspace.

This struct is a pure Rust structure, mirroring some of the C fields, so you should always use the provided methods to interact with them. If they are not enough, the raw field is actually the C original pointer that can be used to directly, and unsafely, act on the structure.

Which http_* are present will depend on which VCL sub routine the function is called from.

use varnish::vcl::ctx::Ctx;

fn foo(ctx: &Ctx) {
    if let Some(ref req) = ctx.http_req {
        for (name, value) in req {
            println!("header {} has value {}", name, value);
        }
    }
}

Fields§

§raw: &'a mut vrt_ctx§http_req: Option<HTTP<'a>>§http_req_top: Option<HTTP<'a>>§http_resp: Option<HTTP<'a>>§http_bereq: Option<HTTP<'a>>§http_beresp: Option<HTTP<'a>>§ws: WS<'a>

Implementations§

source§

impl<'a> Ctx<'a>

source

pub fn new(raw: *mut vrt_ctx) -> Self

Wrap a raw pointer into an object we can use.

The pointer must be non-null, and the magic must match

source

pub fn fail(&mut self, msg: &str) -> u8

Log an error message and fail the current VSL task.

Once the control goes back to Varnish, it will see that the transaction was marked as fail and will return a synthetic error to the client.

source

pub fn log(&mut self, logtag: LogTag, msg: &str)

Log a message, attached to the current context

source

pub fn cached_req_body(&mut self) -> Result<Vec<&'a [u8]>, Error>

Auto Trait Implementations§

§

impl<'a> Freeze for Ctx<'a>

§

impl<'a> RefUnwindSafe for Ctx<'a>

§

impl<'a> !Send for Ctx<'a>

§

impl<'a> !Sync for Ctx<'a>

§

impl<'a> Unpin for Ctx<'a>

§

impl<'a> !UnwindSafe for Ctx<'a>

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, 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, U> TryFrom<U> for T
where 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 T
where 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.