Commit ecad74be authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Rework the filter-list parsing and test a couple of corner cases.

parent e8276b9a
......@@ -150,43 +150,57 @@ VRT_RemoveVDP(VRT_CTX, const struct vdp *filter)
FREE_OBJ(vp);
}
static const struct vfilter vfilter_error[1];
static const struct vfilter *
vcl_filter_list_iter(const struct vfilter_head *h1,
const struct vfilter_head *h2, const char **flp)
{
const char *fl, *q;
const struct vfilter *vp;
AN(h1);
AN(h2);
AN(flp);
fl = *flp;
AN(fl);
while (vct_isspace(*fl))
fl++;
if (*fl == '\0') {
*flp = NULL;
return (NULL);
}
for (q = fl; *q && !vct_isspace(*q); q++)
continue;
*flp = q;
VTAILQ_FOREACH(vp, h1, list)
if (vp->nlen == q - fl && !memcmp(fl, vp->name, vp->nlen))
return (vp);
VTAILQ_FOREACH(vp, h2, list)
if (vp->nlen == q - fl && !memcmp(fl, vp->name, vp->nlen))
return (vp);
*flp = fl;
return (vfilter_error);
}
int
VCL_StackVFP(struct vfp_ctx *vc, const struct vcl *vcl, const char *fl)
{
const char *p, *q;
const struct vfilter *vp;
VSLb(vc->wrk->vsl, SLT_Filters, "%s", fl);
for (p = fl; *p; p = q) {
if (vct_isspace(*p)) {
q = p + 1;
continue;
}
for (q = p; *q; q++)
if (vct_isspace(*q))
break;
VTAILQ_FOREACH(vp, &vfp_filters, list) {
if (vp->nlen != q - p)
continue;
if (!memcmp(p, vp->name, vp->nlen))
break;
}
if (vp == NULL) {
VTAILQ_FOREACH(vp, &vcl->vfps, list) {
if (vp->nlen != q - p)
continue;
if (!memcmp(p, vp->name, vp->nlen))
break;
}
}
while (1) {
vp = vcl_filter_list_iter(&vfp_filters, &vcl->vfps, &fl);
if (vp == NULL)
return (VFP_Error(vc,
"Filter '%.*s' not found", (int)(q-p), p));
return (0);
if (vp == vfilter_error)
return (VFP_Error(vc, "Filter '...%s' not found", fl));
if (VFP_Push(vc, vp->vfp) == NULL)
return (-1);
}
return (0);
}
void
......
......@@ -3,6 +3,11 @@ varnishtest "VMOD vfp"
server s1 {
rxreq
txresp -body "Ponto Facto, Caesar Transit!"
rxreq
txresp -body "Ponto Facto, Caesar Transit!"
accept
rxreq
txresp -body "Ponto Facto, Caesar Transit!"
} -start
varnish v1 -vcl+backend {
......@@ -14,8 +19,39 @@ varnish v1 -vcl+backend {
} -start
client c1 {
txreq
txreq -hdr "Cookie: a"
rxresp
expect resp.body == "Cbagb Snpgb, Pnrfne Genafvg!"
} -run
varnish v1 -vsl_catchup
varnish v1 -vcl+backend {
import debug;
sub vcl_backend_response {
set beresp.filters = "rot13 rot13a";
}
}
client c1 {
txreq -hdr "Cookie: a"
rxresp
expect resp.status == 503
} -run
varnish v1 -vcl+backend {
import debug;
sub vcl_backend_response {
set beresp.filters = "rot13 rot14";
}
}
client c1 {
txreq -hdr "Cookie: a"
rxresp
expect resp.status == 503
} -run
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