[PATCH] Get rid of ban_url/ban.url

Tollef Fog Heen tfheen at varnish-software.com
Fri Nov 23 11:06:21 CET 2012


ban.url is confusing as it takes a regular expression rather than a
fixed string, so get rid of it in favour of people being explicit and
using ban req.url ~ /foo
---
 bin/varnishd/cache/cache_ban.c       |   16 ----------------
 bin/varnishd/mgt/mgt_param.c         |    2 +-
 bin/varnishtest/tests/c00006.vtc     |    2 +-
 bin/varnishtest/tests/c00019.vtc     |   12 ++++++------
 bin/varnishtest/tests/v00011.vtc     |    2 +-
 bin/varnishtest/tests/v00018.vtc     |    4 ++--
 doc/sphinx/reference/varnish-cli.rst |    7 -------
 doc/sphinx/reference/vcl.rst         |    5 +----
 include/vcli.h                       |    7 -------
 lib/libvcl/vcc_action.c              |   19 -------------------
 10 files changed, 12 insertions(+), 64 deletions(-)

diff --git a/bin/varnishd/cache/cache_ban.c b/bin/varnishd/cache/cache_ban.c
index 688842b..6315798 100644
--- a/bin/varnishd/cache/cache_ban.c
+++ b/bin/varnishd/cache/cache_ban.c
@@ -1066,21 +1066,6 @@ ccf_ban(struct cli *cli, const char * const *av, void *priv)
 }
 
 static void
-ccf_ban_url(struct cli *cli, const char * const *av, void *priv)
-{
-	const char *aav[6];
-
-	(void)priv;
-	aav[0] = NULL;
-	aav[1] = "ban";
-	aav[2] = "req.url";
-	aav[3] = "~";
-	aav[4] = av[2];
-	aav[5] = NULL;
-	ccf_ban(cli, aav, priv);
-}
-
-static void
 ban_render(struct cli *cli, const uint8_t *bs)
 {
 	struct ban_test bt;
@@ -1152,7 +1137,6 @@ ccf_ban_list(struct cli *cli, const char * const *av, void *priv)
 }
 
 static struct cli_proto ban_cmds[] = {
-	{ CLI_BAN_URL,				"", ccf_ban_url },
 	{ CLI_BAN,				"", ccf_ban },
 	{ CLI_BAN_LIST,				"", ccf_ban_list },
 	{ NULL }
diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index 9359800..0e4440d 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -683,7 +683,7 @@ static const struct parspec input_parspec[] = {
 		"Objects already cached will not be affected by changes "
 		"made until they are fetched from the backend again.\n"
 		"To force an immediate effect at the expense of a total "
-		"flush of the cache use \"ban.url .\"",
+		"flush of the cache use \"ban obj.http.date ~ .\"",
 		0,
 		"120", "seconds" },
 	{ "workspace_client",
diff --git a/bin/varnishtest/tests/c00006.vtc b/bin/varnishtest/tests/c00006.vtc
index 9342886..83c3ea2 100644
--- a/bin/varnishtest/tests/c00006.vtc
+++ b/bin/varnishtest/tests/c00006.vtc
@@ -20,7 +20,7 @@ client c1 {
 
 client c1 -run
 
-varnish v1 -cli "ban.url foo"
+varnish v1 -cli "ban req.url ~ foo"
 
 client c1 {
 	txreq -url "/foo"
diff --git a/bin/varnishtest/tests/c00019.vtc b/bin/varnishtest/tests/c00019.vtc
index 5cc5973..22b5ca1 100644
--- a/bin/varnishtest/tests/c00019.vtc
+++ b/bin/varnishtest/tests/c00019.vtc
@@ -13,7 +13,7 @@ server s1 {
 
 varnish v1 -vcl+backend {} -start
 
-varnish v1 -cliok "ban.url FOO"
+varnish v1 -cliok "ban req.url ~ FOO"
 
 # There is one "magic" ban from boot
 varnish v1 -expect bans_added == 2
@@ -35,7 +35,7 @@ varnish v1 -expect bans_tested == 0
 varnish v1 -expect bans_tests_tested == 0
 
 # Add another ban
-varnish v1 -cliok "ban.url FOO"
+varnish v1 -cliok "ban req.url ~ FOO"
 varnish v1 -expect bans_added == 3
 varnish v1 -cliok "ban.list"
 
@@ -60,15 +60,15 @@ client c1 {
 
 
 # Now add another two bans, Kilroy should not be hit
-varnish v1 -cliok "ban.url KILROY"
-varnish v1 -cliok "ban.url FOO"
+varnish v1 -cliok "ban req.url ~ KILROY"
+varnish v1 -cliok "ban req.url ~ FOO"
 varnish v1 -expect bans_added == 5
 
 # Enable dup removal of bans
 varnish v1 -cliok "param.set ban_dups on"
 
 # This should incapacitate the two previous FOO bans.
-varnish v1 -cliok "ban.url FOO"
+varnish v1 -cliok "ban req.url ~ FOO"
 varnish v1 -expect bans_added == 6
 varnish v1 -expect bans_dups == 3
 varnish v1 -cliok "ban.list"
@@ -87,4 +87,4 @@ varnish v1 -cliok "ban.list"
 
 # Test a bogus regexp
 
-varnish v1 -clierr 106 "ban.url [[["
+varnish v1 -clierr 106 "ban req.url ~ [[["
diff --git a/bin/varnishtest/tests/v00011.vtc b/bin/varnishtest/tests/v00011.vtc
index 43ea8c2..dc8bd18 100644
--- a/bin/varnishtest/tests/v00011.vtc
+++ b/bin/varnishtest/tests/v00011.vtc
@@ -11,7 +11,7 @@ server s1 {
 varnish v1 -vcl+backend { 
 	sub vcl_recv {
 		if (req.request == "PURGE") {
-			ban_url("^/$");
+			ban("req.url ~ ^/$");
 			error 209 "foo";
 		}
 	}
diff --git a/bin/varnishtest/tests/v00018.vtc b/bin/varnishtest/tests/v00018.vtc
index 7a9ccbc..6fe35fb 100644
--- a/bin/varnishtest/tests/v00018.vtc
+++ b/bin/varnishtest/tests/v00018.vtc
@@ -86,7 +86,7 @@ varnish v1 -errvcl {Only http header variables can be unset.} {
 
 varnish v1 -errvcl {Unknown token 'if' when looking for STRING} {
 	backend b { .host = "127.0.0.1"; }
-	sub vcl_recv { ban_url (if); }
+	sub vcl_recv { ban (if); }
 }
 
 varnish v1 -errvcl {Expected an action, 'if', '{' or '}'} {
@@ -96,7 +96,7 @@ varnish v1 -errvcl {Expected an action, 'if', '{' or '}'} {
 
 varnish v1 -vcl {
 	backend b { .host = "127.0.0.1"; }
-	sub vcl_recv { ban_url ("foo"); }
+	sub vcl_recv { ban ("req.url ~ foo"); }
 }
 
 varnish v1 -errvcl {Expected an action, 'if', '{' or '}'} {
diff --git a/doc/sphinx/reference/varnish-cli.rst b/doc/sphinx/reference/varnish-cli.rst
index 43fd590..787c09d 100644
--- a/doc/sphinx/reference/varnish-cli.rst
+++ b/doc/sphinx/reference/varnish-cli.rst
@@ -118,13 +118,6 @@ ban.list
 
       Then follows the actual ban it self.
 
-ban.url regexp
-      Immediately invalidate all documents whose URL matches the
-      specified regular expression. Please note that the Host part of
-      the URL is ignored, so if you have several virtual hosts all of
-      them will be banned. Use *ban* to specify a complete ban if you
-      need to narrow it down.
-
 help [command]
       Display a list of available commands.
       If the command is specified, display help for this command.
diff --git a/doc/sphinx/reference/vcl.rst b/doc/sphinx/reference/vcl.rst
index 50c339b..98c1c47 100644
--- a/doc/sphinx/reference/vcl.rst
+++ b/doc/sphinx/reference/vcl.rst
@@ -327,9 +327,6 @@ regsuball(str, regex, sub)
 ban(ban expression)
   Bans all objects in cache that match the expression.
 
-ban_url(regex)
-  Bans all objects in cache whose URLs match regex.
-
 Subroutines
 ~~~~~~~~~~~
 
@@ -574,7 +571,7 @@ Example:
 	sub vcl_recv {
 	  if (client.ip ~ admin_network) {
 	    if (req.http.Cache-Control ~ "no-cache") {
-	      ban_url(req.url);
+	      ban("req.url ~ " + req.url);
 	    }
 	  }
 	}
diff --git a/include/vcli.h b/include/vcli.h
index 04ac11c..3294dd7 100644
--- a/include/vcli.h
+++ b/include/vcli.h
@@ -58,13 +58,6 @@
 	    "\tReturns the TTL, size and checksum of the object.",	\
 	1, 1
 
-#define CLI_BAN_URL							\
-	"ban.url",							\
-	"ban.url <regexp>",						\
-	"\tAll objects where the urls matches regexp will be "		\
-	    "marked obsolete.",						\
-	1, 1
-
 #define CLI_BAN								\
 	"ban",								\
 	"ban <field> <operator> <arg> [&& <field> <oper> <arg>]...",	\
diff --git a/lib/libvcl/vcc_action.c b/lib/libvcl/vcc_action.c
index eae6231..1eec1c4 100644
--- a/lib/libvcl/vcc_action.c
+++ b/lib/libvcl/vcc_action.c
@@ -195,24 +195,6 @@ parse_ban(struct vcc *tl)
 /*--------------------------------------------------------------------*/
 
 static void
-parse_ban_url(struct vcc *tl)
-{
-
-	vcc_NextToken(tl);
-	ExpectErr(tl, '(');
-	vcc_NextToken(tl);
-
-	Fb(tl, 1, "VRT_ban(req, \"req.url\", \"~\", ");
-	vcc_Expr(tl, STRING);
-	ERRCHK(tl);
-	ExpectErr(tl, ')');
-	vcc_NextToken(tl);
-	Fb(tl, 0, ", 0);\n");
-}
-
-/*--------------------------------------------------------------------*/
-
-static void
 parse_new_syntax(struct vcc *tl)
 {
 
@@ -324,7 +306,6 @@ static struct action_table {
 	{ "call",		parse_call },
 	{ "hash_data",		parse_hash_data, VCL_MET_HASH },
 	{ "ban",		parse_ban },
-	{ "ban_url",		parse_ban_url },
 	{ "remove",		parse_unset }, /* backward compatibility */
 	{ "return",		parse_return },
 	{ "rollback",		parse_rollback },
-- 
1.7.10.4




More information about the varnish-dev mailing list