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
*/
--- /dev/null
+# $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
+
+
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 *);
do
Fb(tl, 0, ", ");
while (vcc_StringVal(tl));
- Fb(tl, 0, ", 0);\n");
+ Fb(tl, 0, "vrt_magic_string_end);\n");
}
Expect(tl, ')');
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 3406 2008-11-19 14:");
- vsb_cat(sb, "13:57Z petter $\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, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 3541 2009-01-23 21:");
+ vsb_cat(sb, "17:02Z phk $\n *\n * Runtime support for compiled VCL ");
+ vsb_cat(sb, "programs.\n *\n * XXX: When this file is changed, lib/");
+ vsb_cat(sb, "libvcl/vcc_gen_fixed_token.tcl\n");
vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n");
vsb_cat(sb, "\nstruct sess;\nstruct vsb;\nstruct cli;\n");
vsb_cat(sb, "struct director;\nstruct VCL_conf;\n");
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 *);");