Commit 3fbfb293 authored by Tollef Fog Heen's avatar Tollef Fog Heen

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.



git-svn-id: http://www.varnish-cache.org/svn/branches/2.0@3724 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent bddb1d76
......@@ -788,11 +788,61 @@ VRT_purge(struct sess *sp, char *cmds, ...)
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
*/
......
# $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
......@@ -143,6 +143,7 @@ const char *VRT_regsub(const struct sess *sp, int all, const char *,
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 *);
......
......@@ -401,7 +401,7 @@ parse_purge(struct tokenlist *tl)
do
Fb(tl, 0, ", ");
while (vcc_StringVal(tl));
Fb(tl, 0, ", 0);\n");
Fb(tl, 0, "vrt_magic_string_end);\n");
}
Expect(tl, ')');
......
......@@ -235,8 +235,8 @@ vcl_output_lang_h(struct vsb *sb)
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 @@ vcl_output_lang_h(struct vsb *sb)
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 *);");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment