aboutsummaryrefslogtreecommitdiff
path: root/README
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2014-11-11 21:11:37 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2014-11-12 00:10:27 +0200
commit5d91de768f4a5f75f6b663e7d80c94f47e45de23 (patch)
tree8d07950953625faa8c9852379c071c7ea454b8c9 /README
parent55e620d377854d7416ee63d8e2d91905e78b421b (diff)
downloadvmod-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--README135
1 files changed, 76 insertions, 59 deletions
diff --git a/README b/README
index f730269..4c22ea4 100644
--- a/README
+++ b/README
@@ -20,84 +20,101 @@ This version supports MySQL and PostgreSQL databases.
20 20
21The redirection database has the following structure 21The redirection database has the following structure
22 22
23CREATE TABLE redirects ( 23 CREATE TABLE redirects (
24 host varchar(255) NOT NULL DEFAULT '', 24 host varchar(255) NOT NULL DEFAULT '',
25 url varchar(255) NOT NULL DEFAULT '', 25 url varchar(255) NOT NULL DEFAULT '',
26 dest varchar(255) DEFAULT NULL, 26 dest varchar(255) DEFAULT NULL,
27 PRIMARY KEY (host,url) 27 PRIMARY KEY (host,url)
28); 28 );
29 29
30VCL code: 30VCL 3.x code:
31 31
32import dbrw; 32 import dbrw;
33 33
34sub vcl_init { 34 sub vcl_init {
35 dbrw.config("mysql", "database=dbname;user=varnish;debug=1", 35 dbrw.config("mysql", "database=dbname;user=varnish;debug=1",
36 "SELECT dest FROM redirects WHERE host='$host' AND url='$url'"); 36 "SELECT dest FROM redirects WHERE host='$host' AND url='$url'");
37} 37 }
38 38
39sub vcl_recv { 39 sub vcl_recv {
40 set req.http.X-Redirect-To = 40 set req.http.X-Redirect-To =
41 dbrw.rewrite("host=" + req.http.Host + ";" + 41 dbrw.rewrite("host=" + req.http.Host + ";" +
42 "url=" + req.url); 42 "url=" + req.url);
43 if (req.http.X-Redirect-To != "") { 43 if (req.http.X-Redirect-To != "") {
44 error(750, "Redirect"); 44 error(750, "Redirect");
45 } 45 }
46} 46 }
47 47
48sub vcl_error { 48 sub vcl_error {
49 if (obj.status == 750) { 49 if (obj.status == 750) {
50 set obj.http.Location = req.http.X-Redirect-To; 50 set obj.http.Location = req.http.X-Redirect-To;
51 set obj.status = 301; 51 set obj.status = 301;
52 return (deliver); 52 return (deliver);
53 } 53 }
54} 54 }
55
56VCL 4.0 code:
57
58 import dbrw;
59
60 sub vcl_init {
61 dbrw.config("mysql", "database=dbname;user=varnish;debug=1",
62 "SELECT dest FROM redirects WHERE host='$host' AND url='$url'");
63 }
64
65 sub vcl_recv {
66 set req.http.X-Redirect-To =
67 dbrw.rewrite("host=" + req.http.Host + ";" +
68 "url=" + req.url);
69 if (req.http.X-Redirect-To != "") {
70 return(synth(301, "Redirect"));
71 }
72 }
73
74 sub vcl_synth {
75 if (resp.status == 301) {
76 set resp.http.Location = req.http.X-Redirect-To;
77 return (deliver);
78 }
79 }
55 80
56** More complex case: rewrites 81** More complex case: rewrites
57 82
58Table structure: 83Table structure:
59 84
60CREATE TABLE rewrite ( 85 CREATE TABLE rewrite (
61 host varchar(255) NOT NULL DEFAULT '', 86 host varchar(255) NOT NULL DEFAULT '',
62 url varchar(255) NOT NULL DEFAULT '', 87 url varchar(255) NOT NULL DEFAULT '',
63 dest varchar(255) DEFAULT NULL, 88 dest varchar(255) DEFAULT NULL,
64 value varchar(255) DEFAULT NULL, 89 value varchar(255) DEFAULT NULL,
65 pattern varchar(255) DEFAULT NULL, 90 pattern varchar(255) DEFAULT NULL,
66 KEY source (host,url) 91 KEY source (host,url)
67) 92 )
68 93
69VCL code differs only in definition of the vcl_init: 94VCL code differs only in definition of the vcl_init:
70 95
71sub vcl_init { 96 sub vcl_init {
72 dbrw.config("mysql", "database=varnish;user=varnish;debug=10", 97 dbrw.config("mysql", "database=varnish;user=varnish;debug=10",
73 {"SELECT dest,pattern,value FROM rewrite 98 {"SELECT dest,pattern,value FROM rewrite
74 WHERE host='$host' and '$url' like url"}); 99 WHERE host='$host' and '$url' like url"});
75} 100 }
76 101
77* Installation 102* Installation
78 103
79In order to compile the package you need to have Varnish source tree. 104In order to compile the package you need to have Varnish source tree.
80At least Varnish 3.0.1 is required. Supposing that the varnish source tree 105Both Varnish 3.x and 4.x are supported. Supposing that the Varnish
81is available under /usr/src/varnish-3.0.1, run: 106source tree is available under /usr/src/varnish-3.0.1, run:
82 107
83 ./configure --with-varnish-source=/usr/src/varnish-3.0.1 --with-vmod-dir 108 ./configure --with-varnish-source=/usr/src/varnish-3.0.1
84
85The first option tells configure where Varnish sources reside, the
86second one (--with-vmod-dir) instructs it to place created module
87files to the standard Varnish module directory.
88 109
89Once configured, do 110Once configured, do
90 111
91 make 112 make
92 113
93This will build the module. After this step you can optionally run 114This will build the module. Finally, do the following command as root:
94'make test' to test the package.
95
96Finally, do the following command as root:
97 115
98 make install 116 make install
99 117
100
101* Bug reporting 118* Bug reporting
102 119
103Send bug reports and suggestions to <gray@gnu.org> 120Send bug reports and suggestions to <gray@gnu.org>
@@ -119,6 +136,6 @@ Copyright (C) 2013-2014 Sergey Poznyakoff
119 136
120Local Variables: 137Local Variables:
121mode: outline 138mode: outline
122paragraph-separate: "[ ]*$" 139paragraph-separate: "[ ]*$"
123version-control: never 140version-control: never
124End: 141End:

Return to:

Send suggestions and report system problems to the System administrator.