diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-11-11 21:11:37 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2014-11-12 00:10:27 +0200 |
commit | 5d91de768f4a5f75f6b663e7d80c94f47e45de23 (patch) | |
tree | 8d07950953625faa8c9852379c071c7ea454b8c9 /README | |
parent | 55e620d377854d7416ee63d8e2d91905e78b421b (diff) | |
download | vmod-dbrw-5d91de768f4a5f75f6b663e7d80c94f47e45de23.tar.gz vmod-dbrw-5d91de768f4a5f75f6b663e7d80c94f47e45de23.tar.bz2 |
Add test suite.
* Makefile.am: Add tests subdir
* configure.ac: Initialize testsuite.
(DBRW_TEST_PARAMS,DBRW_TEST_SERVER)
(DBRW_TEST_NAME,DBRW_TEST_USER)
(DBRW_TEST_PASS,DBRW_TEST_DEBUG): New variables.
* src/Makefile.am (noinst_LTLIBRARIES): New library libsql.la
* src/dbrw.h (dbrw_backend_select): New proto.
* src/be.c: New file.
* src/mysql.c (check_errno): Add default clause.
* src/vmod_dbrw.c (expand_backref): Fix memory deallocation error.
(dbrw_sethdr): New function.
(findmatch): Use dbrw_sethdr to set X-VMOD-DBRW-Status
* tests/.gitignore: New file.
* tests/initdb.c: New file.
* tests/Makefile.am: New file.
* tests/atlocal.in: New file.
* tests/exact01.at: New file.
* tests/initdb.at: New file.
* tests/rewrite01.at: New file.
* tests/rewrite02.at: New file.
* tests/rewrite03.at: New file.
* tests/rewrite04.at: New file.
* tests/rewrite05.at: New file.
* tests/rewrite06.at: New file.
* tests/testsuite.at: New file.
Diffstat (limited to 'README')
-rw-r--r-- | README | 135 |
1 files changed, 76 insertions, 59 deletions
@@ -20,84 +20,101 @@ This version supports MySQL and PostgreSQL databases. The redirection database has the following structure -CREATE TABLE redirects ( - host varchar(255) NOT NULL DEFAULT '', - url varchar(255) NOT NULL DEFAULT '', - dest varchar(255) DEFAULT NULL, - PRIMARY KEY (host,url) -); - -VCL code: - -import dbrw; - -sub vcl_init { - dbrw.config("mysql", "database=dbname;user=varnish;debug=1", - "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); - if (req.http.X-Redirect-To != "") { - error(750, "Redirect"); - } -} - -sub vcl_error { - if (obj.status == 750) { - set obj.http.Location = req.http.X-Redirect-To; - set obj.status = 301; - return (deliver); - } -} + CREATE TABLE redirects ( + host varchar(255) NOT NULL DEFAULT '', + url varchar(255) NOT NULL DEFAULT '', + dest varchar(255) DEFAULT NULL, + PRIMARY KEY (host,url) + ); + +VCL 3.x code: + + import dbrw; + + sub vcl_init { + dbrw.config("mysql", "database=dbname;user=varnish;debug=1", + "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); + if (req.http.X-Redirect-To != "") { + error(750, "Redirect"); + } + } + + sub vcl_error { + if (obj.status == 750) { + set obj.http.Location = req.http.X-Redirect-To; + set obj.status = 301; + return (deliver); + } + } + +VCL 4.0 code: + + import dbrw; + + sub vcl_init { + dbrw.config("mysql", "database=dbname;user=varnish;debug=1", + "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); + if (req.http.X-Redirect-To != "") { + return(synth(301, "Redirect")); + } + } + + sub vcl_synth { + if (resp.status == 301) { + set resp.http.Location = req.http.X-Redirect-To; + return (deliver); + } + } ** More complex case: rewrites Table structure: -CREATE TABLE rewrite ( - host varchar(255) NOT NULL DEFAULT '', - url varchar(255) NOT NULL DEFAULT '', - dest varchar(255) DEFAULT NULL, - value varchar(255) DEFAULT NULL, - pattern varchar(255) DEFAULT NULL, - KEY source (host,url) -) + CREATE TABLE rewrite ( + host varchar(255) NOT NULL DEFAULT '', + url varchar(255) NOT NULL DEFAULT '', + dest varchar(255) DEFAULT NULL, + value varchar(255) DEFAULT NULL, + pattern varchar(255) DEFAULT NULL, + KEY source (host,url) + ) VCL code differs only in definition of the vcl_init: -sub vcl_init { - dbrw.config("mysql", "database=varnish;user=varnish;debug=10", - {"SELECT dest,pattern,value FROM rewrite - WHERE host='$host' and '$url' like url"}); -} + sub vcl_init { + dbrw.config("mysql", "database=varnish;user=varnish;debug=10", + {"SELECT dest,pattern,value FROM rewrite + WHERE host='$host' and '$url' like url"}); + } * Installation In order to compile the package you need to have Varnish source tree. -At least Varnish 3.0.1 is required. Supposing that the varnish source tree -is available under /usr/src/varnish-3.0.1, run: +Both Varnish 3.x and 4.x are supported. Supposing that the Varnish +source tree is available under /usr/src/varnish-3.0.1, run: - ./configure --with-varnish-source=/usr/src/varnish-3.0.1 --with-vmod-dir - -The first option tells configure where Varnish sources reside, the -second one (--with-vmod-dir) instructs it to place created module -files to the standard Varnish module directory. + ./configure --with-varnish-source=/usr/src/varnish-3.0.1 Once configured, do make -This will build the module. After this step you can optionally run -'make test' to test the package. - -Finally, do the following command as root: +This will build the module. Finally, do the following command as root: make install - - + * Bug reporting Send bug reports and suggestions to <gray@gnu.org> @@ -119,6 +136,6 @@ Copyright (C) 2013-2014 Sergey Poznyakoff Local Variables: mode: outline -paragraph-separate: "[ ]*$" +paragraph-separate: "[ ]*$" version-control: never End: |