[master] a7da0ca Make it possible to return synth from vcl_deliver{}

Poul-Henning Kamp phk at FreeBSD.org
Thu Jul 24 10:42:42 CEST 2014


commit a7da0caab86ef32861c5109080ab07777281828b
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Jul 24 08:40:02 2014 +0000

    Make it possible to return synth from vcl_deliver{}
    
    This is now possible because synth responses do not go through
    deliver any more, as error responses used to.
    
    Patch by:	Nils Goroll
    
    Much appreciated

diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index afc5e4d..e630160 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -137,11 +137,22 @@ cnt_deliver(struct worker *wrk, struct req *req)
 	if (req->restarts >= cache_param->max_restarts)
 		wrk->handling = VCL_RET_DELIVER;
 
-	if (wrk->handling == VCL_RET_RESTART) {
+	if (wrk->handling != VCL_RET_DELIVER) {
 		(void)HSH_DerefObj(&wrk->stats, &req->obj);
 		AZ(req->obj);
 		http_Teardown(req->resp);
-		req->req_step = R_STP_RESTART;
+
+		switch (wrk->handling) {
+		case VCL_RET_RESTART:
+			req->req_step = R_STP_RESTART;
+			break;
+		case VCL_RET_SYNTH:
+			req->req_step = R_STP_SYNTH;
+			break;
+		default:
+			INCOMPL();
+		}
+
 		return (REQ_FSM_MORE);
 	}
 
diff --git a/bin/varnishtest/tests/c00068.vtc b/bin/varnishtest/tests/c00068.vtc
new file mode 100644
index 0000000..817ec32
--- /dev/null
+++ b/bin/varnishtest/tests/c00068.vtc
@@ -0,0 +1,60 @@
+varnishtest "synth in deliver"
+
+server s1 {
+	rxreq
+	txresp -status 200
+	rxreq
+	txresp -status 200
+	rxreq
+	txresp -status 200
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_deliver {
+		if (req.url == "/332") {
+			return (synth(332, "FOO"));
+		} else if (req.url == "/333") {
+			return (synth(333, "FOO"));
+		} else {
+			return (synth(334, "BAR"));
+		}
+	}
+
+	sub vcl_synth {
+		if (resp.status == 333) {
+			set resp.http.connection = "close";
+		} else if (resp.status == 332) {
+			if (req.restarts == 0) {
+				return (restart);
+			} else {
+				set resp.http.restarts = req.restarts;
+				synthetic(req.restarts);
+			}
+		}
+		return (deliver);
+	}
+} -start
+
+client c1 {
+	txreq -url /334
+	rxresp
+	expect resp.status == 334
+
+	# cache hit
+	txreq -url /334
+	rxresp
+	expect resp.status == 334
+
+	txreq -url /333
+	rxresp
+	expect resp.status == 333
+	expect_close
+} -run
+
+client c2 {
+	txreq -url /332
+	rxresp
+	expect resp.status == 332
+	expect resp.http.restarts == 1
+	expect resp.bodylen == 1
+} -run
diff --git a/bin/varnishtest/tests/r01027.vtc b/bin/varnishtest/tests/r01027.vtc
deleted file mode 100644
index 716e6f0..0000000
--- a/bin/varnishtest/tests/r01027.vtc
+++ /dev/null
@@ -1,9 +0,0 @@
-varnishtest "Test if you can error in vcl_deliver"
-
-varnish v1 -errvcl {Invalid return "synth"} {
-	backend b { .host = "127.0.0.1"; }
-	sub vcl_deliver {
-		return (synth(201,"ok"));
-	}
-}
-
diff --git a/lib/libvcc/generate.py b/lib/libvcc/generate.py
index a1fd2d7..2906588 100755
--- a/lib/libvcc/generate.py
+++ b/lib/libvcc/generate.py
@@ -112,7 +112,7 @@ returns =(
 	),
 	('deliver',
 		"C",
-		('restart', 'deliver',)
+		('synth', 'restart', 'deliver',)
 	),
 	('synth',
 		"C",



More information about the varnish-commit mailing list