r3724 - in branches/2.0/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl
tfheen at projects.linpro.no
tfheen at projects.linpro.no
Tue Feb 10 15:58:18 CET 2009
Author: tfheen
Date: 2009-02-10 15:58:17 +0100 (Tue, 10 Feb 2009)
New Revision: 3724
Added:
branches/2.0/varnish-cache/bin/varnishtest/tests/c00022.vtc
Modified:
branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c
branches/2.0/varnish-cache/include/vrt.h
branches/2.0/varnish-cache/lib/libvcl/vcc_action.c
branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c
Log:
Merge r3542:
Implement the new-purge case where the entire expression comes
from VCL.
It is possible to instigate purges two ways from VCL now:
sub vcl_recv {
# Purge the req.url
if (req.request == "PURGE") {
purge (req.url == req.url);
error 410;
}
# Take entire purge instruction from "Purge:" header
if (req.request == "PURGESTR") {
purge ("" req.http.purge);
error 410;
}
Testcase for this.
Modified: branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-10 14:50:53 UTC (rev 3723)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_vrt.c 2009-02-10 14:58:17 UTC (rev 3724)
@@ -788,11 +788,61 @@
good = 1;
}
if (!good)
+ /* XXX: report error how ? */
BAN_Free(b);
else
BAN_Insert(b);
}
+/*--------------------------------------------------------------------*/
+
+void
+VRT_purge_string(struct sess *sp, char *str, ...)
+{
+ char *p, *a1, *a2, *a3;
+ char **av;
+ va_list ap;
+ struct ban *b;
+ int good;
+ int i;
+
+ va_start(ap, str);
+ p = vrt_assemble_string(sp->http, NULL, str, ap);
+ if (p == NULL)
+ /* XXX: report error how ? */
+ return;
+
+ av = ParseArgv(p, 0);
+ if (av[0] != NULL) {
+ /* XXX: report error how ? */
+ FreeArgv(av);
+ return;
+ }
+ b = BAN_New();
+ good = 0;
+ for (i = 1; ; i += 3) {
+ a1 = av[i];
+ if (a1 == NULL)
+ break;
+ good = 0;
+ a2 = av[i + 1];
+ if (a2 == NULL)
+ break;
+ a3 = av[i + 2];
+ if (a3 == NULL)
+ break;
+ if (BAN_AddTest(NULL, b, a1, a2, a3))
+ break;
+ good = 1;
+ }
+ if (!good)
+ /* XXX: report error how ? */
+ BAN_Free(b);
+ else
+ BAN_Insert(b);
+ FreeArgv(av);
+}
+
/*--------------------------------------------------------------------
* Simple stuff
*/
Copied: branches/2.0/varnish-cache/bin/varnishtest/tests/c00022.vtc (from rev 3542, trunk/varnish-cache/bin/varnishtest/tests/c00022.vtc)
===================================================================
--- branches/2.0/varnish-cache/bin/varnishtest/tests/c00022.vtc (rev 0)
+++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00022.vtc 2009-02-10 14:58:17 UTC (rev 3724)
@@ -0,0 +1,162 @@
+# $Id$
+
+test "Test banning a url with VCL purge"
+
+server s1 {
+ rxreq
+ expect req.url == "/foo"
+ txresp -hdr "foo: bar5" -body "1111\n"
+
+ rxreq
+ expect req.url == "/foo"
+ txresp -hdr "foo: bar6" -body "11111\n"
+
+ rxreq
+ expect req.url == "/foo"
+ txresp -hdr "foo: bar7" -body "111111\n"
+
+ rxreq
+ expect req.url == "/foo"
+ txresp -hdr "foo: bar8" -body "1111111\n"
+} -start
+
+varnish v1 -vcl+backend {
+ sub vcl_recv {
+ if (req.request == "PURGE") {
+ purge (req.url == req.url);
+ error 410;
+ }
+ if (req.request == "PURGESTR") {
+ purge ("" req.http.purge);
+ error 410;
+ }
+ }
+} -start
+
+# Fetch into cache
+client c1 {
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.foo == bar5
+ expect resp.bodylen == 5
+} -run
+
+# Purge something else
+client c1 {
+ txreq -req PURGE -url /foox
+ rxresp
+ expect resp.status == 410
+} -run
+varnish v1 -cliok "purge.list"
+
+# Still in cache
+client c1 {
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.foo == bar5
+ expect resp.bodylen == 5
+} -run
+
+# Purge it
+client c1 {
+ txreq -req PURGE -url /foo
+ rxresp
+ expect resp.status == 410
+} -run
+varnish v1 -cliok "purge.list"
+
+# New obj
+client c1 {
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.foo == bar6
+ expect resp.bodylen == 6
+} -run
+
+# Purge everything else
+client c1 {
+ txreq -req PURGESTR -hdr "purge=req.url != /foo"
+ rxresp
+ expect resp.status == 410
+} -run
+varnish v1 -cliok "purge.list"
+
+# still there
+client c1 {
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.foo == bar6
+ expect resp.bodylen == 6
+} -run
+
+# Purge it
+client c1 {
+ txreq -req PURGESTR -hdr "Purge: obj.http.foo == \"bar6\""
+ rxresp
+ expect resp.status == 410
+} -run
+varnish v1 -cliok "purge.list"
+
+# New one
+client c1 {
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.foo == bar7
+ expect resp.bodylen == 7
+} -run
+
+# Purge something else
+client c1 {
+ txreq -req PURGESTR -hdr "Purge: obj.http.foo == \"bar6\""
+ rxresp
+ expect resp.status == 410
+} -run
+varnish v1 -cliok "purge.list"
+
+# Still there
+client c1 {
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.foo == bar7
+ expect resp.bodylen == 7
+} -run
+
+# Header match
+client c1 {
+ txreq -req PURGESTR -hdr "Purge: req.http.foo == \"barcheck\""
+ rxresp
+ expect resp.status == 410
+} -run
+varnish v1 -cliok "purge.list"
+
+client c1 {
+ txreq -url "/foo" -hdr "foo: barcheck"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.foo == bar8
+ expect resp.bodylen == 8
+} -run
+
+# Header match
+client c1 {
+ txreq -req PURGESTR -hdr "Purge: obj.http.foo == \"barcheck\""
+ rxresp
+ expect resp.status == 410
+} -run
+varnish v1 -cliok "purge.list"
+
+client c1 {
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.foo == bar8
+ expect resp.bodylen == 8
+} -run
+
+
Modified: branches/2.0/varnish-cache/include/vrt.h
===================================================================
--- branches/2.0/varnish-cache/include/vrt.h 2009-02-10 14:50:53 UTC (rev 3723)
+++ branches/2.0/varnish-cache/include/vrt.h 2009-02-10 14:58:17 UTC (rev 3724)
@@ -143,6 +143,7 @@
void VRT_panic(struct sess *sp, const char *, ...);
void VRT_purge(struct sess *sp, char *, ...);
+void VRT_purge_string(struct sess *sp, char *, ...);
void VRT_count(const struct sess *, unsigned);
int VRT_rewrite(const char *, const char *);
Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_action.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-10 14:50:53 UTC (rev 3723)
+++ branches/2.0/varnish-cache/lib/libvcl/vcc_action.c 2009-02-10 14:58:17 UTC (rev 3724)
@@ -401,7 +401,7 @@
do
Fb(tl, 0, ", ");
while (vcc_StringVal(tl));
- Fb(tl, 0, ", 0);\n");
+ Fb(tl, 0, "vrt_magic_string_end);\n");
}
Expect(tl, ')');
Modified: branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-10 14:50:53 UTC (rev 3723)
+++ branches/2.0/varnish-cache/lib/libvcl/vcc_fixed_token.c 2009-02-10 14:58:17 UTC (rev 3724)
@@ -235,8 +235,8 @@
vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWI");
vsb_cat(sb, "SE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFT");
vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n");
- vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3616 2009-02-05 11:");
- vsb_cat(sb, "43:20Z tfheen $\n *\n * Runtime support for compiled V");
+ vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3723 2009-02-10 14:");
+ vsb_cat(sb, "50:53Z tfheen $\n *\n * Runtime support for compiled V");
vsb_cat(sb, "CL programs.\n *\n * XXX: When this file is changed, l");
vsb_cat(sb, "ib/libvcl/vcc_gen_fixed_token.tcl\n");
vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n");
@@ -289,6 +289,7 @@
vsb_cat(sb, " const char *,\n void *, const char *);\n");
vsb_cat(sb, "\nvoid VRT_panic(struct sess *sp, const char *, ...);\n");
vsb_cat(sb, "void VRT_purge(struct sess *sp, char *, ...);\n");
+ vsb_cat(sb, "void VRT_purge_string(struct sess *sp, char *, ...);\n");
vsb_cat(sb, "\nvoid VRT_count(const struct sess *, unsigned);\n");
vsb_cat(sb, "int VRT_rewrite(const char *, const char *);\n");
vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);");
More information about the varnish-commit
mailing list