[master] a5f32fd Start sorting VCL variables into "client", "backend" or "both".
Poul-Henning Kamp
phk at varnish-cache.org
Mon Apr 29 16:35:09 CEST 2013
commit a5f32fd8f201e0d1f25dc7236bde37b7fa815d74
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Apr 29 14:34:30 2013 +0000
Start sorting VCL variables into "client", "backend" or "both".
Fix some test-cases to match, generally s/req.*/bereq.*/
diff --git a/bin/varnishtest/tests/c00001.vtc b/bin/varnishtest/tests/c00001.vtc
index 860e827..7497ec3 100644
--- a/bin/varnishtest/tests/c00001.vtc
+++ b/bin/varnishtest/tests/c00001.vtc
@@ -22,7 +22,7 @@ varnish v1 -vcl+backend {
set beresp.http.Snafu6 =
regsub(beresp.http.Foobar, "(b)(a)(r)(f)", "\4\&\3\2p\");
set beresp.http.Snafu7 =
- regsub(beresp.http.Foobar, "ar", req.http.nosuchheader);
+ regsub(beresp.http.Foobar, "ar", bereq.http.nosuchheader);
}
} -start
diff --git a/bin/varnishtest/tests/c00032.vtc b/bin/varnishtest/tests/c00032.vtc
index a3b5c92..d5d06e3 100644
--- a/bin/varnishtest/tests/c00032.vtc
+++ b/bin/varnishtest/tests/c00032.vtc
@@ -20,8 +20,8 @@ varnish v1 -vcl+backend {
}
}
- sub vcl_backend_response {
- if (beresp.status == 400) {
+ sub vcl_deliver {
+ if (resp.status == 400) {
rollback;
set req.url = "/bar";
return (restart);
diff --git a/bin/varnishtest/tests/g00003.vtc b/bin/varnishtest/tests/g00003.vtc
index a4dfa7e..db4ed17 100644
--- a/bin/varnishtest/tests/g00003.vtc
+++ b/bin/varnishtest/tests/g00003.vtc
@@ -21,7 +21,7 @@ varnish v1 -cliok "param.set http_gzip_support true" -vcl+backend {
sub vcl_backend_response {
set beresp.do_gunzip = true;
- if (req.url == "/foobar") {
+ if (bereq.url == "/foobar") {
set beresp.do_gzip = true;
}
}
diff --git a/bin/varnishtest/tests/g00004.vtc b/bin/varnishtest/tests/g00004.vtc
index 286fc98..703cacc 100644
--- a/bin/varnishtest/tests/g00004.vtc
+++ b/bin/varnishtest/tests/g00004.vtc
@@ -22,7 +22,7 @@ varnish v1 \
sub vcl_backend_response {
set beresp.do_stream = false;
- if (req.url == "/gunzip") {
+ if (bereq.url == "/gunzip") {
set beresp.do_gunzip = true;
}
}
diff --git a/bin/varnishtest/tests/p00008.vtc b/bin/varnishtest/tests/p00008.vtc
index 07d6c2c..d72c627 100644
--- a/bin/varnishtest/tests/p00008.vtc
+++ b/bin/varnishtest/tests/p00008.vtc
@@ -20,7 +20,7 @@ varnish v1 \
-vcl+backend {
sub vcl_backend_response {
set beresp.storage = "per1";
- if (req.url ~ "silo2") {
+ if (bereq.url ~ "silo2") {
set beresp.storage = "per2";
}
}
diff --git a/bin/varnishtest/tests/v00016.vtc b/bin/varnishtest/tests/v00016.vtc
index eb5f3d5..2d323b0 100644
--- a/bin/varnishtest/tests/v00016.vtc
+++ b/bin/varnishtest/tests/v00016.vtc
@@ -64,9 +64,9 @@ varnish v1 -vcl {
if (beresp.ttl > 1d) {
set beresp.ttl = 1d;
}
- if (req.backend == b) {
+ if (bereq.backend == b) {
set beresp.ttl = 1d;
- } else if (req.backend != b) {
+ } else if (bereq.backend != b) {
set beresp.ttl = 1h;
}
}
diff --git a/lib/libvcl/generate.py b/lib/libvcl/generate.py
index bd5e6ab..a4b3b7a 100755
--- a/lib/libvcl/generate.py
+++ b/lib/libvcl/generate.py
@@ -78,126 +78,128 @@ tokens = {
# Our methods and actions
returns =(
- ('recv', ('error', 'pass', 'pipe', 'lookup',)),
- ('pipe', ('error', 'pipe',)),
- ('pass', ('error', 'restart', 'pass',)),
- ('hash', ('hash',)),
- ('miss', ('error', 'restart', 'pass', 'fetch',)),
- ('lookup', ('error', 'restart', 'pass', 'deliver',)),
- ('backend_fetch', ('error', 'fetch', 'pass',)),
- ('backend_response', ('error', 'restart', 'deliver',)),
- ('deliver', ('restart', 'deliver',)),
- ('error', ('restart', 'deliver',)),
- ('init', ('ok',)),
- ('fini', ('ok',)),
+ ('recv', "C", ('error', 'pass', 'pipe', 'lookup',)),
+ ('pipe', "C", ('error', 'pipe',)),
+ ('pass', "C", ('error', 'restart', 'pass',)),
+ ('hash', "C", ('hash',)),
+ ('miss', "C", ('error', 'restart', 'pass', 'fetch',)),
+ ('lookup', "C", ('error', 'restart', 'pass', 'deliver',)),
+ ('backend_fetch', "B", ('error', 'fetch', 'pass',)),
+ ('backend_response', "B", ('error', 'restart', 'deliver',)),
+ ('deliver', "C", ('restart', 'deliver',)),
+ ('error', "C", ('restart', 'deliver',)),
+ ('init', "", ('ok',)),
+ ('fini', "", ('ok',)),
)
#######################################################################
# Variables available in sessions
#
# 'all' means all methods
-# 'proc' means all methods but 'init' and 'fini'
+# 'client' means all methods tagged "C"
+# 'backend' means all methods tagged "B"
+# 'both' means all methods tagged "B" or "C"
sp_variables = (
('client.ip',
'IP',
- ( 'proc',),
+ ( 'both',),
( ),
'R'
),
('client.identity',
'STRING',
- ( 'proc',),
- ( 'proc',),
+ ( 'both',),
+ ( 'both',),
'R'
),
('server.ip',
'IP',
- ( 'proc',),
+ ( 'client',),
( ),
'R'
),
('server.hostname',
'STRING',
- ( 'proc',),
+ ( 'client',),
( ),
'R'
),
('server.identity',
'STRING',
- ( 'proc',),
+ ( 'client',),
( ),
'R'
),
('server.port',
'INT',
- ( 'proc',),
+ ( 'client',),
( ),
'R'
),
('req.method',
'STRING',
- ( 'proc',),
- ( 'proc',),
+ ( 'client',),
+ ( 'client',),
'cR'
),
('req.request',
'STRING',
- ( 'proc',),
- ( 'proc',),
+ ( 'client',),
+ ( 'client',),
'cR'
),
('req.url',
'STRING',
- ( 'proc',),
- ( 'proc',),
+ ( 'client',),
+ ( 'client',),
'cR'
),
('req.proto',
'STRING',
- ( 'proc',),
- ( 'proc',),
+ ( 'client',),
+ ( 'client',),
'cR'
),
('req.http.',
'HEADER',
- ( 'proc',),
- ( 'proc',),
+ ( 'client',),
+ ( 'client',),
'cR'
),
('req.restarts',
'INT',
- ( 'proc',),
+ ( 'client',),
( ),
'cR'
),
('req.esi_level',
'INT',
- ( 'proc',),
+ ( 'client',),
( ),
'cR'
),
('req.ttl',
'DURATION',
- ( 'proc',),
- ( 'proc',),
+ ( 'client',),
+ ( 'client',),
'R'
),
('req.grace',
'DURATION',
- ( 'proc',),
- ( 'proc',),
+ ( 'client',),
+ ( 'client',),
'R'
),
('req.keep',
'DURATION',
- ( 'proc',),
- ( 'proc',),
+ ( 'client',),
+ ( 'client',),
'R'
),
('req.xid',
'STRING',
- ( 'proc',),
+ ( 'client',),
( ),
'R'
),
@@ -209,19 +211,19 @@ sp_variables = (
),
('req.can_gzip',
'BOOL',
- ( 'proc',),
+ ( 'client',),
( ),
'R'
),
('req.backend',
'BACKEND',
- ( 'proc',),
- ( 'proc',),
+ ( 'client',),
+ ( 'client',),
'R'
),
('req.backend.healthy',
'BOOL',
- ( 'proc',),
+ ( 'client',),
( ),
'R'
),
@@ -239,13 +241,13 @@ sp_variables = (
),
('bereq.backend',
'BACKEND',
- ( 'backend_fetch', 'backend_response'),
- ( 'backend_fetch', 'backend_response'),
+ ( 'backend', ),
+ ( 'backend', ),
'B'
),
('bereq.backend.healthy',
'BOOL',
- ( 'backend_fetch', 'backend_response'),
+ ( 'backend', ),
( ),
'B'
),
@@ -710,9 +712,16 @@ fo.close()
rets = dict()
vcls = list()
+vcls_client = list()
+vcls_backend = list()
for i in returns:
vcls.append(i[0])
for j in i[1]:
+ if j == "B":
+ vcls_backend.append(i[0])
+ elif j == "C":
+ vcls_client.append(i[0])
+ for j in i[2]:
rets[j] = True
#######################################################################
@@ -730,7 +739,7 @@ for i in l:
fo.write("VCL_RET_MAC(%s, %s" % (i.lower(), i.upper()))
s=", "
for j in returns:
- if i in j[1]:
+ if i in j[2]:
fo.write("%sVCL_MET_%s" % (s, j[0].upper()))
s = " | "
fo.write(")\n")
@@ -740,7 +749,7 @@ fo.write("\n#ifdef VCL_MET_MAC\n")
for i in returns:
fo.write("VCL_MET_MAC(%s,%s,\n" % (i[0].lower(), i[0].upper()))
p = " ("
- for j in i[1]:
+ for j in i[2]:
fo.write(" %s(1U << VCL_RET_%s)\n" % (p, j.upper()))
p = "| "
fo.write("))\n")
@@ -827,11 +836,13 @@ def restrict(fo, spec):
return
if spec[0] == 'all':
spec = vcls
- if spec[0] == 'proc':
- spec = list()
- for i in vcls:
- if i != "init" and i != "fini":
- spec.append(i)
+ if spec[0] == 'client':
+ spec = vcls_client
+ if spec[0] == 'backend':
+ spec = vcls_backend
+ if spec[0] == 'both':
+ spec = vcls_client
+ spec += vcls_backend
p = ""
n = 0
for j in spec:
More information about the varnish-commit
mailing list