[master] a7be4ff straighten VRB_Cache / VRT_CacheReqBody corner cases, improve test

Nils Goroll nils.goroll at uplex.de
Wed Mar 4 14:39:26 CET 2015


commit a7be4ff8d790c52402e3e98efec1154a4b9ae1b6
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Wed Mar 4 13:39:13 2015 +0100

    straighten VRB_Cache / VRT_CacheReqBody corner cases, improve test
    
    - As VRB_Cache returns -1 upon error, so should VRT_CacheReqBody
    - 0 is a valid body size, so it shouldn't be used for signalling errors
    - VRB_Cache should return number of bytes when already cached
    - VRB_Cache: return -1 on insufficient bytes also

diff --git a/bin/varnishd/cache/cache_req_body.c b/bin/varnishd/cache/cache_req_body.c
index 8d20c98..5c8f08c 100644
--- a/bin/varnishd/cache/cache_req_body.c
+++ b/bin/varnishd/cache/cache_req_body.c
@@ -199,7 +199,7 @@ VRB_Cache(struct req *req, ssize_t maxsize)
 	assert (req->req_step == R_STP_RECV);
 	switch(req->req_body_status) {
 	case REQ_BODY_CACHED:
-		return (0);
+		return (req->req_bodybytes);
 	case REQ_BODY_FAIL:
 		return (-1);
 	case REQ_BODY_NONE:
@@ -279,5 +279,5 @@ VRB_Cache(struct req *req, ssize_t maxsize)
 		req->req_body_status = REQ_BODY_FAIL;
 	}
 	VSLb_ts_req(req, "ReqBody", VTIM_real());
-	return (vfps == VFP_END ? req->req_bodybytes : 0);
+	return (vfps == VFP_END ? req->req_bodybytes : -1);
 }
diff --git a/bin/varnishd/cache/cache_vrt.c b/bin/varnishd/cache/cache_vrt.c
index 8f972f1..6148b2b 100644
--- a/bin/varnishd/cache/cache_vrt.c
+++ b/bin/varnishd/cache/cache_vrt.c
@@ -486,7 +486,7 @@ VRT_CacheReqBody(VRT_CTX, long long maxsize)
 	if (ctx->method != VCL_MET_RECV) {
 		VSLb(ctx->vsl, SLT_VCL_Error,
 		    "req.body can only be cached in vcl_recv{}");
-		return (0);
+		return (-1);
 	}
 	return (VRB_Cache(ctx->req, maxsize));
 }
diff --git a/bin/varnishtest/tests/c00055.vtc b/bin/varnishtest/tests/c00055.vtc
index ebac77e..5f525d0 100644
--- a/bin/varnishtest/tests/c00055.vtc
+++ b/bin/varnishtest/tests/c00055.vtc
@@ -10,20 +10,35 @@ server s1 {
 	txresp -status 200 -hdr "Foo: Foo" -body "56"
 } -start
 
-varnish v1 -vcl+backend {
+varnish v1 -cliok "param.set vcc_allow_inline_c true" -vcl+backend {
 	import ${vmod_std};
 
 	sub vcl_recv {
 		std.cache_req_body(1KB);
+		C{
+			const struct gethdr_s HDR_REQ_X_BodyBytes =
+			    { HDR_REQ, "\014X-BodyBytes:"};
+			VRT_SetHdr(ctx, &HDR_REQ_X_BodyBytes,
+			    VRT_INT_string(ctx, VRT_CacheReqBody(ctx, 1024)),
+			    vrt_magic_string_end);
+		}C
 		return (pass);
 	}
 	sub vcl_deliver {
 		if (resp.http.foo == "BAR") {
 			return (restart);
 		}
+		set resp.http.X-BodyBytes = req.http.X-BodyBytes;
 	}
 } -start
 
+# check log for the aborted POST
+logexpect l1 -v v1 {
+	expect * 1006	Begin
+	expect * =	FetchError	"^straight insufficient bytes"
+	expect * =	ReqHeader	"^X-BodyBytes: -1"
+} -start
+
 varnish v1 -cliok "param.set debug +syncvsl"
 
 client c1 {
@@ -31,6 +46,7 @@ client c1 {
 	rxresp
 	expect resp.http.Foo == "Foo"
 	expect resp.bodylen == 2
+	expect resp.http.X-BodyBytes == 3
 } -run
 
 delay .1
@@ -51,4 +67,7 @@ client c1 {
 	txreq -url "/is_varnish_still_running"
 	rxresp
 	expect resp.status == 200
+	expect resp.http.X-BodyBytes == 0
 } -run
+varnish v1 -stop
+logexpect l1 -wait



More information about the varnish-commit mailing list