Date: | 2016-04-05 |
---|---|
Version: | 1.0 |
Manual section: | 3 |
import types;
Implements various object types.
- Prototype
string(STRING s)
- Return value
- OBJECT
- Description
- Creates a new string object with value s.
- Example
new str = types.string("This is a string!");
- Prototype
.value()
- Return value
- STRING
- Description
- Gets the string value.
- Example
new str = types.string("This is a string!"); set resp.http.X-str = str.value();
- Prototype
.length()
- Return value
- INT
- Description
- Gets the string length.
- Example
new str = types.string("This is a string!"); if (str.length() == 17) { //str has a length of 17 }
- Prototype
.set(STRING s)
- Return value
- VOID
- Description
- Sets the string value.
- Example
new str = types.string("This is a string!"); str.set("Here is a new value.");
- Prototype
integer(INT i)
- Return value
- OBJECT
- Description
- Creates a new integer object with value i.
- Example
new i = types.integer(0);
- Prototype
.value()
- Return value
- INT
- Description
- Gets the integer value.
- Example
new i = types.integer(12); set resp.http.X-int = i.value();
- Prototype
.set(INT i)
- Return value
- VOID
- Description
- Sets the integer value.
- Example
new i = types.integer(12); i.set(0);
- Prototype
.increment(INT i)
- Return value
- VOID
- Description
- Increment value by i.
- Example
new i = types.integer(0); i.increment(1);
- Prototype
.increment_get(INT i)
- Return value
- INT
- Description
- Increment value by i and return new value.
- Example
new i = types.integer(0); set resp.http.X-int = i.increment_get(1);
In your VCL you could then use this vmod along the following lines:
import types; sub vcl_init { new s = types.string("Hello!"); new reqs = types.integer(0); } sub vcl_recv { reqs.increment(1); } sub vcl_deliver { set resp.http.s = s.value(); set resp.http.s_len = s.length() + 0; set resp.http.requests = reqs.value(); }
The source tree is based on autotools to configure the building, and
does also have the necessary bits in place to do functional unit tests
using the varnishtest
tool.
Building requires the Varnish header files and uses pkg-config to find the necessary paths.
Pre-requisites:
sudo apt-get install -y autotools-dev make automake libtool pkg-config libvarnishapi1 libvarnishapi-dev
Usage:
./autogen.sh ./configure
If you have installed Varnish to a non-standard directory, call
autogen.sh
and configure
with PKG_CONFIG_PATH
pointing to
the appropriate path. For types, when varnishd configure was called
with --prefix=$PREFIX
, use
PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig export PKG_CONFIG_PATH
Make targets:
- make - builds the vmod.
- make install - installs your vmod.
- make check - runs the unit tests in
src/tests/*.vtc
- make distcheck - run check and prepare a tarball of the vmod.
By default, the vmod configure
script installs the built vmod in
the same directory as Varnish, determined via pkg-config(1)
. The
vmod installation directory can be overridden by passing the
VMOD_DIR
variable to configure
.
Other files like man-pages and documentation are installed in the
locations determined by configure
, which inherits its default
--prefix
setting from Varnish.