]> err.no Git - varnish/commitdiff
move all policy to rfc2616.c
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 30 Jun 2006 20:17:54 +0000 (20:17 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 30 Jun 2006 20:17:54 +0000 (20:17 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@274 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_fetch.c
varnish-cache/bin/varnishd/rfc2616.c

index a4e378741ba4ce1dd266a221aab2d77f0ecaa464..7736f5722e7fb46f86a1710e645a6e1f030609c4 100644 (file)
@@ -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);
index 72d45a44b68d3425bc6c8e9277e3e793752bbcd8..d1382841958d69fb487594d21ed76a7c9a5e3728 100644 (file)
@@ -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);
 
index 7dcf08e81bcab5f3b970a479362837971ad68ddd..fdfe1649956db38fea1f336440e93f7957de43b7 100644 (file)
@@ -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);
+
+}
+