r315 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Wed Jul 5 11:44:53 CEST 2006
Author: phk
Date: 2006-07-05 11:44:53 +0200 (Wed, 05 Jul 2006)
New Revision: 315
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_acceptor.c
trunk/varnish-cache/bin/varnishd/cache_fetch.c
trunk/varnish-cache/bin/varnishd/cache_pool.c
trunk/varnish-cache/bin/varnishd/rfc2616.c
Log:
Add Age and Via header to responses.
Change arguments to vca_write_obj() (It should really be "send_repsonse()" ?)
Store received age and time entered into cache in object.
Generate Age: and Via: headers as part of response.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2006-07-05 09:32:12 UTC (rev 314)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2006-07-05 09:44:53 UTC (rev 315)
@@ -67,6 +67,9 @@
unsigned busy;
unsigned len;
+
+ time_t age;
+ time_t entered;
time_t ttl;
char *header;
@@ -133,7 +136,7 @@
/* cache_acceptor.c */
void vca_write(struct sess *sp, void *ptr, size_t len);
-void vca_write_obj(struct sess *sp, char *b, unsigned l);
+void vca_write_obj(struct worker *w, struct sess *sp);
void vca_flush(struct sess *sp);
void vca_return_session(struct sess *sp);
void vca_close_session(struct sess *sp, const char *why);
Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2006-07-05 09:32:12 UTC (rev 314)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c 2006-07-05 09:44:53 UTC (rev 315)
@@ -85,18 +85,25 @@
}
void
-vca_write_obj(struct sess *sp, char *b, unsigned l)
+vca_write_obj(struct worker *w, struct sess *sp)
{
struct storage *st;
unsigned u = 0;
char *r;
+
VSL(SLT_Response, sp->fd, "%u", sp->obj->response);
VSL(SLT_Length, sp->fd, "%u", sp->obj->len);
- if (l == 0)
- l = strlen(b);
- vca_write(sp, b, l);
+ vca_write(sp, sp->obj->header, strlen(sp->obj->header));
+
+ sbuf_clear(w->sb);
+ sbuf_printf(w->sb, "Age: %u\r\n",
+ sp->obj->age + sp->t_req - sp->obj->entered);
+ sbuf_printf(w->sb, "Via: 1.1 varnish\r\n");
+ sbuf_printf(w->sb, "\r\n");
+ sbuf_finish(w->sb);
+ vca_write(sp, sbuf_data(w->sb), sbuf_len(w->sb));
assert(http_GetReq(sp->http, &r));
if (!strcmp(r, "GET")) {
TAILQ_FOREACH(st, &sp->obj->store, list) {
Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2006-07-05 09:32:12 UTC (rev 314)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2006-07-05 09:44:53 UTC (rev 315)
@@ -285,11 +285,10 @@
sbuf_printf(w->sb, "Content-Length: %u\r\n", sp->obj->len);
} else
cls = 0;
- sbuf_cat(w->sb, "\r\n");
sbuf_finish(w->sb);
sp->obj->header = strdup(sbuf_data(w->sb));
- vca_write_obj(sp, sp->obj->header, 0);
+ vca_write_obj(w, sp);
if (http_GetHdr(hp, "Connection", &b) && !strcasecmp(b, "close"))
cls = 1;
Modified: trunk/varnish-cache/bin/varnishd/cache_pool.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pool.c 2006-07-05 09:32:12 UTC (rev 314)
+++ trunk/varnish-cache/bin/varnishd/cache_pool.c 2006-07-05 09:44:53 UTC (rev 315)
@@ -50,7 +50,7 @@
{
- vca_write_obj(sp, sp->obj->header, 0);
+ vca_write_obj(w, sp);
HSH_Deref(sp->obj);
sp->obj = NULL;
return (1);
@@ -139,6 +139,8 @@
return;
}
+ time(&sp->t_req);
+
/*
* No locking necessary, we're serialized in the acceptor thread
*/
Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/rfc2616.c 2006-07-05 09:32:12 UTC (rev 314)
+++ trunk/varnish-cache/bin/varnishd/rfc2616.c 2006-07-05 09:44:53 UTC (rev 315)
@@ -72,7 +72,7 @@
#endif
static time_t
-RFC2616_Ttl(struct http *hp, time_t t_req, time_t t_resp)
+RFC2616_Ttl(struct http *hp, time_t t_req, time_t t_resp, struct object *obj)
{
int retirement_age;
unsigned u1, u2;
@@ -85,8 +85,10 @@
if (http_GetHdrField(hp, "Cache-Control", "max-age", &p)) {
u1 = strtoul(p, NULL, 0);
u2 = 0;
- if (http_GetHdr(hp, "Age", &p))
+ if (http_GetHdr(hp, "Age", &p)) {
u2 = strtoul(p, NULL, 0);
+ obj->age = u2;
+ }
if (u2 <= u1)
retirement_age = u1 - u2;
}
@@ -148,7 +150,8 @@
break;
}
- sp->obj->ttl = RFC2616_Ttl(hp, sp->t_req, sp->t_resp);
+ sp->obj->ttl = RFC2616_Ttl(hp, sp->t_req, sp->t_resp, sp->obj);
+ sp->obj->entered = sp->t_req;
if (sp->obj->ttl == 0) {
sp->obj->cacheable = 0;
}
More information about the varnish-commit
mailing list