r274 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Fri Jun 30 22:17:54 CEST 2006


Author: phk
Date: 2006-06-30 22:17:54 +0200 (Fri, 30 Jun 2006)
New Revision: 274

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_fetch.c
   trunk/varnish-cache/bin/varnishd/rfc2616.c
Log:
move all policy to rfc2616.c


Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2006-06-30 13:44:09 UTC (rev 273)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2006-06-30 20:17:54 UTC (rev 274)
@@ -105,6 +105,9 @@
 	/* HTTP request */
 	struct http		*http;
 
+	time_t			t_req;
+	time_t			t_resp;
+
 	unsigned 		handling;
 
 	TAILQ_ENTRY(sess)	list;
@@ -234,4 +237,4 @@
 #endif
 
 /* rfc2616.c */
-time_t RFC2616_Ttl(struct http *hp, time_t, time_t);
+int RFC2616_cache_policy(struct sess *sp, struct http *hp);

Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-06-30 13:44:09 UTC (rev 273)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c	2006-06-30 20:17:54 UTC (rev 274)
@@ -240,7 +240,6 @@
 	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 @@
 	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,33 +262,11 @@
 	 */
 	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;
-	}
+	body = RFC2616_cache_policy(sp, hp);
 
-	sp->obj->ttl = RFC2616_Ttl(hp, t_req, t_resp);
-	if (sp->obj->ttl == 0) {
-		sp->obj->cacheable = 0;
-	}
-
 	VCL_fetch_method(sp);
 
 	if (sp->obj->cacheable)

Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/rfc2616.c	2006-06-30 13:44:09 UTC (rev 273)
+++ trunk/varnish-cache/bin/varnishd/rfc2616.c	2006-06-30 20:17:54 UTC (rev 274)
@@ -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 @@
 
 	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);
+
+}
+




More information about the varnish-commit mailing list