r4042 - in trunk/varnish-cache/bin: varnishd varnishtest/tests

phk at projects.linpro.no phk at projects.linpro.no
Wed Apr 29 11:18:03 CEST 2009


Author: phk
Date: 2009-04-29 11:18:02 +0200 (Wed, 29 Apr 2009)
New Revision: 4042

Added:
   trunk/varnish-cache/bin/varnishtest/tests/r00444.vtc
Modified:
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_http.c
Log:
Previously, we forced the request to "GET" on all fetches for cache
and this prevented users from implementing "purge on POST" semantics
by looking up the POST requests and ditching the object found.

Now we only overwrite the request with "GET" if it is a HEAD, (the
internal "wantbody" flag tells hos how the response should be composed.)

The testcase shold probably be elevated to VCL example, with suitable
footnotes about URL sanitizing etc.

Fixes #444



Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2009-04-29 08:04:26 UTC (rev 4041)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2009-04-29 09:18:02 UTC (rev 4042)
@@ -979,7 +979,12 @@
 		return (0);
 	}
 
-	sp->wantbody = (strcmp(sp->http->hd[HTTP_HDR_REQ].b, "HEAD") != 0);
+	if (!strcmp(sp->http->hd[HTTP_HDR_REQ].b, "HEAD")) {
+		sp->wantbody = 0;
+		http_ForceGet(sp->http);
+	} else
+		sp->wantbody = 1;
+
 	sp->sendbody = 0;
 	switch(sp->handling) {
 	case VCL_RET_LOOKUP:

Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2009-04-29 08:04:26 UTC (rev 4041)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2009-04-29 09:18:02 UTC (rev 4042)
@@ -555,23 +555,6 @@
 	to->hdf[n] = fm->hdf[n];
 }
 
-static void
-http_copyreq(struct http *to, const struct http *fm, int how)
-{
-
-	CHECK_OBJ_NOTNULL(fm, HTTP_MAGIC);
-	CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
-
-	if ((how == HTTPH_R_PIPE) || (how == HTTPH_R_PASS)) {
-		http_copyh(to, fm, HTTP_HDR_REQ);
-		http_copyh(to, fm, HTTP_HDR_PROTO);
-	} else {
-		http_SetH(to, HTTP_HDR_REQ, "GET");
-		http_SetH(to, HTTP_HDR_PROTO, "HTTP/1.1");
-	}
-	http_copyh(to, fm, HTTP_HDR_URL);
-}
-
 void
 http_ForceGet(struct http *to)
 {
@@ -660,7 +643,12 @@
 	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
 	hp->logtag = HTTP_Tx;
 
-	http_copyreq(hp, sp->http, how);
+	http_copyh(hp, sp->http, HTTP_HDR_REQ);
+	http_copyh(hp, sp->http, HTTP_HDR_URL);
+	if (how == HTTPH_R_FETCH)
+		http_SetH(hp, HTTP_HDR_PROTO, "HTTP/1.1");
+	else
+		http_copyh(hp, sp->http, HTTP_HDR_PROTO);
 	http_FilterFields(sp->wrk, sp->fd, hp, sp->http, how);
 	http_PrintfHeader(sp->wrk, sp->fd, hp, "X-Varnish: %u", sp->xid);
 	http_PrintfHeader(sp->wrk, sp->fd, hp,

Added: trunk/varnish-cache/bin/varnishtest/tests/r00444.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/r00444.vtc	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/r00444.vtc	2009-04-29 09:18:02 UTC (rev 4042)
@@ -0,0 +1,62 @@
+# $Id$
+
+test "purging on POST"
+
+server s1 {
+	rxreq
+	expect req.request == "GET"
+	txresp -body "1"
+
+	rxreq
+	expect req.request == "POST"
+	txresp -body "22"
+
+	rxreq
+	expect req.request == "POST"
+	txresp -body "333"
+
+	rxreq
+	expect req.request == "GET"
+	txresp -body "4444"
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_recv {
+		if (req.request == "POST") {
+			/* Lookup so we find any cached object */
+			lookup;
+		}
+	}
+	sub vcl_hit {
+		if (req.request == "POST") {
+			/* Get rid of this object */
+			set obj.cacheable = false;
+			set obj.ttl = 0s;
+			pass;
+		}
+	}
+	sub vcl_miss {
+		if (req.request == "POST") {
+			/* Make sure we don't cache the POST result */
+			pass;
+		}
+	}
+} -start
+
+client c1 {
+	txreq
+	rxresp
+	expect resp.bodylen == 1
+
+	txreq -req POST
+	rxresp
+	expect resp.bodylen == 2
+
+	txreq -req POST
+	rxresp
+	expect resp.bodylen == 3
+
+	txreq
+	rxresp
+	expect resp.bodylen == 4
+} -run



More information about the varnish-commit mailing list