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

phk at projects.linpro.no phk at projects.linpro.no
Tue Oct 6 10:31:57 CEST 2009


Author: phk
Date: 2009-10-06 10:31:57 +0200 (Tue, 06 Oct 2009)
New Revision: 4277

Added:
   trunk/varnish-cache/bin/varnishtest/tests/p00006.vtc
Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_center.c
   trunk/varnish-cache/bin/varnishd/cache_hash.c
   trunk/varnish-cache/bin/varnishd/cache_vary.c
Log:
Move the Vary specification into the object worksspace instead of
using malloc space.

Otherwise -spersistent would resurrect objects without their Vary
specifications.


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2009-10-06 08:10:38 UTC (rev 4276)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2009-10-06 08:31:57 UTC (rev 4277)
@@ -652,7 +652,7 @@
 void RES_WriteObj(struct sess *sp);
 
 /* cache_vary.c */
-void VRY_Create(const struct sess *sp);
+struct vsb *VRY_Create(const struct sess *sp, struct http *hp);
 int VRY_Match(const struct sess *sp, const unsigned char *vary);
 
 /* cache_vcl.c */

Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c	2009-10-06 08:10:38 UTC (rev 4276)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c	2009-10-06 08:31:57 UTC (rev 4277)
@@ -420,6 +420,7 @@
 	struct http *hp, *hp2;
 	char *b;
 	unsigned handling, l;
+	struct vsb *vary;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(sp->vcl, VCL_CONF_MAGIC);
@@ -515,13 +516,18 @@
 	if (sp->wrk->cacheable) {
 		CHECK_OBJ_NOTNULL(sp->objhead, OBJHEAD_MAGIC);
 		CHECK_OBJ_NOTNULL(sp->objcore, OBJCORE_MAGIC);
+		vary = VRY_Create(sp, sp->wrk->beresp);
 	} else {
 		AZ(sp->objhead);
 		AZ(sp->objcore);
+		vary = NULL;
 	}
 
 	l = http_EstimateWS(sp->wrk->beresp, HTTPH_A_INS);
 
+	if (vary != NULL)
+		l += vsb_len(vary);
+
 	/* Space for producing a Content-Length: header */
 	l += 30;
 
@@ -543,6 +549,15 @@
 		BAN_NewObj(sp->obj);
 	}
 
+	if (vary != NULL) {
+		sp->obj->vary =
+		    (void *)WS_Alloc(sp->obj->http->ws, vsb_len(vary));
+		AN(sp->obj->vary);
+		memcpy(sp->obj->vary, vsb_data(vary), vsb_len(vary));
+		vsb_delete(vary);
+		vary = NULL;
+	}
+
 	sp->obj->xid = sp->xid;
 	sp->obj->response = sp->err_code;
 	sp->obj->cacheable = sp->wrk->cacheable;
@@ -619,7 +634,6 @@
 
 	sp->obj->cacheable = 1;
 	if (sp->wrk->cacheable) {
-		VRY_Create(sp);
 		EXP_Insert(sp->obj);
 		AN(sp->obj->ban);
 		HSH_Unbusy(sp);

Modified: trunk/varnish-cache/bin/varnishd/cache_hash.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-10-06 08:10:38 UTC (rev 4276)
+++ trunk/varnish-cache/bin/varnishd/cache_hash.c	2009-10-06 08:31:57 UTC (rev 4277)
@@ -701,9 +701,6 @@
 	DSL(0x40, SLT_Debug, 0, "Object %u workspace min free %u",
 	    o->xid, WS_Free(o->ws_o));
 
-	if (o->vary != NULL)
-		free(o->vary);
-
 	ESI_Destroy(o);
 	if (o->objcore != NULL && o->objcore->smp_seg != NULL) {
 		SMP_FreeObj(o);

Modified: trunk/varnish-cache/bin/varnishd/cache_vary.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_vary.c	2009-10-06 08:10:38 UTC (rev 4276)
+++ trunk/varnish-cache/bin/varnishd/cache_vary.c	2009-10-06 08:31:57 UTC (rev 4277)
@@ -63,16 +63,16 @@
 
 #include "cache.h"
 
-void
-VRY_Create(const struct sess *sp)
+struct vsb *
+VRY_Create(const struct sess *sp, struct http *hp)
 {
 	char *v, *p, *q, *h, *e;
 	struct vsb *sb, *sbh;
 	int l;
 
 	/* No Vary: header, no worries */
-	if (!http_GetHdr(sp->obj->http, H_Vary, &v))
-		return;
+	if (!http_GetHdr(hp, H_Vary, &v))
+		return (NULL);
 
 	/* For vary matching string */
 	sb = vsb_newauto();
@@ -126,16 +126,10 @@
 	/* Terminate vary matching string */
 	vsb_printf(sb, "%c", 0);
 
+	vsb_delete(sbh);
 	vsb_finish(sb);
 	AZ(vsb_overflowed(sb));
-	l = vsb_len(sb);
-	assert(l >= 0);
-	sp->obj->vary = malloc(l);
-	AN(sp->obj->vary);
-	memcpy(sp->obj->vary, vsb_data(sb), l);
-
-	vsb_delete(sb);
-	vsb_delete(sbh);
+	return(sb);
 }
 
 int

Added: trunk/varnish-cache/bin/varnishtest/tests/p00006.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/p00006.vtc	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/p00006.vtc	2009-10-06 08:31:57 UTC (rev 4277)
@@ -0,0 +1,56 @@
+# $Id$
+
+test "Check that Vary headers are stored"
+
+shell "rm -f /tmp/__v1/_.per"
+
+server s1 {
+	rxreq 
+	txresp -hdr "Foo: foo1" -hdr "Vary: foo, bar"
+	rxreq 
+	txresp -hdr "Foo: foo2" -hdr "Vary: foo, bar"
+} -start
+
+
+varnish v1 \
+	-arg "-spersistent,/tmp/__v1/_.per,10m" \
+	-vcl+backend { } -start 
+
+client c1 {
+	txreq -url "/foo" -hdr "foo: 1" -hdr "bar: 2"
+	rxresp
+	expect resp.status == 200
+	expect resp.http.X-Varnish == "1001"
+	expect resp.http.foo == "foo1"
+
+	txreq -url "/foo" -hdr "foo: 2" -hdr "bar: 1"
+	rxresp
+	expect resp.status == 200
+	expect resp.http.X-Varnish == "1002"
+	expect resp.http.foo == "foo2"
+
+} -run
+
+varnish v1 -expect n_object == 2
+server s1 -wait
+
+varnish v1 -stop
+varnish v1 -start
+
+varnish v1 -expect n_vampireobject == 2
+
+client c1 {
+	txreq -url "/foo" -hdr "foo: 1" -hdr "bar: 2"
+	rxresp
+	expect resp.status == 200
+	#expect resp.http.X-Varnish == "1001"
+	expect resp.http.foo == "foo1"
+
+	txreq -url "/foo" -hdr "foo: 2" -hdr "bar: 1"
+	rxresp
+	expect resp.status == 200
+	#expect resp.http.X-Varnish == "1002"
+	expect resp.http.foo == "foo2"
+
+} -run
+



More information about the varnish-commit mailing list