GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
VMOD_VAR(3) VMOD_VAR(3)

vmod_var - Variable support for Varnish VCL

import var [from "path"] ;
This VMOD implements basic variable support in VCL.
It supports strings, integers and real numbers. There are methods to get and set each data type.
Global variables have a lifespan that extends across requests and VCLs, for as long as the vmod is loaded.
The remaining functions have PRIV_TASK lifespan and are local to a single request or backend request.
Example:
vcl 4.0;
import var;
backend default { .host = "192.0.2.11"; .port = "8080"; }
sub vcl_recv { # Set and get some values. var.set("foo", "bar"); set req.http.x-foo = var.get("foo");
var.set_int("ten", 10); var.set_int("five", 5); set req.http.twenty = var.get_int("ten") + var.get_int("five") + 5;
# VCL will use the first token to decide final data type. Headers are strings. # set req.http.X-lifetime = var.get_int("ten") + " seconds"; # Won't work. set req.http.X-lifetime = "" + var.get_int("ten") + " seconds"; # Works!
var.set_duration("timedelta", 1m); # 60s set req.http.d1 = var.get_duration("timedelta");
var.set_ip("endpoint", client.ip); set req.http.x-client = var.get_ip("endpoint");
# Unset all non-global variables. var.clear();
# Demonstrate use of global variables as state flags. if (req.url ~ "/close$") { var.global_set("open", "no"); } else if (req.url ~ "/open$") { var.global_set("open", "yes"); }
if (var.global_get("open") != "yes") { return (synth(200, "We are currently closed, sorry!")); } }


VOID clear(PRIV_TASK)
STRING get(PRIV_TASK, STRING)
DURATION get_duration(PRIV_TASK, STRING)
INT get_int(PRIV_TASK, STRING)
IP get_ip(PRIV_TASK, STRING)
REAL get_real(PRIV_TASK, STRING)
STRING get_string(PRIV_TASK, STRING)
STRING global_get(STRING)
VOID global_set(STRING, STRING)
VOID set(PRIV_TASK, STRING, STRING)
VOID set_duration(PRIV_TASK, STRING, DURATION)
VOID set_int(PRIV_TASK, STRING, INT)
VOID set_ip(PRIV_TASK, STRING, IP)
VOID set_real(PRIV_TASK, STRING, REAL)
VOID set_string(PRIV_TASK, STRING, STRING)

Prototype
VOID set(PRIV_TASK, STRING key, STRING value)

Set key to value.

Prototype
STRING get(PRIV_TASK, STRING)

Get key with data type STRING. If stored key is not a STRING an empty string is returned.

Prototype
VOID global_set(STRING, STRING)

Prototype
STRING global_get(STRING)

Prototype
VOID set_int(PRIV_TASK, STRING key, INT value)

Set key to value.

Prototype
INT get_int(PRIV_TASK, STRING key)

Get key with data type INT. If stored key is not an INT zero will be returned.

Prototype
VOID set_string(PRIV_TASK, STRING key, STRING value)

Identical to set().

Prototype
STRING get_string(PRIV_TASK, STRING key)

Identical to get().

Prototype
VOID set_real(PRIV_TASK, STRING key, REAL value)

Set key to value.

Prototype
REAL get_real(PRIV_TASK, STRING key)

Get key with data type REAL. If stored key is not a REAL zero will be returned.

Prototype
VOID set_duration(PRIV_TASK, STRING key, DURATION value)

Set key to value.

Prototype
DURATION get_duration(PRIV_TASK, STRING key)

Get key with data type DURATION. If stored key is not a DURATION zero will be returned.

Prototype
VOID set_ip(PRIV_TASK, STRING key, IP value)

Set key to value.

Prototype
IP get_ip(PRIV_TASK, STRING key)

Get key with data type IP. If stored key is not an IP null will be returned.

Prototype
VOID clear(PRIV_TASK)

Clear all non-global variables.

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.