pub struct Ctx<'a> {
pub raw: &'a mut vrt_ctx,
pub http_req: Option<HttpHeaders<'a>>,
pub http_req_top: Option<HttpHeaders<'a>>,
pub http_resp: Option<HttpHeaders<'a>>,
pub http_bereq: Option<HttpHeaders<'a>>,
pub http_beresp: Option<HttpHeaders<'a>>,
pub ws: Workspace<'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;
fn foo(ctx: &Ctx) {
if let Some(ref req) = ctx.http_req {
for (name, value) in req {
println!("header {name} has value {value:?}");
}
}
}Fields§
§raw: &'a mut vrt_ctx§http_req: Option<HttpHeaders<'a>>§http_req_top: Option<HttpHeaders<'a>>§http_resp: Option<HttpHeaders<'a>>§http_bereq: Option<HttpHeaders<'a>>§http_beresp: Option<HttpHeaders<'a>>§ws: Workspace<'a>Implementations§
Source§impl<'a> Ctx<'a>
impl<'a> Ctx<'a>
Sourcepub unsafe fn from_ptr(ptr: *const vrt_ctx) -> Self
pub unsafe fn from_ptr(ptr: *const vrt_ctx) -> Self
Wrap a raw pointer into an object we can use.
The pointer must be non-null, and the magic must match
Sourcepub fn from_ref(raw: &'a mut vrt_ctx) -> Self
pub fn from_ref(raw: &'a mut vrt_ctx) -> Self
Instantiate from a mutable reference to a vrt_ctx.
Sourcepub fn fail(&mut self, msg: impl Into<VclError>)
pub fn fail(&mut self, msg: impl Into<VclError>)
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.
Sourcepub fn log(&mut self, tag: LogTag, msg: impl AsRef<str>)
pub fn log(&mut self, tag: LogTag, msg: impl AsRef<str>)
Log a message, attached to the current context