diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-04-21 16:23:35 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-04-21 16:47:22 +0300 |
commit | b5f2337ad45d26941bf533741d8bff1238d59b5d (patch) | |
tree | 878a65c333272ceb198ec0d8e871e431f8015f7a /doc | |
parent | 5ee1409fc878cd65dd224ec5f709507e37e9ed5d (diff) | |
download | vmod-dbrw-b5f2337ad45d26941bf533741d8bff1238d59b5d.tar.gz vmod-dbrw-b5f2337ad45d26941bf533741d8bff1238d59b5d.tar.bz2 |
Rewrite SQL configuration support.
Multiple configurations can be provided, by calling dbrw.config from
branches of a conditional VCL statement. The only requirement is that
exactly one dbrw.config is executed within a single HTTP session. This
allows the user to select rewrite data from various databases depending
on some conditions.
Open SQL connections are stored in a pool and reused as needed. So far
no limit on the number of connections is imposed. This is a TODO.
Connections remain open during the lifetime of the module (i.e. for as
long as varnish is not restarted).
* src/dbrw.h (dbrw_config): New members: param_str, magic and list.
(dbrw_connection): New members: magic, busy, list.
* src/vmod_dbrw.c (dbrw_connection_get)
(dbrw_connection_release): New functions.
(dbrw_event): Install atexit function.
(vmod_config): Keep a pool of configurations.
(dbrw_sethdr) [VARNISHVERSION]: Remove leftover code.
(vmod_rewrite): Rewrite.
* src/vmod_dbrw.vcc (config, rewrite): Mark as PRIV_TASK.
* doc/vmod-dbrw.3: Update docs.
* doc/vmod-dbrw.texi: Update docs.
* configure.ac: Raise version number
Diffstat (limited to 'doc')
-rw-r--r-- | doc/vmod-dbrw.3 | 12 | ||||
-rw-r--r-- | doc/vmod-dbrw.texi | 12 |
2 files changed, 10 insertions, 14 deletions
diff --git a/doc/vmod-dbrw.3 b/doc/vmod-dbrw.3 index f2ee5fe..8c89cc4 100644 --- a/doc/vmod-dbrw.3 +++ b/doc/vmod-dbrw.3 @@ -13,7 +13,7 @@ .\" .\" You should have received a copy of the GNU General Public License .\" along with vmod-dbrw. If not, see <http://www.gnu.org/licenses/>. -.TH VMOD-DBRW 1 "November 12, 2014" "VMOD-DBRW" "User Reference" +.TH VMOD-DBRW 1 "April 21, 2016" "VMOD-DBRW" "User Reference" .SH NAME vmod-dbrw \- Database-driven rewrite rules for Varnish Cache .SH SYNOPSIS @@ -28,8 +28,9 @@ is a Varnish Cache module implementing database-driven rewrite procedures. Its intended use is for web sites that need an exceedingly big number of redirect and/or rewrite rules. .PP -The \fBconfig\fR function should be called upon startup, in \fBsub -vcl_init\fR. It configures the module and supplies it the information +The \fBdbrw.config\fR function should be called exactly once per HTTP session, +before calling \fBdbrw.rewrite\fR (normally it is done from +\fBvcl_recv\fR). It configures the module and supplies it the information necessary for accessing the database and interpreting the data obtained from it. .PP @@ -190,15 +191,12 @@ CREATE TABLE redirects ( VCL 3.0 code: .PP .EX -sub vcl_init { +sub vcl_recv { dbrw.config("mysql", "database=dbname;user=varnish", {"SELECT dest FROM redirects WHERE host='$host' AND url='$url'"}); -} - -sub vcl_recv { set req.http.X-Redirect-To = dbrw.rewrite("host=" + req.http.Host + ";" + "url=" + req.url); diff --git a/doc/vmod-dbrw.texi b/doc/vmod-dbrw.texi index 344b940..c0dbbea 100644 --- a/doc/vmod-dbrw.texi +++ b/doc/vmod-dbrw.texi @@ -30,7 +30,7 @@ Published by the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -Copyright @copyright{} 2013-2014 Sergey Poznyakoff +Copyright @copyright{} 2013-2016 Sergey Poznyakoff Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -103,8 +103,6 @@ manageable. Some web sites implement thousands of rewrite rules. The purpose of this module is to facilitate deploying and handling them. -The module can be compiled for VCL 3.0 or 4.0. - @node Overview @chapter Overview @cindex rewrite rules @@ -115,7 +113,7 @@ Rewrite rules are stored in a MySQL or PostgreSQL database. The schema. It only needs to know the SQL query which is to be used to retrieve data. This query is supplied to the module, along with the credentials for accessing the database, by calling the @code{config} -function in the @code{vcl_init} subroutine of the Varnish +function in the @code{vcl_recv} subroutine of the Varnish configuration file. Once the module is configured, the @code{rewrite} function can be called @@ -220,12 +218,12 @@ If @var{flags} is NULL, it is ignored. @deftypefn {function} void config (string @var{dbtype}, string @var{params}, @ string @var{query}) -@cindex vcl_init +@cindex vcl_recv @cindex configuration @cindex initialization This function configures the module and provides it with the data necessary to connect and use the database. It is normally called from the -@code{vcl_init} subroutine. +@code{vcl_recv} subroutine. Arguments: @@ -345,7 +343,7 @@ The example below configures @command{vmod-dbrw} to use MySQL database @group import dbrw; -sub vcl_init @{ +sub vcl_recv @{ dbrw.config("mysql", "database=rewrite;user=varnish;password=guessme", @{"SELECT dest |