[4.0] 1b57f4c Add a VCC variable type "HTTP" to refer to an entire HTTP message. Presently supported "req", "bereq", "resp", "beresp".

Lasse Karstensen lkarsten at varnish-software.com
Mon Sep 22 16:38:22 CEST 2014


commit 1b57f4cb1956c16d4597e19fc6182b37b6f5c339
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Jul 24 11:00:10 2014 +0000

    Add a VCC variable type "HTTP" to refer to an entire
    HTTP message.  Presently supported "req", "bereq", "resp", "beresp".

diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index b74e101..47897e1 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -608,3 +608,19 @@ VRT_r_obj_uncacheable(const struct vrt_ctx *ctx)
 	CHECK_OBJ_NOTNULL(ctx->req->obj, OBJECT_MAGIC);
 	return (ctx->req->obj->objcore->flags & OC_F_PASS ? 1 : 0);
 }
+
+/*--------------------------------------------------------------------*/
+
+#define HTTP_VAR(x)						\
+struct http *							\
+VRT_r_##x(const struct vrt_ctx *ctx)				\
+{								\
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);			\
+	CHECK_OBJ_NOTNULL(ctx->http_##x, HTTP_MAGIC);		\
+	return (ctx->http_##x);					\
+}
+
+HTTP_VAR(req)
+HTTP_VAR(resp)
+HTTP_VAR(bereq)
+HTTP_VAR(beresp)
diff --git a/bin/varnishtest/tests/m00000.vtc b/bin/varnishtest/tests/m00000.vtc
index 5704a1f..b3ac748 100644
--- a/bin/varnishtest/tests/m00000.vtc
+++ b/bin/varnishtest/tests/m00000.vtc
@@ -2,6 +2,7 @@ varnishtest "Test std & debug vmod"
 
 server s1 {
 	rxreq
+	expect req.http.encrypted == "ROT52"
 	txresp -hdr "foo: bAr" -hdr "bar: fOo" -bodylen 4
 } -start
 
@@ -9,6 +10,10 @@ varnish v1 -vcl+backend {
 	import ${vmod_std};
 	import ${vmod_debug};
 
+	sub vcl_recv {
+		debug.rot52(req);
+	}
+
 	sub vcl_deliver {
 		set resp.http.foo = std.toupper(resp.http.foo);
 		set resp.http.bar = std.tolower(resp.http.bar);
@@ -17,6 +22,7 @@ varnish v1 -vcl+backend {
 		debug.test_priv_vcl();
 		std.log("VCL initiated log");
 		std.syslog(8 + 7, "Somebody runs varnishtest");
+		debug.rot52(resp);
 	}
 } -start
 
@@ -27,6 +33,7 @@ client c1 {
 	expect resp.bodylen == "4"
 	expect resp.http.foo == "BAR"
 	expect resp.http.bar == "foo"
+	expect resp.http.encrypted == "ROT52"
 } -run
 
 varnish v1 -errvcl {Wrong enum value.  Expected one of:} {
diff --git a/include/vrt.h b/include/vrt.h
index 066d6c8..efc9c94 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -41,7 +41,7 @@
 
 #define VRT_MAJOR_VERSION	1U
 
-#define VRT_MINOR_VERSION	1U
+#define VRT_MINOR_VERSION	2U
 
 
 /***********************************************************************/
@@ -59,21 +59,23 @@ struct suckaddr;
 /***********************************************************************
  * This is the central definition of the mapping from VCL types to
  * C-types.  The python scripts read these from here.
+ * (alphabetic order)
  */
 
 typedef struct director *		VCL_BACKEND;
+typedef const struct vmod_priv *	VCL_BLOB;
 typedef unsigned			VCL_BOOL;
 typedef double				VCL_BYTES;
 typedef double				VCL_DURATION;
 typedef const char *			VCL_ENUM;
 typedef const struct gethdr_s *		VCL_HEADER;
+typedef struct http *			VCL_HTTP;
 typedef long				VCL_INT;
 typedef const struct suckaddr *		VCL_IP;
 typedef double				VCL_REAL;
 typedef const char *			VCL_STRING;
 typedef double				VCL_TIME;
 typedef void				VCL_VOID;
-typedef const struct vmod_priv *	VCL_BLOB;
 
 /***********************************************************************
  * This is the composite argument we pass to compiled VCL and VRT
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index 2906588..21173c4 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -197,6 +197,13 @@ sp_variables = [
 		specified by the -n parameter.
 		"""
 	),
+	('req',
+		'HTTP',
+		( 'client',),
+		( ), """
+		The entire request HTTP data structure
+		"""
+	),
 	('req.method',
 		'STRING',
 		( 'client',),
@@ -294,6 +301,13 @@ sp_variables = [
 		always (re)fetch from the backend.
 		"""
 	),
+	('bereq',
+		'HTTP',
+		( 'backend',),
+		( ), """
+		The entire backend request HTTP data structure
+		"""
+	),
 	('bereq.xid',
 		'STRING',
 		( 'backend',),
@@ -370,6 +384,13 @@ sp_variables = [
 		backend.  Not available in pipe mode.
 		"""
 	),
+	('beresp',
+		'HTTP',
+		( 'backend_response', 'backend_error'),
+		( ), """
+		The entire backend response HTTP data structure
+		"""
+	),
 	('beresp.proto',
 		'STRING',
 		( 'backend_response', 'backend_error'),
@@ -553,6 +574,13 @@ sp_variables = [
 		( ), """
 		"""
 	),
+	('resp',
+		'HTTP',
+		( 'deliver', 'synth'),
+		( ), """
+		The entire response HTTP data structure
+		"""
+	),
 	('resp.proto',
 		'STRING',
 		( 'deliver', 'synth', ),
@@ -597,17 +625,17 @@ aliases = [
 
 stv_variables = (
 	('free_space',	'BYTES',	"0.", 'storage.<name>.free_space', """
-        Free space available in the named stevedore. Only available for
-        the malloc stevedore.
-        """),
+	Free space available in the named stevedore. Only available for
+	the malloc stevedore.
+	"""),
 	('used_space',	'BYTES',	"0.", 'storage.<name>.used_space', """
-        Used space in the named stevedore. Only available for the malloc
-        stevedore.
-        """),
+	Used space in the named stevedore. Only available for the malloc
+	stevedore.
+	"""),
 	('happy',	'BOOL',		"0", 'storage.<name>.happy', """
-        Health status for the named stevedore. Not available in any of the
-        current stevedores.
-        """),
+	Health status for the named stevedore. Not available in any of the
+	current stevedores.
+	"""),
 )
 
 #######################################################################
@@ -1188,11 +1216,11 @@ hdr="storage"
 fp_vclvar.write("\n" + hdr + "\n");
 fp_vclvar.write("~" * len(hdr) + "\n");
 for i in stv_variables:
-        fp_vclvar.write("\n" + i[3] + "\n\n")
-        fp_vclvar.write("\tType: " + i[1] + "\n\n")
-        fp_vclvar.write("\tReadable from: client, backend\n\n")
-        for j in i[4].split("\n"):
-                fp_vclvar.write("\t%s\n" % j.strip())
+	fp_vclvar.write("\n" + i[3] + "\n\n")
+	fp_vclvar.write("\tType: " + i[1] + "\n\n")
+	fp_vclvar.write("\tReadable from: client, backend\n\n")
+	for j in i[4].split("\n"):
+		fp_vclvar.write("\t%s\n" % j.strip())
 
 
 fp_vclvar.close()
diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py
index 21c6c6d..25a901f 100755
--- a/lib/libvcc/vmodtool.py
+++ b/lib/libvcc/vmodtool.py
@@ -47,10 +47,12 @@ from pprint import pprint, pformat
 
 ctypes = {
 	'BACKEND':	"VCL_BACKEND",
+	'BLOB':		"VCL_BLOB",
 	'BOOL':		"VCL_BOOL",
 	'DURATION':	"VCL_DURATION",
 	'ENUM':		"VCL_ENUM",
 	'HEADER':	"VCL_HEADER",
+	'HTTP':		"VCL_HTTP",
 	'INT':		"VCL_INT",
 	'IP':		"VCL_IP",
 	'PRIV_CALL':	"struct vmod_priv *",
@@ -60,7 +62,6 @@ ctypes = {
 	'STRING_LIST':	"const char *, ...",
 	'TIME':		"VCL_TIME",
 	'VOID':		"VCL_VOID",
-	'BLOB':		"VCL_BLOB",
 }
 
 #######################################################################
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index 8667298..ca1b307 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -80,3 +80,8 @@ Foo indeed.
 $Method TIME .date()
 
 You never know when you need a date.
+
+$Function VOID rot52(HTTP)
+
+Encrypt the HTTP header with quad-ROT13 encryption,
+(this is approx 33% better than triple-DES).
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index 744b10d..b952f64 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -138,3 +138,12 @@ vmod_no_backend(const struct vrt_ctx *ctx)
 	return (NULL);
 }
 
+VCL_VOID __match_proto__(td_debug_rot52)
+vmod_rot52(const struct vrt_ctx *ctx, VCL_HTTP hp)
+{
+
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
+
+	http_PrintfHeader(hp, "Encrypted: ROT52");
+}



More information about the varnish-commit mailing list