Outdated starting point for vmod development for Vinyl Cache - VCDK should be used instead: https://git.sr.ht/~dridi/vcdk
  • M4 82.6%
  • Shell 9%
  • C 5.8%
  • Makefile 2.6%
slink dc4003f3d8 Update README.md
Improve markdown
2026-02-16 18:53:38 +01:00
.circleci add circleci integration 2020-11-09 14:10:16 -08:00
m4 rm m4/PLACEHOLDER 2016-12-08 19:23:28 +01:00
src WS_Reserve is now deprecated 2020-11-09 14:10:16 -08:00
.gitignore Use the new autoconf macros 2016-09-19 17:05:19 +02:00
.travis.yml fix travis. and update dist from trusty to xenial 2019-03-18 09:42:37 +01:00
autogen.sh emit the right error also for older pkg-config versions which don't 2015-05-24 12:35:47 +02:00
CHANGES.rst Add example of change log. 2015-12-01 13:29:04 +01:00
configure.ac Moved 2026-02-16 18:44:22 +01:00
COPYING Clear up copyright statements. 2015-03-16 15:38:34 +01:00
LICENSE Change license to public domain. 2015-03-03 16:16:08 +01:00
Makefile.am Moved 2026-02-16 18:44:22 +01:00
README.md Update README.md 2026-02-16 18:53:38 +01:00
rename-vmod-script clean test changes 2020-11-18 11:32:44 -08:00

vmod-example

NOTE

For new developments, we recommend to consider using https://git.sr.ht/~dridi/vcdk

SYNOPSIS

import example;

DESCRIPTION

Example Vinyl Cache vmod demonstrating how to write an out-of-tree vmod.

Implements the traditional Hello World as a vmod.

FUNCTIONS

hello

Prototype

hello(STRING S)

Return value: STRING

Description

Returns "Hello, " prepended to S

Example

set resp.http.hello = example.hello("World");

INSTALLATION

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 vinyltest tool.

Building requires the Vinyl Cache header files and uses pkg-config to find the necessary paths.

Usage:

 ./autogen.sh
 ./configure

If you have installed Vinyl Cache to a non-standard directory, call autogen.sh and configure with PKG_CONFIG_PATH pointing to the appropriate path. For instance, when vinyld configure was called with --prefix=$PREFIX, use

 export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig
 export ACLOCAL_PATH=${PREFIX}/share/aclocal

The module will inherit its prefix from Vinyl Cache, unless you specify a different --prefix when running the configure script for this module.

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.

If you build a dist tarball, you don't need any of the autotools or pkg-config. You can build the module simply by running::

 ./configure
 make

Installation directories

By default, the vmod configure script installs the built vmod in the directory relevant to the prefix. The vmod installation directory can be overridden by passing the vmoddir variable to make install.

USAGE

In your VCL you could then use this vmod along the following lines::

        import example;

        sub vcl_deliver {
                # This sets resp.http.hello to "Hello, World"
                set resp.http.hello = example.hello("World");
        }

COMMON PROBLEMS

  • configure: error: Need vinyl.m4 -- see README.rst

    Check whether PKG_CONFIG_PATH and ACLOCAL_PATH were set correctly before calling autogen.sh and configure

  • Incompatibilities with different Vinyl Cache / Varnish Cache versions

    Make sure you build this vmod against its correspondent version. For instance, to build against Varnish Cache 4.1, this vmod must be built from branch 4.1.

START YOUR OWN VMOD

The basic steps to start a new vmod from this example are::

  name=myvmod
  git clone libvmod-example libvmod-$name
  cd libvmod-$name
  ./rename-vmod-script $name

and follow the instructions output by rename-vmod-script