]> err.no Git - varnish/commitdiff
The beginnings of rfc2616 policy implemenation.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 16 Jun 2006 10:18:08 +0000 (10:18 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 16 Jun 2006 10:18:08 +0000 (10:18 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@191 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/Makefile.am
varnish-cache/bin/varnishd/rfc2616.c [new file with mode: 0644]

index 8a23a035ed4338f436566711c2d310bb38cb1b68..b56b34e9d5707f8a55b527d3b55df79154f20a94 100644 (file)
@@ -18,6 +18,7 @@ varnishd_SOURCES = \
        cli_event.c \
        hash_simple_list.c \
        mgt_child.c \
+       rfc2616.c \
        storage_file.c \
        storage_malloc.c \
        tcp.c \
diff --git a/varnish-cache/bin/varnishd/rfc2616.c b/varnish-cache/bin/varnishd/rfc2616.c
new file mode 100644 (file)
index 0000000..c0d5d00
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * $Id$
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include "vcl_lang.h"
+
+#include "cache.h"
+#include "libvarnish.h"
+
+/*--------------------------------------------------------------------
+ * From RFC2616, 13.2.3 Age Calculations
+ *
+ * age_value
+ *      is the value of Age: header received by the cache with
+ *      this response.
+ * date_value
+ *      is the value of the origin server's Date: header
+ * request_time
+ *      is the (local) time when the cache made the request
+ *      that resulted in this cached response
+ * response_time
+ *      is the (local) time when the cache received the response
+ * now
+ *      is the current (local) time
+ *
+ * apparent_age = max(0, response_time - date_value);
+ * corrected_received_age = max(apparent_age, age_value);
+ * response_delay = response_time - request_time;
+ * corrected_initial_age = corrected_received_age + response_delay;
+ * resident_time = now - response_time;
+ * current_age   = corrected_initial_age + resident_time;
+ *
+ */
+
+void
+RFC2616_Age(struct http *hp, time_t t_req, time_t t_resp)
+{
+       time_t h_date = 0, h_expires = 0, h_age = 0;
+       time_t apparent_age = 0, corrected_received_age;
+       time_t response_delay, corrected_initial_age;
+       time_t max_age = -1;
+       char *p;
+
+       if (http_GetHdrField(hp, "Cache-Control", "max-age", &p))
+               max_age = strtoul(p, NULL, 0);
+
+       if (http_GetHdr(hp, "Date", &p))
+               h_date = TIM_parse(p);
+
+       if (h_date < t_resp)
+               apparent_age = t_resp - h_date;
+
+       if (http_GetHdr(hp, "Age", &p))
+               h_age = strtoul(p, NULL, 0);
+
+       if (h_age > apparent_age)
+               corrected_received_age = h_age;
+       else
+               corrected_received_age = apparent_age;
+
+       response_delay = t_resp - t_req;
+       corrected_initial_age = corrected_received_age + response_delay;
+
+       if (http_GetHdr(hp, "Expires", &p))
+               h_expires = TIM_parse(p);
+
+       printf("Date: %d\n", h_date);
+       printf("Expires: %d\n", h_expires);
+       printf("Age: %d\n", h_age);
+       printf("CIAge: %d\n", corrected_initial_age);
+
+
+}