diff options
-rw-r--r-- | NEWS | 17 | ||||
-rw-r--r-- | README | 39 | ||||
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | doc/vmod-dbrw.3 | 105 | ||||
-rw-r--r-- | doc/vmod-dbrw.texi | 62 | ||||
-rw-r--r-- | src/vmod_dbrw.c | 2 | ||||
-rw-r--r-- | tests/Makefile.am | 2 |
7 files changed, 39 insertions, 190 deletions
@@ -1,18 +1,17 @@ -vmod-dbrw -- history of user-visible changes. 2016-01-24 -Copyright (C) 2013-2016 Sergey Poznyakoff +vmod-dbrw -- history of user-visible changes. 2017-08-05 +Copyright (C) 2013-2017 Sergey Poznyakoff See the end of file for copying conditions. Please send vmod-dbrw bug reports to <gray@gnu.org> -Version 2.0.90-4.1.0, (Git) +Version 2.0.92, (Git) -* Support for Varnish 4.1 +* Requires Varnish 4.1 -* Versioning changes - -Starting with this release, the version number includes version -of Varnish API the release was designed for. +* The --with-varnish-source option has been withdrawn +The configure script relies on pkg-config to determine the location of +Varnish header files and libraries. Version 2.0, 2014-11-13 @@ -27,7 +26,7 @@ Initial release ========================================================================= Copyright information: -Copyright (C) 2013-2016 Sergey Poznyakoff +Copyright (C) 2013-2017 Sergey Poznyakoff Permission is granted to anyone to make or distribute verbatim copies of this document as received, in any medium, provided that the @@ -46,30 +46,7 @@ The redirection database has the following structure PRIMARY KEY (host,url) ); -VCL 3.x code: - - import dbrw; - - sub vcl_recv { - dbrw.config("mysql", "database=dbname;user=varnish;debug=1", - "SELECT dest FROM redirects WHERE host='$host' AND url='$url'"); - 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: +The VCL code: import dbrw; @@ -116,6 +93,19 @@ The VCL code differs only in the call to dbrw.config in vcl_recv: In order to compile the package you need to have installed varnishd and varnishapi package. +<<<<<<< HEAD + +Supposing that condition is met, run: + + ./configure + +It should be able to automatically find the necessary components. In case +it doesn't, tweak the configuration variables as necessary. The most +important one is PKG_CONFIG_PATH, which contains a path (in the UNIX sense) +where the .pc files are located. It should contain a directory where the +'varnishapi.pc' file lives. Example usage: + +======= Supposing that condition is met, run: @@ -127,6 +117,7 @@ important one is PKG_CONFIG_PATH, which contains a path (in the UNIX sense) where the .pc files are located. It should contain a directory where the 'varnishapi.pc' file lives. Example usage: +>>>>>>> e0e3166a8bbe666414c2f0ee9c732f6254acf550 ./configure PKG_CONFIG_PATH=/usr/local/varnish/lib/pkgconfig:$PKG_CONFIG_PATH Please read the file INSTALL for a detailed discussion of available variables diff --git a/configure.ac b/configure.ac index bdb9df5..681d471 100644 --- a/configure.ac +++ b/configure.ac @@ -42,7 +42,7 @@ AC_PROG_MAKE_SET AC_HEADER_STDC AC_CHECK_HEADERS([sys/stdlib.h]) -AM_VARNISHAPI +AM_VARNISHAPI([4.1]) ########### # Check for SQL support diff --git a/doc/vmod-dbrw.3 b/doc/vmod-dbrw.3 index 8c89cc4..139fbab 100644 --- a/doc/vmod-dbrw.3 +++ b/doc/vmod-dbrw.3 @@ -1,5 +1,5 @@ .\" This file is part of Vmod-dbrw -*- nroff -*- -.\" Copyright (C) 2013-2014 Sergey Poznyakoff +.\" Copyright (C) 2013-2017 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 @@ -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 "April 21, 2016" "VMOD-DBRW" "User Reference" +.TH VMOD-DBRW 1 "August 5, 2017" "VMOD-DBRW" "User Reference" .SH NAME vmod-dbrw \- Database-driven rewrite rules for Varnish Cache .SH SYNOPSIS @@ -188,7 +188,7 @@ CREATE TABLE redirects ( ); .EE .PP -VCL 3.0 code: +The VCL code: .PP .EX sub vcl_recv { @@ -201,38 +201,6 @@ sub vcl_recv { 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); - } -} -.EE -.PP -Notice the use of concatenation to build the argument to -\fBdbrw.rewrite\fR. -.PP -The following is the same code for VCL 4.0: -.PP -.EX -sub vcl_init { - 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); - if (req.http.X-Redirect-To != "") { return(synth(301, "Redirect")); } } @@ -260,50 +228,15 @@ CREATE TABLE rewrite ( ) .EE .PP -VCL 3.0 code: +The VCL: .PP .EX -import std; -import dbrw; - -sub vcl_init { +sub vcl_recv { # It is supposed that the url column contains an SQL-style # wildcard pattern. dbrw.config("mysql", "database=varnish;user=varnish;debug=10", {"SELECT dest,pattern,value,flags FROM rewrite WHERE host='$host' and '$url' like 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"); - } -} -.EE -.PP -The \fBvcl_error\fR function uses the \fBX\-VMOD\-DBRW\-Status\fR -header, which may be set by \fBredirect=\fR flag in the -\fBflags\fR column. Its value is converted to integer using the -\fBinteger\fR function from the \fBstd\fR module. If the header is -not set, permanent redirect is assumed: -.PP -.EX -sub vcl_error { - if (obj.status == 750) { - set obj.http.Location = req.http.X-Redirect-To; - set obj.status = std.integer(req.http.X-VMOD-DBRW-Status, 301); - return (deliver); - } -} -.EE -.PP -For VCL 4.0, \fBvcl_synth\fR is used instead of \fBvcl_error\fR: -.PP -.EX -sub vcl_recv { set req.http.X-Redirect-To = dbrw.rewrite("host=" + req.http.Host + ";" + "url=" + req.url); @@ -320,34 +253,6 @@ sub vcl_synth { } } .EE -.SS Use of vmod-dbrw and vmod-redirect -.PP -.ie "\*[.T]"html" \{\ -For VCL 3.0 you can use the -.URL https://www.varnish-cache.org/vmod/redirect \fBvmod-redirect\fR " module" -\} -.el \{\ -For VCL 3.0 you can use the \fBvmod-redirect\fR module -.BR ( https://www.varnish-cache.org/vmod/redirect ) -\} -and get rid of the \fBvcl_error\fR subroutine: -.PP -.EX -import std; -import dbrw; -import redirect; - -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(redirect.location( - std.integer(req.http.X-VMOD-DBRW-Status, 301), - req.http.X-Redirect-To), "Redirection"); - } -} -.EE .\" The MANCGI variable is set by man.cgi script on Ulysses. .\" The download.inc file contains the default DOWNLOAD section .\" for man-based doc pages. diff --git a/doc/vmod-dbrw.texi b/doc/vmod-dbrw.texi index c0dbbea..82adda2 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-2016 Sergey Poznyakoff +Copyright @copyright{} 2013-2017 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 @@ -545,11 +545,17 @@ caller. @cindex vcl_recv Assuming the database structure similar to the one discussed in the previous chapter, the following example illustrates how to use -@code{rewrite} to redirect the incoming request. It assumes VCL 4.0: +@code{rewrite} to redirect the incoming request. @example @group sub vcl_recv @{ + dbrw.config("mysql", + "database=rewrite;user=varnish;password=guessme", + @{"SELECT dest + FROM redirects + WHERE host='$host' + AND url='$url'"@}); set req.http.X-Redirect-To = dbrw.rewrite("host=" + req.http.Host + ";" + "url=" + req.url); @@ -587,58 +593,6 @@ The @code{X-VMOD-DBRW-Status} header, if set, contains the status code to be returned to the client (@pxref{X-VMOD-DBRW-Status}). Notice the use of the @command{vmod_std} module to cast it to integer. -The example below shows the same code for VCL 3.0: - -@example -@group -import std; - -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 = - std.integer(req.http.X-VMOD-DBRW-Status, 301); - return (deliver); - @} -@} -@end group -@end example - -@cindex vmod_redirect -For VCL 3.0, you can use @command{libvmod_redirect} to simplify the -code: - -@example -@group -import std; -import dbrw; -import redirect; - -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(redirect.location( - std.integer(req.http.X-VMOD-DBRW-Status, 301), - req.http.X-Redirect-To), "Redirection"); - @} -@} -@end group -@end example - -@noindent -The @code{vcl_error} subroutine is not needed in this case. - @node Reporting Bugs @chapter How to Report a Bug diff --git a/src/vmod_dbrw.c b/src/vmod_dbrw.c index 9a0f2c3..9e6af1e 100644 --- a/src/vmod_dbrw.c +++ b/src/vmod_dbrw.c @@ -1,5 +1,5 @@ /* This file is part of vmod-dbrw - Copyright (C) 2013-2014 Sergey Poznyakoff + Copyright (C) 2013-2017 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 diff --git a/tests/Makefile.am b/tests/Makefile.am index 7d1b99d..0da98e8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,5 +1,5 @@ # This file is part of vmod-dbrw -# Copyright (C) 2013-2014, 2016 Sergey Poznyakoff +# Copyright (C) 2013-2017 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 |