Unverified Commit 28590eef authored by Dridi Boukelmoune's avatar Dridi Boukelmoune Committed by Nils Goroll

vcc: Allow arbitrary subs in the built-in VCL

Now that we know in advance the available suboutines in the built-in VCL
we can use that as the condition to create an append-able subroutine
when the vcl_ prefix is encountered.

This work is currently incomplete, at least because non-state built-in
subroutines are currently not listed when an unknwon subroutine is
encountered.

Also, instead of proper test coverage this currently uses b00000.vtc as
a strawman to show how to skip a specific processing.
parent e45595ec
......@@ -65,13 +65,21 @@ sub vcl_recv {
# We only deal with GET and HEAD by default
return (pass);
}
if (req.http.Authorization || req.http.Cookie) {
if (req.http.Authorization) {
# Not cacheable by default
return (pass);
}
call vcl_req_cookie;
return (hash);
}
sub vcl_req_cookie {
if (req.http.Cookie) {
# Risky to cache by default
return (pass);
}
}
sub vcl_pipe {
# By default "Connection: close" is set on all piped requests, to stop
# connection reuse from sending future requests directly to the
......
varnishtest "Built-in split subroutine"
server s1 {
rxreq
txresp -hdr "age: 12" \
-hdr "cache-control: public, max-age=10, stale-while-revalidate=20"
} -start
varnish v1 -vcl+backend {
sub vcl_req_cookie {
return; # trust beresp headers
}
sub vcl_beresp_stale {
if (beresp.ttl + beresp.grace > 0s) {
return; # cache stale responses
}
}
} -start
client c1 {
txreq
rxresp
expect resp.status == 200
txreq -hdr "cookie: unrelated=analytics"
rxresp
expect resp.status == 200
} -run
varnish v1 -expect cache_hit == 1
varnish v1 -expect cache_hit == cache_hit_grace
......@@ -219,7 +219,7 @@ vcc_Compound(struct vcc *tl)
static void
vcc_ParseFunction(struct vcc *tl)
{
struct symbol *sym;
struct symbol *sym, *bsym;
struct token *t;
struct proc *p;
......@@ -231,9 +231,20 @@ vcc_ParseFunction(struct vcc *tl)
sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_SUB, SYMTAB_CREATE, XREF_DEF);
ERRCHK(tl);
AN(sym);
if (vcc_builtin != NULL) {
vcc_builtin->t = t;
bsym = VCC_SymbolGet(vcc_builtin, SYM_MAIN, SYM_SUB,
SYMTAB_NOERR, XREF_NONE);
AZ(vcc_builtin->err);
}
else
bsym = NULL;
p = sym->proc;
if (p == NULL) {
if ((t->b[0] == 'v'|| t->b[0] == 'V') &&
if (vcc_builtin != NULL && bsym == NULL &&
(t->b[0] == 'v'|| t->b[0] == 'V') &&
(t->b[1] == 'c'|| t->b[1] == 'C') &&
(t->b[2] == 'l'|| t->b[2] == 'L') &&
(t->b[3] == '_')) {
......@@ -241,10 +252,10 @@ vcc_ParseFunction(struct vcc *tl)
" are reserved for subroutines.\n");
vcc_ErrWhere(tl, t);
VSB_printf(tl->sb, "Valid vcl_* subroutines are:\n");
VTAILQ_FOREACH(p, &tl->procs, list) {
if (p->method != NULL)
VSB_printf(tl->sb, "\t%s\n",
p->method->name);
VTAILQ_FOREACH(p, &vcc_builtin->procs, list) {
t = p->name;
VSB_printf(tl->sb, "\t%.*s\n",
(int)pdiff(t->b, t->e), t->b);
}
return;
}
......@@ -252,7 +263,7 @@ vcc_ParseFunction(struct vcc *tl)
p = vcc_NewProc(tl, sym);
p->name = t;
VSB_printf(p->cname, "%s", sym->lname);
} else if (p->method == NULL) {
} else if (p->method == NULL && bsym == NULL) {
VSB_printf(tl->sb, "Subroutine '%s' redefined\n", sym->name);
vcc_ErrWhere(tl, t);
VSB_printf(tl->sb, "Previously defined here:\n");
......@@ -260,7 +271,6 @@ vcc_ParseFunction(struct vcc *tl)
return;
} else {
/* Add to VCL sub */
AN(p->method);
if (p->name == NULL)
p->name = t;
}
......
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