Commit f13a521c authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@577 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 65519e9b
......@@ -244,6 +244,7 @@ struct sess {
enum step step;
unsigned handling;
unsigned char wantbody;
TAILQ_ENTRY(sess) list;
......@@ -322,6 +323,7 @@ void HSH_Init(void);
/* 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);
......
......@@ -543,6 +543,7 @@ cnt_recv(struct sess *sp)
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:
......
......@@ -228,8 +228,7 @@ FetchBody(struct sess *sp)
* 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 @@ FetchBody(struct sess *sp)
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;
......
......@@ -628,10 +628,23 @@ http_FilterHeader(int fd, struct http *to, struct http *fm, unsigned how)
/*--------------------------------------------------------------------*/
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 @@ http_PrintfHeader(int fd, struct http *to, const char *fmt, ...)
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);
......
......@@ -148,8 +148,7 @@ PassBody(struct sess *sp)
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);
......
......@@ -79,14 +79,10 @@ static void
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 @@ RES_WriteObj(struct sess *sp)
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 @@ RES_WriteObj(struct sess *sp)
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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment