Commit 2848ac66 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

More caching of HTTP status


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2063 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent f2438ba1
......@@ -300,24 +300,6 @@ cnt_fetch(struct sess *sp)
i = Fetch(sp);
CHECK_OBJ_NOTNULL(sp->backend, BACKEND_MAGIC);
/* Experimental. Set time for last check of backend health.
* If the backend replied with 200, it is obviously up and running,
* increase health parameter. If we got a 504 back, it would imply
* that the backend is not reachable. Decrease health parameter.
*/
sp->backend->last_check = TIM_mono();
sp->backend->minute_limit = 1;
if (!i){
if (http_GetStatus(sp->bereq->http) == 200) {
if (sp->backend->health < 10000)
sp->backend->health++;
} else if(http_GetStatus(sp->bereq->http) == 504) {
if (sp->backend->health > -10000)
sp->backend->health--;
}
}
VBE_free_bereq(sp->bereq);
sp->bereq = NULL;
......
......@@ -282,6 +282,7 @@ Fetch(struct sess *sp)
WRK_Reset(w, &vc->fd);
http_Write(w, hp, 0);
if (WRK_Flush(w)) {
VBE_UpdateHealth(sp, vc, -1);
VBE_ClosedFd(sp->wrk, vc);
/* XXX: other cleanup ? */
return (1);
......@@ -296,6 +297,7 @@ Fetch(struct sess *sp)
while (i == 0);
if (http_DissectResponse(sp->wrk, htc, hp)) {
VBE_UpdateHealth(sp, vc, -2);
VBE_ClosedFd(sp->wrk, vc);
/* XXX: other cleanup ? */
return (1);
......@@ -335,6 +337,7 @@ Fetch(struct sess *sp)
} else if (http_GetHdr(hp, H_Transfer_Encoding, &b)) {
/* XXX: AUGH! */
WSL(sp->wrk, SLT_Debug, vc->fd, "Invalid Transfer-Encoding");
VBE_UpdateHealth(sp, vc, -3);
VBE_ClosedFd(sp->wrk, vc);
return (-1);
} else if (strcmp(http_GetProto(hp), "HTTP/1.1")) {
......@@ -355,6 +358,7 @@ Fetch(struct sess *sp)
VTAILQ_REMOVE(&sp->obj->store, st, list);
STV_free(st);
}
VBE_UpdateHealth(sp, vc, -4);
VBE_ClosedFd(sp->wrk, vc);
return (-1);
}
......@@ -376,10 +380,7 @@ Fetch(struct sess *sp)
if (http_GetHdr(hp, H_Connection, &b) && !strcasecmp(b, "close"))
cls = 1;
if (http_GetStatus(sp->bereq->http) == 200)
VBE_UpdateHealth(sp, vc, 1);
else if(http_GetStatus(sp->bereq->http) == 504)
VBE_UpdateHealth(sp, vc, -1);
VBE_UpdateHealth(sp, vc, http_GetStatus(sp->bereq->http));
if (cls)
VBE_ClosedFd(sp->wrk, vc);
......
......@@ -327,9 +327,6 @@ http_GetStatus(const struct http *hp)
{
Tcheck(hp->hd[HTTP_HDR_STATUS]);
if (hp->status == 0)
hp->status = strtoul(hp->hd[HTTP_HDR_STATUS].b,
NULL /* XXX */, 10));
return (hp->status);
}
......@@ -506,6 +503,7 @@ http_DissectResponse(struct worker *w, const struct http_conn *htc, struct http
if (i != 0 || memcmp(hp->hd[HTTP_HDR_PROTO].b, "HTTP/1.", 7))
WSLR(w, SLT_HttpGarbage, htc->fd, htc->rxbuf);
hp->status = strtoul(hp->hd[HTTP_HDR_STATUS].b, NULL /* XXX */, 10);
return (i);
}
......@@ -738,6 +736,7 @@ http_PutStatus(struct worker *w, int fd, struct http *to, int status)
assert(status >= 0 && status <= 999);
sprintf(stat, "%d", status);
http_PutField(w, fd, to, HTTP_HDR_STATUS, stat);
to->status = status;
}
void
......
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