summaryrefslogtreecommitdiffabout
path: root/src/vmod_dbrw.vcc
blob: 9a15af150fa31076ed98a2bb615e470fa4a6fae9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# This file is part of vmod-dbrw
# Copyright (C) 2013-2016 Sergey Poznyakoff
#
# Vmod-dbrw is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# Vmod-dbrw is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with vmod-dbrw.  If not, see <http://www.gnu.org/licenses/>.

$Module dbrw 3 Database-driven rewrite rules for Varnish Cache

COLOPHON
========
This document provides a short description of the **vmod-dbrw** module.
For a detailed documentation, please see the vmod-dbrw texinfo document
or vmod-dbrw(3) manual page.  If **vmod-dbrw** is properly installed on
your system, running **info vmod-dbrw** will bring you complete
documentation.

You will find documentation sources in **vmod-dbrw** source tree,
subdirectory **doc**.

DESCRIPTION
===========

This module for Varnish Cache implements database-driven rewrite rules.
These rules may be similar to *RewriteRule* directives implemented by
**mod_rewrite** module in Apache or to *Redirect* directives of its
**mod_alias** module.  What distinguishes the **vmod-dbrw** rules from
these, is that they are handled by Varnish, before the request reaches the
httpd server, and that they are stored in an SQL database, which makes
them easily manageable.

$Event dbrw_event
$Function VOID config(PRIV_TASK, STRING, STRING, STRING)

Description
    Configures the module and provides it with the data
    necessary to connect and use the database.  It is normally called
    from the **vcl_recv** subroutine.

Example
    ::
	
      dbrw.config("mysql",
                  "database=rewrite;user=varnish;password=guessme",
                  {"SELECT dest
                      FROM redirects
                     WHERE host='$host'
                       AND url='$url'"});


$Function STRING rewrite(PRIV_TASK, STRING)

Description
     Rewrites its argument using the database configured in the previous
     call to **config** and returns the obtained value.

Example
     ::
     
       set req.http.X-Redirect-To =
             dbrw.rewrite("host=" + req.http.Host + ";" +
                          "url=" + req.url);

SEE ALSO
========

* vcl(7)
* varnishd(1)
	

Return to:

Send suggestions and report system problems to the System administrator.