r4295 - in branches/2.0/varnish-cache/bin: varnishd varnishtest/tests

tfheen at projects.linpro.no tfheen at projects.linpro.no
Thu Oct 8 14:26:18 CEST 2009


Author: tfheen
Date: 2009-10-08 14:26:18 +0200 (Thu, 08 Oct 2009)
New Revision: 4295

Modified:
   branches/2.0/varnish-cache/bin/varnishd/cache_response.c
   branches/2.0/varnish-cache/bin/varnishtest/tests/c00008.vtc
Log:
Merge r4150: Emit more headers when hitting 304

When hitting 304, ETag, Content-Location, Expires, Cache-control and
Vary should all be sent to the client.

See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
for some more details

Thanks to Rog?\195?\169rio Schneider for the patch.

Fixes #529



Modified: branches/2.0/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- branches/2.0/varnish-cache/bin/varnishd/cache_response.c	2009-10-08 12:05:56 UTC (rev 4294)
+++ branches/2.0/varnish-cache/bin/varnishd/cache_response.c	2009-10-08 12:26:18 UTC (rev 4295)
@@ -46,6 +46,7 @@
 res_do_304(struct sess *sp)
 {
 	char lm[64];
+	char *p;
 
 	WSP(sp, SLT_Length, "%u", 0);
 
@@ -60,6 +61,19 @@
 		TIM_format(sp->obj->last_modified, lm);
 		http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Last-Modified: %s", lm);
 	}
+
+	/* http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5 */
+	if (http_GetHdr(sp->obj->http, H_Cache_Control, &p))
+		http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Cache-Control: %s", p);
+	if (http_GetHdr(sp->obj->http, H_Content_Location, &p))
+		http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Content-Location: %s", p);
+	if (http_GetHdr(sp->obj->http, H_ETag, &p))
+		http_PrintfHeader(sp->wrk, sp->fd, sp->http, "ETag: %s", p);
+	if (http_GetHdr(sp->obj->http, H_Expires, &p))
+		http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Expires: %s", p);
+	if (http_GetHdr(sp->obj->http, H_Vary, &p))
+		http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Vary: %s", p);
+
 	http_PrintfHeader(sp->wrk, sp->fd, sp->http, "Connection: %s",
 	    sp->doclose ? "close" : "keep-alive");
 	sp->wantbody = 0;

Modified: branches/2.0/varnish-cache/bin/varnishtest/tests/c00008.vtc
===================================================================
--- branches/2.0/varnish-cache/bin/varnishtest/tests/c00008.vtc	2009-10-08 12:05:56 UTC (rev 4294)
+++ branches/2.0/varnish-cache/bin/varnishtest/tests/c00008.vtc	2009-10-08 12:26:18 UTC (rev 4295)
@@ -6,6 +6,7 @@
 	rxreq
 	expect req.url == "/foo"
 	txresp -hdr "Last-Modified: Thu, 26 Jun 2008 12:00:01 GMT" \
+	    -hdr "ETag: foo" \
 	    -body "11111\n"
 } -start
 
@@ -15,22 +16,26 @@
 	txreq -url "/foo"
 	rxresp
 	expect resp.status == 200
+	expect resp.http.etag == "foo"
 	expect resp.http.content-length == 6
 
 	txreq -url "/foo" \
 	    -hdr "If-Modified-Since: Thu, 26 Jun 2008 12:00:00 GMT"
 	rxresp
 	expect resp.status == 200
+	expect resp.http.etag == "foo"
 
 	txreq -url "/foo" \
 	    -hdr "If-Modified-Since: Thu, 26 Jun 2008 12:00:01 GMT"
 	rxresp
 	expect resp.status == 304
+	expect resp.http.etag == "foo"
 
 	txreq -url "/foo" \
 	    -hdr "If-Modified-Since: Thu, 26 Jun 2008 12:00:02 GMT"
 	rxresp
 	expect resp.status == 304
+	expect resp.http.etag == "foo"
 } 
 
 client c1 -run



More information about the varnish-commit mailing list