Skip to content

Latest commit

 

History

History
99 lines (72 loc) · 2.26 KB

README.rst

File metadata and controls

99 lines (72 loc) · 2.26 KB

vmod_access

Varnish Example Module

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

SYNOPSIS

import access;

DESCRIPTION

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

Implements the traditional Hello World as a vmod.

FUNCTIONS

check

Prototype
check(STRING service, STRING cookie_name, STRING salt)
Return value
BOOL
Description
Returns true if a request with a valid cookie is sent, false otherwise.
Example
if (req.url ~ "^/protected/")
{
        if (access.check("protected_content", "__access", "salt used for checksum"))
        {
                // access granted
        }
        else
        {
                // access denied
        }
}

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

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

import access;

sub vcl_deliver {
        # This sets resp.http.hello to "Hello, World"
        set resp.http.hello = access.hello("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