From 11f042962882c8f519f1168f87e364e39f61bed9 Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 30 Jun 2006 20:17:54 +0000 Subject: [PATCH] move all policy to rfc2616.c git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@274 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache.h | 5 +++- varnish-cache/bin/varnishd/cache_fetch.c | 29 ++---------------- varnish-cache/bin/varnishd/rfc2616.c | 38 ++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache.h b/varnish-cache/bin/varnishd/cache.h index a4e37874..7736f572 100644 --- a/varnish-cache/bin/varnishd/cache.h +++ b/varnish-cache/bin/varnishd/cache.h @@ -105,6 +105,9 @@ struct sess { /* HTTP request */ struct http *http; + time_t t_req; + time_t t_resp; + unsigned handling; TAILQ_ENTRY(sess) list; @@ -234,4 +237,4 @@ cli_func_t cli_func_config_use; #endif /* rfc2616.c */ -time_t RFC2616_Ttl(struct http *hp, time_t, time_t); +int RFC2616_cache_policy(struct sess *sp, struct http *hp); diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 72d45a44..d1382841 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -240,7 +240,6 @@ FetchSession(struct worker *w, struct sess *sp) void *fd_token; struct http *hp; char *b; - time_t t_req, t_resp; int body; sp->obj->xid = sp->xid; @@ -253,7 +252,7 @@ FetchSession(struct worker *w, struct sess *sp) http_BuildSbuf(fd, 1, w->sb, sp->http); i = write(fd, sbuf_data(w->sb), sbuf_len(w->sb)); assert(i == sbuf_len(w->sb)); - time(&t_req); + time(&sp->t_req); /* XXX: copy any contents */ @@ -263,32 +262,10 @@ FetchSession(struct worker *w, struct sess *sp) */ http_RecvHead(hp, fd, w->eb, NULL, NULL); event_base_loop(w->eb, 0); - time(&t_resp); + time(&sp->t_resp); http_Dissect(hp, fd, 2); - switch (http_GetStatus(hp)) { - case 200: - case 301: - /* XXX: fill in object from headers */ - sp->obj->valid = 1; - sp->obj->cacheable = 1; - body = 1; - break; - case 304: - /* XXX: fill in object from headers */ - sp->obj->valid = 1; - sp->obj->cacheable = 1; - body = 0; - break; - default: - body = 0; - break; - } - - sp->obj->ttl = RFC2616_Ttl(hp, t_req, t_resp); - if (sp->obj->ttl == 0) { - sp->obj->cacheable = 0; - } + body = RFC2616_cache_policy(sp, hp); VCL_fetch_method(sp); diff --git a/varnish-cache/bin/varnishd/rfc2616.c b/varnish-cache/bin/varnishd/rfc2616.c index 7dcf08e8..fdfe1649 100644 --- a/varnish-cache/bin/varnishd/rfc2616.c +++ b/varnish-cache/bin/varnishd/rfc2616.c @@ -9,7 +9,6 @@ #include "cache.h" #include "libvarnish.h" #include "heritage.h" - /*-------------------------------------------------------------------- * From RFC2616, 13.2.3 Age Calculations * @@ -35,7 +34,7 @@ * */ -time_t +static time_t RFC2616_Ttl(struct http *hp, time_t t_req, time_t t_resp) { time_t h_date = 0, h_expires = 0, h_age = 0; @@ -94,3 +93,38 @@ RFC2616_Ttl(struct http *hp, time_t t_req, time_t t_resp) return (ttl); } + +int +RFC2616_cache_policy(struct sess *sp, struct http *hp) +{ + int body = 0; + + /* + * Initial cacheability determination per [RFC2616, 13.4] + * We do not support ranges yet, so 206 is out. + */ + switch (http_GetStatus(hp)) { + case 200: /* OK */ + sp->obj->valid = 1; + case 203: /* Non-Authoritative Information */ + case 300: /* Multiple Choices */ + case 301: /* Moved Permanently */ + case 410: /* Gone */ + sp->obj->cacheable = 1; + body = 1; + break; + default: + sp->obj->cacheable = 0; + body = 0; + break; + } + + sp->obj->ttl = RFC2616_Ttl(hp, sp->t_req, sp->t_resp); + if (sp->obj->ttl == 0) { + sp->obj->cacheable = 0; + } + + return (body); + +} + -- 2.39.5