From 4347510df719580adae1dc4a339196c20413c63c Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 16 Jun 2006 10:18:08 +0000 Subject: [PATCH] The beginnings of rfc2616 policy implemenation. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@191 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/Makefile.am | 1 + varnish-cache/bin/varnishd/rfc2616.c | 76 ++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 varnish-cache/bin/varnishd/rfc2616.c diff --git a/varnish-cache/bin/varnishd/Makefile.am b/varnish-cache/bin/varnishd/Makefile.am index 8a23a035..b56b34e9 100644 --- a/varnish-cache/bin/varnishd/Makefile.am +++ b/varnish-cache/bin/varnishd/Makefile.am @@ -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 index 00000000..c0d5d008 --- /dev/null +++ b/varnish-cache/bin/varnishd/rfc2616.c @@ -0,0 +1,76 @@ +/* + * $Id$ + */ + +#include +#include +#include +#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); + + +} -- 2.39.5