[master] cc2b4c4 Add std.cache_req_body to call VRT_CacheReqBody from VCL

Nils Goroll nils.goroll at uplex.de
Fri Sep 19 11:41:45 CEST 2014


commit cc2b4c4d1a14dcdfe1a9f01a9797cbea396c581b
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

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 5bcc403..fbc082b 100644
--- a/lib/libvmod_std/vmod.vcc
+++ b/lib/libvmod_std/vmod.vcc
@@ -199,6 +199,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.
 
 
 SEE ALSO
diff --git a/lib/libvmod_std/vmod_std.c b/lib/libvmod_std/vmod_std.c
index 1aaec4c..55a574e 100644
--- a/lib/libvmod_std/vmod_std.c
+++ b/lib/libvmod_std/vmod_std.c
@@ -230,3 +230,12 @@ vmod_timestamp(const struct vrt_ctx *ctx, VCL_STRING label)
 		VSLb_ts_req(ctx->req, label, VTIM_real());
 	}
 }
+
+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