[master] 3e3619d Add a simple facility for having variables alias each other and use it to rename {beresp, resp, obj}.response to *.reason while still keeping the old ones working.

Poul-Henning Kamp phk at varnish-cache.org
Fri Nov 22 12:36:20 CET 2013


commit 3e3619da01f3582866390a11967d31986ad92c08
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Fri Nov 22 11:34:57 2013 +0000

    Add a simple facility for having variables alias each other and
    use it to rename {beresp,resp,obj}.response to *.reason while
    still keeping the old ones working.
    
    Use it to also eliminate the already duplicated req.request
    and bereq.request (now: *.method)

diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 2555f24..250cb85 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -103,22 +103,20 @@ VRT_r_##obj##_status(const struct vrt_ctx *ctx)				\
 }
 
 VRT_DO_HDR(req,    method,	HTTP_HDR_METHOD)
-VRT_DO_HDR(req,    request,	HTTP_HDR_METHOD)
 VRT_DO_HDR(req,    url,		HTTP_HDR_URL)
 VRT_DO_HDR(req,    proto,	HTTP_HDR_PROTO)
 VRT_DO_HDR(obj,    proto,	HTTP_HDR_PROTO)
-VRT_DO_HDR(obj,    response,	HTTP_HDR_RESPONSE)
+VRT_DO_HDR(obj,    reason,	HTTP_HDR_RESPONSE)
 VRT_DO_STATUS(obj)
 VRT_DO_HDR(resp,   proto,	HTTP_HDR_PROTO)
-VRT_DO_HDR(resp,   response,	HTTP_HDR_RESPONSE)
+VRT_DO_HDR(resp,   reason,	HTTP_HDR_RESPONSE)
 VRT_DO_STATUS(resp)
 
 VRT_DO_HDR(bereq,  method,	HTTP_HDR_METHOD)
-VRT_DO_HDR(bereq,  request,	HTTP_HDR_METHOD)
 VRT_DO_HDR(bereq,  url,		HTTP_HDR_URL)
 VRT_DO_HDR(bereq,  proto,	HTTP_HDR_PROTO)
 VRT_DO_HDR(beresp, proto,	HTTP_HDR_PROTO)
-VRT_DO_HDR(beresp, response,	HTTP_HDR_RESPONSE)
+VRT_DO_HDR(beresp, reason,	HTTP_HDR_RESPONSE)
 VRT_DO_STATUS(beresp)
 
 /*--------------------------------------------------------------------*/
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index a12fe24..9a00c37 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -157,13 +157,6 @@ The client's IP address.
 		The request type (e.g. "GET", "HEAD").
 		"""
 	),
-	('req.request',
-		'STRING',
-		( 'client',),
-		( 'client',), """
-		utdated way to spell req.method. (XXX: remove)
-		"""
-	),
 	('req.url',
 		'STRING',
 		( 'client',),
@@ -287,13 +280,6 @@ The client's IP address.
 		The request type (e.g. "GET", "HEAD").
 		"""
 	),
-	('bereq.request',
-		'STRING',
-		( 'pipe', 'backend', ),
-		( 'pipe', 'backend', ), """
-		XXX: remove
-		"""
-	),
 	('bereq.url',
 		'STRING',
 		( 'pipe', 'backend', ),
@@ -358,7 +344,7 @@ The client's IP address.
 		The HTTP status code returned by the server.
 		"""
 	),
-	('beresp.response',
+	('beresp.reason',
 		'STRING',
 		( 'backend_response',),
 		( 'backend_response',), """
@@ -481,7 +467,7 @@ The client's IP address.
 		The HTTP status code returned by the server.
 		"""
 	),
-	('obj.response',
+	('obj.reason',
 		'STRING',
 		( 'error',),
 		( 'error',), """
@@ -554,7 +540,7 @@ The client's IP address.
 		The HTTP status code that will be returned.
 		"""
 	),
-	('resp.response',
+	('resp.reason',
 		'STRING',
 		( 'deliver',),
 		( 'deliver',), """
@@ -578,6 +564,15 @@ The client's IP address.
 	),
 ]
 
+# Backwards compatibility:
+aliases = [
+	('req.request',		'req.method'),
+	('bereq.request',	'bereq.method'),
+	('beresp.response',	'beresp.reason'),
+	('resp.response',	'resp.reason'),
+	('obj.response',	'obj.reason'),
+]
+
 stv_variables = (
 	('free_space',	'BYTES',	"0."),
 	('used_space',	'BYTES',	"0."),
@@ -967,43 +962,55 @@ fo.write("""
 const struct var vcc_vars[] = {
 """)
 
-sp_variables.sort()
-for i in sp_variables:
+def one_var(nm, spec):
 	fh.write("\n")
-	typ = i[1]
+	typ = spec[1]
 	cnam = i[0].replace(".", "_")
 	ctyp = vcltypes[typ]
 
-	fo.write("\t{ \"%s\", %s, %d,\n" % (i[0], typ, len(i[0])))
+	fo.write("\t{ \"%s\", %s, %d,\n" % (nm, typ, len(nm)))
 
-	if len(i[2]) == 0:
+	if len(spec[2]) == 0:
 		fo.write('\t    NULL,\t/* No reads allowed */\n')
 	elif typ == "HEADER":
 		fo.write('\t    "HDR_')
-		fo.write(i[0].split(".")[0].upper())
+		fo.write(nm.split(".")[0].upper())
 		fo.write('",\n')
 	else:
 		fo.write('\t    "VRT_r_%s(ctx)",\n' % cnam)
-		fh.write("VCL_" + typ + " VRT_r_%s(const struct vrt_ctx *);\n" % cnam )
-	restrict(fo, i[2])
+		if nm == i[0]:
+			fh.write("VCL_" + typ +
+			    " VRT_r_%s(const struct vrt_ctx *);\n" % cnam )
+	restrict(fo, spec[2])
 
-	if len(i[3]) == 0:
+	if len(spec[3]) == 0:
 		fo.write('\t    NULL,\t/* No writes allowed */\n')
 	elif typ == "HEADER":
 		fo.write('\t    "HDR_')
-		fo.write(i[0].split(".")[0].upper())
+		fo.write(nm.split(".")[0].upper())
 		fo.write('",\n')
 	else:
 		fo.write('\t    "VRT_l_%s(ctx, ",\n' % cnam)
-		fh.write("void VRT_l_%s(const struct vrt_ctx *, " % cnam)
-		if typ != "STRING":
-			fh.write("VCL_" + typ + ");\n")
-		else:
-			fh.write(ctyp + ", ...);\n")
-	restrict(fo, i[3])
+		if nm == i[0]:
+			fh.write(
+			    "void VRT_l_%s(const struct vrt_ctx *, " % cnam)
+			if typ != "STRING":
+				fh.write("VCL_" + typ + ");\n")
+			else:
+				fh.write(ctyp + ", ...);\n")
+	restrict(fo, spec[3])
 
 	fo.write("\t},\n")
 
+
+sp_variables.sort()
+aliases.sort()
+for i in sp_variables:
+	one_var(i[0], i)
+	for j in aliases:
+		if j[1] == i[0]:
+			one_var(j[0], i)
+
 fo.write("\t{ NULL }\n};\n")
 
 fh.write("\n")



More information about the varnish-commit mailing list