#define BAN_T_NOT (1 << 1)
regex_t re;
char *dst;
+ char *src;
};
struct ban {
}
/*--------------------------------------------------------------------
- * Test functions -- return 0 if the test does not match
+ * Test functions -- return 0 if the test matches
*/
static int
{
int i;
+ if (p == NULL)
+ return(!(bt->flags & BAN_T_NOT));
if (bt->flags & BAN_T_REGEXP)
i = regexec(&bt->re, p, 0, NULL, 0);
else
i = strcmp(bt->dst, p);
if (bt->flags & BAN_T_NOT)
- return (i);
- return (!i);
+ return (!i);
+ return (i);
}
static int
return(ban_cond_str(bt, o->objhead->hash));
}
+static int
+ban_cond_req_http(const struct ban_test *bt, const struct object *o,
+ const struct sess *sp)
+{
+ char *s;
+
+ (void)o;
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ http_GetHdr(sp->http, bt->src, &s);
+ return (ban_cond_str(bt, s));
+}
+
+static int
+ban_cond_obj_http(const struct ban_test *bt, const struct object *o,
+ const struct sess *sp)
+{
+ char *s;
+
+ (void)sp;
+ CHECK_OBJ_NOTNULL(o, OBJECT_MAGIC);
+ http_GetHdr(o->http, bt->src, &s);
+ return (ban_cond_str(bt, s));
+}
+
/*--------------------------------------------------------------------
* Parse and add a ban test specification
*/
return (0);
}
+static void
+ban_parse_http(struct ban_test *bt, const char *a1)
+{
+ int l;
+
+ l = strlen(a1);
+ bt->src = malloc(l + 3);
+ XXXAN(bt->src);
+ bt->src[0] = l + 1;
+ memcpy(bt->src + 1, a1, l);
+ bt->src[l + 1] = ':';
+ bt->src[l + 2] = '\0';
+}
+
static int
ban_parse_test(struct cli *cli, struct ban *b, const char *a1, const char *a2, const char *a3)
{
cli_result(cli, CLIS_PARAM);
return (-1);
}
+
+
if (!strcmp(a1, "req.url"))
bt->func = ban_cond_url;
else if (!strcmp(a1, "obj.hash"))
bt->func = ban_cond_hash;
- else {
+ else if (!strncmp(a1, "req.http.", 9)) {
+ bt->func = ban_cond_req_http;
+ ban_parse_http(bt, a1 + 9);
+ } else if (!strncmp(a1, "obj.http.", 9)) {
+ bt->func = ban_cond_obj_http;
+ ban_parse_http(bt, a1 + 9);
+ } else {
cli_out(cli, "unknown or unsupported field \"%s\"", a1);
cli_result(cli, CLIS_PARAM);
return (-1);
if (bt->func(bt, o, sp))
break;
}
- if (bt != NULL)
+ if (bt == NULL)
break;
}
server s1 {
rxreq
expect req.url == "/foo"
- txresp -body "1111\n"
+ 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 -body "11111\n"
+ txresp -hdr "foo: bar8" -body "1111111\n"
} -start
varnish v1 -vcl+backend { } -start
txreq -url "/foo"
rxresp
expect resp.status == 200
- expect resp.http.content-length == 5
-}
-
-client c1 -run
+ expect resp.http.foo == bar5
+ expect resp.bodylen == 5
+} -run
+# syntax checks
varnish v1 -clierr 104 "purge"
varnish v1 -clierr 104 "purge foo"
varnish v1 -clierr 104 "purge foo bar"
varnish v1 -clierr 106 "purge a b c && a"
varnish v1 -clierr 106 "purge a b c && a b"
varnish v1 -clierr 106 "purge a b c || a b c"
+varnish v1 -cliok "purge.list"
+
+# exact match, not matching
varnish v1 -cliok "purge req.url == foo"
+varnish v1 -cliok "purge.list"
+
client c1 {
txreq -url "/foo"
rxresp
expect resp.status == 200
- expect resp.http.content-length == 5
-}
+ expect resp.http.foo == bar5
+ expect resp.bodylen == 5
+} -run
-varnish v1 -cliok "purge req.url ~ foo && req.url ~ \"[ o]\""
+# exact match, matching
+varnish v1 -cliok "purge req.url == /foo"
+varnish v1 -cliok "purge.list"
+client c1 {
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.foo == bar6
+ expect resp.bodylen == 6
+} -run
+
+# regexp nonmatch
+varnish v1 -cliok "purge req.url ~ bar"
varnish v1 -cliok "purge.list"
client c1 {
txreq -url "/foo"
rxresp
expect resp.status == 200
- expect resp.http.content-length == 6
-}
+ expect resp.http.foo == bar6
+ expect resp.bodylen == 6
+} -run
+
+
+# regexp match
+varnish v1 -cliok "purge req.url ~ foo"
+varnish v1 -cliok "purge.list"
+
+client c1 {
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.foo == bar7
+ expect resp.bodylen == 7
+} -run
+
+# header check, nonmatch
+varnish v1 -cliok "purge obj.http.foo != bar7"
+varnish v1 -cliok "purge.list"
+
+client c1 {
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.foo == bar7
+ expect resp.bodylen == 7
+} -run
+
+# header check, match
+varnish v1 -cliok "purge req.http.foo == barcheck"
+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 check, no header
+varnish v1 -cliok "purge obj.http.bar == barcheck"
+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
+
-client c1 -run