[master] a7c1871 Round down synthesized last-modified timestamp in object

Tollef Fog Heen tfheen at varnish-cache.org
Tue May 3 10:18:13 CEST 2011


commit a7c18717f45390231bf62cfedcf805458b26ca26
Author: Tollef Fog Heen <tfheen at varnish-software.com>
Date:   Tue May 3 10:12:08 2011 +0200

    Round down synthesized last-modified timestamp in object
    
    Commit 3bd239e9b2361c96b1acf1c03bce9c50baaf838d makes it so we set the
    object's last-modified timestamp to the current timestamp if there's
    no Last-Modified header.  This makes it so we can do conditional gets
    even when there's no Last-Modified or ETag header from the backend.
    However, the time entered was a float, so we effectively ended up with
    an off-by-up-to-one-minus-epsilon error.  This lead to requests ending
    up in a 304/200 response code round-dance.
    
    We now round the timestamp down to the nearest whole second instead,
    which should fix this bug.  Thanks to lrowe for a helpful bug report.
    
    Fixes: #907

diff --git a/bin/varnishd/cache_center.c b/bin/varnishd/cache_center.c
index ac86da0..edfe75d 100644
--- a/bin/varnishd/cache_center.c
+++ b/bin/varnishd/cache_center.c
@@ -785,7 +785,7 @@ cnt_fetchbody(struct sess *sp)
 	if (http_GetHdr(hp, H_Last_Modified, &b))
 		sp->obj->last_modified = TIM_parse(b);
 	else
-		sp->obj->last_modified = sp->wrk->entered;
+		sp->obj->last_modified = floor(sp->wrk->entered);
 
 	assert(WRW_IsReleased(sp->wrk));
 
diff --git a/bin/varnishtest/tests/r00907.vtc b/bin/varnishtest/tests/r00907.vtc
new file mode 100644
index 0000000..8bbcd2e
--- /dev/null
+++ b/bin/varnishtest/tests/r00907.vtc
@@ -0,0 +1,23 @@
+varnishtest "Ticket #907 200/304 handling with Etags + Last-Modified"
+
+server s1 {
+	rxreq 
+	txresp \
+	       -hdr "ETag: saengei1Ohshicich4iteesu"
+} -start
+
+varnish v1 -vcl+backend {
+	sub vcl_deliver {
+		set resp.http.x-timestamp = now;
+	}
+} -start 
+
+client c1 {
+	txreq -hdr "If-None-Match: saengei1Ohshicich4iteesu"
+	rxresp
+	expect resp.status == 304
+	txreq -hdr "If-None-Match: saengei1Ohshicich4iteesu" \
+	      -hdr "If-Modified-Since: ${date}"
+	rxresp
+	expect resp.status == 304
+} -run



More information about the varnish-commit mailing list