Commit 89b4d2e5 authored by Artur Bergman's avatar Artur Bergman

merge r:4112:4144 if-none-match support

git-svn-id: http://www.varnish-cache.org/svn/trunk@4146 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 8dd0729d
......@@ -57,8 +57,10 @@ res_do_304(struct sess *sp)
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 @@ res_do_304(struct sess *sp)
static int
res_do_conds(struct sess *sp)
{
char *p;
char *p, *e;
double ims;
int do_cond = 0;
/* RFC 2616 13.3.4 states we need to match both ETag
and If-Modified-Since if present*/
if (sp->obj->last_modified > 0 &&
http_GetHdr(sp->http, H_If_Modified_Since, &p)) {
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);
}
......
# $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
# $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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment