r577 - trunk/varnish-cache/bin/varnishd
phk at projects.linpro.no
phk at projects.linpro.no
Mon Jul 31 23:04:43 CEST 2006
Author: phk
Date: 2006-07-31 23:04:43 +0200 (Mon, 31 Jul 2006)
New Revision: 577
Modified:
trunk/varnish-cache/bin/varnishd/cache.h
trunk/varnish-cache/bin/varnishd/cache_center.c
trunk/varnish-cache/bin/varnishd/cache_fetch.c
trunk/varnish-cache/bin/varnishd/cache_http.c
trunk/varnish-cache/bin/varnishd/cache_pass.c
trunk/varnish-cache/bin/varnishd/cache_response.c
Log:
Add http_ClrHeader() and cure an unintended bug-oid its use exposes:
we checked if the request is a GET long after we should have.
Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h 2006-07-31 20:38:46 UTC (rev 576)
+++ trunk/varnish-cache/bin/varnishd/cache.h 2006-07-31 21:04:43 UTC (rev 577)
@@ -244,6 +244,7 @@
enum step step;
unsigned handling;
+ unsigned char wantbody;
TAILQ_ENTRY(sess) list;
@@ -322,6 +323,7 @@
/* cache_http.c */
void HTTP_Init(void);
+void http_ClrHeader(struct http *to);
void http_CopyHttp(struct http *to, struct http *fm);
unsigned http_Write(struct worker *w, struct http *hp, int resp);
void http_GetReq(int fd, struct http *to, struct http *fm);
Modified: trunk/varnish-cache/bin/varnishd/cache_center.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_center.c 2006-07-31 20:38:46 UTC (rev 576)
+++ trunk/varnish-cache/bin/varnishd/cache_center.c 2006-07-31 21:04:43 UTC (rev 577)
@@ -543,6 +543,7 @@
switch(sp->handling) {
case VCL_RET_LOOKUP:
/* XXX: discard req body, if any */
+ sp->wantbody = !strcmp(sp->http->hd[HTTP_HDR_REQ].b, "GET");
sp->step = STP_LOOKUP;
return (0);
case VCL_RET_PIPE:
Modified: trunk/varnish-cache/bin/varnishd/cache_fetch.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_fetch.c 2006-07-31 20:38:46 UTC (rev 576)
+++ trunk/varnish-cache/bin/varnishd/cache_fetch.c 2006-07-31 21:04:43 UTC (rev 577)
@@ -228,8 +228,7 @@
* The actual headers to reply with are built later on over in
* cache_response.c
*/
- sp->http->f = sp->http->v;
- sp->http->nhd = HTTP_HDR_FIRST;
+ http_ClrHeader(sp->http);
sp->http->objlog = 1; /* log as SLT_ObjHeader */
http_CopyResp(sp->fd, sp->http, vc->http);
http_FilterHeader(sp->fd, sp->http, vc->http, HTTPH_A_INS);
@@ -247,7 +246,6 @@
cls = 0;
sp->http->objlog = 0;
http_CopyHttp(&sp->obj->http, sp->http);
- sp->http->f = sp->http->v;
if (http_GetHdr(vc->http, H_Connection, &b) && !strcasecmp(b, "close"))
cls = 1;
Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c 2006-07-31 20:38:46 UTC (rev 576)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c 2006-07-31 21:04:43 UTC (rev 577)
@@ -629,9 +629,22 @@
/*--------------------------------------------------------------------*/
void
+http_ClrHeader(struct http *to)
+{
+
+ CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
+ to->f = to->v;
+ to->nhd = HTTP_HDR_FIRST;
+ memset(to->hd, 0, sizeof to->hd);
+}
+
+/*--------------------------------------------------------------------*/
+
+void
http_SetHeader(int fd, struct http *to, const char *hdr)
{
+ CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
to->hd[to->nhd].b = (void*)(uintptr_t)hdr;
to->hd[to->nhd].e = strchr(hdr, '\0');
assert(to->hd[to->nhd].e != NULL);
@@ -647,6 +660,7 @@
va_list ap;
unsigned l, n;
+ CHECK_OBJ_NOTNULL(to, HTTP_MAGIC);
va_start(ap, fmt);
l = to->e - to->f;
n = vsnprintf(to->f, l, fmt, ap);
Modified: trunk/varnish-cache/bin/varnishd/cache_pass.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_pass.c 2006-07-31 20:38:46 UTC (rev 576)
+++ trunk/varnish-cache/bin/varnishd/cache_pass.c 2006-07-31 21:04:43 UTC (rev 577)
@@ -148,8 +148,7 @@
vc = sp->vbc;
assert(vc != NULL);
- sp->http->f = sp->http->v;
- sp->http->nhd = HTTP_HDR_FIRST;
+ http_ClrHeader(sp->http);
http_CopyResp(sp->fd, sp->http, vc->http);
http_FilterHeader(sp->fd, sp->http, vc->http, HTTPH_A_PASS);
http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid);
Modified: trunk/varnish-cache/bin/varnishd/cache_response.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_response.c 2006-07-31 20:38:46 UTC (rev 576)
+++ trunk/varnish-cache/bin/varnishd/cache_response.c 2006-07-31 21:04:43 UTC (rev 577)
@@ -79,14 +79,10 @@
res_do_304(struct sess *sp, char *p)
{
- VSL(SLT_Status, sp->fd, "%u", 304);
VSL(SLT_Length, sp->fd, "%u", 0);
- sp->http->f = sp->http->v;
-
+ http_ClrHeader(sp->http);
http_SetResp(sp->fd, sp->http, "HTTP/1.1", "304", "Not Modified");
-
- sp->http->nhd = HTTP_HDR_FIRST;
http_SetHeader(sp->fd, sp->http, "Via: 1.1 varnish");
http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid);
http_PrintfHeader(sp->fd, sp->http, "Last-Modified: %s", p);
@@ -135,15 +131,14 @@
if (sp->obj->response == 200 && sp->http->conds && res_do_conds(sp))
return;
- VSL(SLT_Status, sp->fd, "%u", sp->obj->response);
VSL(SLT_Length, sp->fd, "%u", sp->obj->len);
- sp->http->f = sp->http->v;
- sp->http->nhd = HTTP_HDR_FIRST;
+ http_ClrHeader(sp->http);
http_CopyResp(sp->fd, sp->http, &sp->obj->http);
http_FilterHeader(sp->fd, sp->http, &sp->obj->http, HTTPH_A_DELIVER);
if (sp->xid != sp->obj->xid)
- http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u %u", sp->xid, sp->obj->xid);
+ http_PrintfHeader(sp->fd, sp->http,
+ "X-Varnish: %u %u", sp->xid, sp->obj->xid);
else
http_PrintfHeader(sp->fd, sp->http, "X-Varnish: %u", sp->xid);
http_PrintfHeader(sp->fd, sp->http, "Age: %u",
@@ -155,7 +150,7 @@
sp->wrk->acct.hdrbytes += http_Write(sp->wrk, sp->http, 1);
/* XXX: conditional request handling */
- if (!strcmp(sp->http->hd[HTTP_HDR_REQ].b, "GET")) {
+ if (sp->wantbody) {
TAILQ_FOREACH(st, &sp->obj->store, list) {
assert(st->stevedore != NULL);
u += st->len;
More information about the varnish-commit
mailing list