thebyrd / libvmod-example

An example vmod for Varnish

Home Page:http://www.varnish-cache.org/project/modules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vmod_dynamic

Varnish Dynamic Backend Module

Date: 2015-03-03
Version: 1.0
Manual section:3

SYNOPSIS

import dynamic;

DESCRIPTION

Varnish vmod for dynamic backends using subdomain.

FUNCTIONS

backend_hostname

Prototype
backend_hostname(STRING S)
Return value
STRING
Description
Returns "Hello, " prepended to S
Example
set resp.http.hello = dynamic.backend_hostname("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 varnishtest tool.

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

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 instance, 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.

Installation directories

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.

USAGE EXAMPLE

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

import dynamic;

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

COMMON PROBLEMS

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

    Check if PKG_CONFIG_PATH has been set correctly before calling autogen.sh and configure

  • Incompatibilities with different Varnish Cache versions

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

About

An example vmod for Varnish

http://www.varnish-cache.org/project/modules

License:The Unlicense


Languages

Language:Shell 73.2%Language:C 26.8%