r4115 - in branches/sky/if-none-match/varnish-cache/bin: varnishd varnishtest/tests
sky at projects.linpro.no
sky at projects.linpro.no
Wed Jun 17 15:28:17 CEST 2009
Author: sky
Date: 2009-06-17 15:28:16 +0200 (Wed, 17 Jun 2009)
New Revision: 4115
Added:
branches/sky/if-none-match/varnish-cache/bin/varnishtest/tests/c00025.vtc
branches/sky/if-none-match/varnish-cache/bin/varnishtest/tests/c00026.vtc
Modified:
branches/sky/if-none-match/varnish-cache/bin/varnishd/cache_response.c
Log:
Add if-none-match support to allow people with compliant browsers to save a decent chunk of bandwidth
Modified: branches/sky/if-none-match/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- branches/sky/if-none-match/varnish-cache/bin/varnishd/cache_response.c 2009-06-17 13:18:56 UTC (rev 4114)
+++ branches/sky/if-none-match/varnish-cache/bin/varnishd/cache_response.c 2009-06-17 13:28:16 UTC (rev 4115)
@@ -57,8 +57,10 @@
http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, "Date: %s", lm);
http_SetHeader(sp->wrk, sp->fd, sp->wrk->resp, "Via: 1.1 varnish");
http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, "X-Varnish: %u", sp->xid);
- TIM_format(sp->obj->last_modified, lm);
- http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, "Last-Modified: %s", lm);
+ if (sp->obj->last_modified) {
+ TIM_format(sp->obj->last_modified, lm);
+ http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, "Last-Modified: %s", lm);
+ }
http_PrintfHeader(sp->wrk, sp->fd, sp->wrk->resp, "Connection: %s",
sp->doclose ? "close" : "keep-alive");
sp->wantbody = 0;
@@ -69,17 +71,33 @@
static int
res_do_conds(struct sess *sp)
{
- char *p;
+ char *p, *e;
double ims;
+ int do_cond = 0;
- if (sp->obj->last_modified > 0 &&
- http_GetHdr(sp->http, H_If_Modified_Since, &p)) {
+ /* RFC 2616 13.3.4 states we need to match both ETag
+ and If-Modified-Since if present*/
+
+ if (http_GetHdr(sp->http, H_If_Modified_Since, &p) ) {
+ if (!sp->obj->last_modified)
+ return (0);
ims = TIM_parse(p);
if (ims > sp->t_req) /* [RFC2616 14.25] */
return (0);
if (sp->obj->last_modified > ims) {
return (0);
}
+ do_cond = 1;
+ }
+
+ if (http_GetHdr(sp->http, H_If_None_Match, &p) &&
+ http_GetHdr(sp->obj->http, H_ETag, &e)) {
+ if (strcmp(p,e) != 0)
+ return (0);
+ do_cond = 1;
+ }
+
+ if (do_cond == 1) {
res_do_304(sp);
return (1);
}
Added: branches/sky/if-none-match/varnish-cache/bin/varnishtest/tests/c00025.vtc
===================================================================
--- branches/sky/if-none-match/varnish-cache/bin/varnishtest/tests/c00025.vtc (rev 0)
+++ branches/sky/if-none-match/varnish-cache/bin/varnishtest/tests/c00025.vtc 2009-06-17 13:28:16 UTC (rev 4115)
@@ -0,0 +1,33 @@
+# $Id$
+
+test "Test If-None-Match"
+
+server s1 {
+ rxreq
+ expect req.url == "/foo"
+ txresp -hdr "ETag: 123456789" \
+ -body "11111\n"
+} -start
+
+varnish v1 -vcl+backend { } -start
+
+client c1 {
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.content-length == 6
+
+ txreq -url "/foo" \
+ -hdr "If-None-Match: 12345678"
+ rxresp
+ expect resp.status == 200
+
+ txreq -url "/foo" \
+ -hdr "If-None-Match: 123456789"
+ rxresp
+ expect resp.status == 304
+}
+
+client c1 -run
+
+client c1 -run
Added: branches/sky/if-none-match/varnish-cache/bin/varnishtest/tests/c00026.vtc
===================================================================
--- branches/sky/if-none-match/varnish-cache/bin/varnishtest/tests/c00026.vtc (rev 0)
+++ branches/sky/if-none-match/varnish-cache/bin/varnishtest/tests/c00026.vtc 2009-06-17 13:28:16 UTC (rev 4115)
@@ -0,0 +1,53 @@
+# $Id$
+
+test "Test Combination of If-None-Match and If-Modified-Since"
+
+server s1 {
+ rxreq
+ expect req.url == "/foo"
+ txresp -hdr "ETag: 123456789" \
+ -hdr "Last-Modified: Thu, 26 Jun 2008 12:00:01 GMT" \
+ -body "11111\n"
+} -start
+
+varnish v1 -vcl+backend { } -start
+
+client c1 {
+ txreq -url "/foo"
+ rxresp
+ expect resp.status == 200
+ expect resp.http.content-length == 6
+
+ txreq -url "/foo" \
+ -hdr "If-None-Match: 123456789"
+ rxresp
+ expect resp.status == 304
+
+ txreq -url "/foo" \
+ -hdr "If-Modified-Since: Thu, 26 Jun 2008 12:00:01 GMT"
+ rxresp
+ expect resp.status == 304
+
+ txreq -url "/foo" \
+ -hdr "If-Modified-Since: Thu, 26 Jun 2008 12:00:00 GMT" \
+ -hdr "If-None-Match: 123456789"
+ rxresp
+ expect resp.status == 200
+
+ txreq -url "/foo" \
+ -hdr "If-Modified-Since: Thu, 26 Jun 2008 12:00:01 GMT" \
+ -hdr "If-None-Match: 12345678"
+ rxresp
+ expect resp.status == 200
+
+ txreq -url "/foo" \
+ -hdr "If-Modified-Since: Thu, 26 Jun 2008 12:00:01 GMT" \
+ -hdr "If-None-Match: 123456789"
+ rxresp
+ expect resp.status == 304
+
+}
+
+client c1 -run
+
+client c1 -run
More information about the varnish-commit
mailing list