[4.0] 982d27c Add std.cache_req_body to call VRT_CacheReqBody from VCL

Lasse Karstensen lkarsten at varnish-software.com
Thu Jan 15 16:35:41 CET 2015


commit 982d27cc44fbf4cdcb666dbc2ec265910a321fbe
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Fri Sep 19 11:40:22 2014 +0200

    Add std.cache_req_body to call VRT_CacheReqBody from VCL
    
    Initial patch by Meng Zhnag - jammy.linux at gmail.com
    
    Conflicts:
    	lib/libvmod_std/vmod_std.c

diff --git a/bin/varnishtest/tests/c00055.vtc b/bin/varnishtest/tests/c00055.vtc
index 0344d02..ef568ea 100644
--- a/bin/varnishtest/tests/c00055.vtc
+++ b/bin/varnishtest/tests/c00055.vtc
@@ -11,8 +11,10 @@ server s1 {
 } -start
 
 varnish v1 -cliok "param.set vcc_allow_inline_c true" -vcl+backend {
+	import ${vmod_std};
+
 	sub vcl_recv {
-		C{ VRT_CacheReqBody(ctx, 1000); }C
+		std.cache_req_body(1KB);
 		return (pass);
 	}
 	sub vcl_deliver {
diff --git a/bin/varnishtest/tests/c00067.vtc b/bin/varnishtest/tests/c00067.vtc
index d6d4c02..3c77433 100644
--- a/bin/varnishtest/tests/c00067.vtc
+++ b/bin/varnishtest/tests/c00067.vtc
@@ -31,8 +31,10 @@ client c1 {
 delay .2
 
 varnish v1 -cliok "param.set vcc_allow_inline_c true" -vcl+backend {
+	import ${vmod_std};
+
 	sub vcl_recv {
-		C{ VRT_CacheReqBody(ctx, 1000); }C
+		std.cache_req_body(1000B);
 	}
 }
 
diff --git a/lib/libvmod_std/vmod.vcc b/lib/libvmod_std/vmod.vcc
index b15a603..ad832d1 100644
--- a/lib/libvmod_std/vmod.vcc
+++ b/lib/libvmod_std/vmod.vcc
@@ -198,6 +198,14 @@ Description
 Example
         set req.url = std.querysort(req.url);
 
+$Function VOID cache_req_body(BYTES)
+
+Description
+       Cache the req.body if it is smaller than the given size
+Example
+       std.cache_req_body(1KB);
+
+       This will cache the req.body if its size is smaller than 1KB.
 
 $Function STRING strstr(STRING, STRING)
 
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index fd2bbbc..241196b 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -231,7 +231,6 @@ vmod_timestamp(const struct vrt_ctx *ctx, VCL_STRING label)
 	}
 }
 
-
 VCL_STRING __match_proto__(td_std_strstr)
 vmod_strstr(const struct vrt_ctx *ctx, VCL_STRING mstr, VCL_STRING msubstr)
 {
@@ -242,3 +241,12 @@ vmod_strstr(const struct vrt_ctx *ctx, VCL_STRING mstr, VCL_STRING msubstr)
 	else
 		return(strstr(mstr, msubstr));
 }
+
+VCL_VOID __match_proto__(td_std_cache_req_body)
+vmod_cache_req_body(const struct vrt_ctx *ctx, VCL_BYTES size)
+{
+	int result;
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+	result = VRT_CacheReqBody(ctx, size);
+	VSLb(ctx->vsl, SLT_Debug,"VRT_CacheReqBody[size: %zu] result: %d", (size_t)size, result);
+}



More information about the varnish-commit mailing list