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

Unify the handling of the Connection: header between client/backend

parent c5fa269a
......@@ -494,6 +494,8 @@ struct busyobj {
ssize_t content_length;
enum sess_close doclose;
#define BO_FLAG(l, r, w, d) unsigned l:1;
#include "tbl/bo_flags.h"
#undef BO_FLAG
......
......@@ -151,6 +151,7 @@ VBO_GetBusyObj(struct worker *wrk, const struct req *req)
bo->t_first = bo->t_prev = NAN;
bo->content_length = -1;
bo->doclose = SC_NULL;
return (bo);
}
......
......@@ -187,7 +187,7 @@ vbf_stp_mkbereq(const struct worker *wrk, struct busyobj *bo)
assert(bo->state == BOS_INVALID);
AZ(bo->vbc);
AZ(bo->should_close);
assert(bo->doclose == SC_NULL);
AZ(bo->storage_hint);
HTTP_Setup(bo->bereq0, bo->ws, bo->vsl, SLT_BereqMethod);
......@@ -261,7 +261,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
AZ(bo->vbc);
AZ(bo->should_close);
assert(bo->doclose == SC_NULL);
AZ(bo->storage_hint);
if (bo->do_pass)
......@@ -375,7 +375,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
if (wrk->handling == VCL_RET_RETRY) {
AN (bo->vbc);
VDI_CloseFd(&bo->vbc, &bo->acct);
bo->should_close = 0;
bo->doclose = SC_NULL;
bo->retries++;
if (bo->retries <= cache_param->max_retries)
return (F_STP_RETRY);
......@@ -470,13 +470,13 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
if (VFP_Open(bo)) {
(void)VFP_Error(bo, "Fetch Pipeline failed to open");
bo->should_close = 1;
bo->doclose = SC_RX_BODY;
return (F_STP_ERROR);
}
if (vbf_beresp2obj(bo)) {
(void)VFP_Error(bo, "Could not get storage");
bo->should_close = 1;
bo->doclose = SC_RX_BODY;
return (F_STP_ERROR);
}
......@@ -538,7 +538,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
/* Recycle the backend connection before setting BOS_FINISHED to
give predictable backend reuse behavior for varnishtest */
if (bo->vbc != NULL && !(bo->should_close)) {
if (bo->vbc != NULL && bo->doclose == SC_NULL) {
VDI_RecycleFd(&bo->vbc, &bo->acct);
AZ(bo->vbc);
}
......@@ -642,7 +642,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
/* Recycle the backend connection before setting BOS_FINISHED to
give predictable backend reuse behavior for varnishtest */
if (bo->vbc != NULL && !(bo->should_close)) {
if (bo->vbc != NULL && bo->doclose == SC_NULL) {
VDI_RecycleFd(&bo->vbc, &bo->acct);
AZ(bo->vbc);
}
......@@ -774,6 +774,7 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
THR_SetBusyobj(bo);
stp = F_STP_MKBEREQ;
assert(bo->doclose == SC_NULL);
assert(isnan(bo->t_first));
assert(isnan(bo->t_prev));
VSLb_ts_busyobj(bo, "Start", W_TIM_real(wrk));
......@@ -799,7 +800,7 @@ vbf_fetch_thread(struct worker *wrk, void *priv)
bo->stats = NULL;
if (bo->vbc != NULL) {
if (bo->should_close)
if (bo->doclose != SC_NULL)
VDI_CloseFd(&bo->vbc, &bo->acct);
else
VDI_RecycleFd(&bo->vbc, &bo->acct);
......
......@@ -205,7 +205,7 @@ VFP_Fetch_Body(struct busyobj *bo)
VSLb(bo->vsl, SLT_FetchError,
"Pass delivery abandoned");
vfps = VFP_END;
bo->should_close = 1;
bo->doclose = SC_RX_BODY;
break;
}
AZ(bo->failed);
......@@ -214,7 +214,7 @@ VFP_Fetch_Body(struct busyobj *bo)
est = 0;
}
if (st == NULL) {
bo->should_close = 1;
bo->doclose = SC_RX_BODY;
(void)VFP_Error(bo, "Out of storage");
break;
}
......@@ -235,7 +235,7 @@ VFP_Fetch_Body(struct busyobj *bo)
if (vfps == VFP_ERROR) {
AN(bo->failed);
(void)VFP_Error(bo, "Fetch Pipeline failed to process");
bo->should_close = 1;
bo->doclose = SC_RX_BODY;
}
vfp_suck_fini(bo);
......
......@@ -370,5 +370,7 @@ V1F_fetch_hdr(struct worker *wrk, struct busyobj *bo, struct req *req)
/* XXX: other cleanup ? */
return (-1);
}
bo->doclose = HTTP1_DoConnection(hp);
return (0);
}
......@@ -511,16 +511,17 @@ enum sess_close
HTTP1_DoConnection(struct http *hp)
{
char *p, *q;
enum sess_close ret;
enum sess_close retval;
unsigned u;
if (hp->protover < 11)
retval = SC_REQ_HTTP10;
else
retval = SC_NULL;;
http_CollectHdr(hp, H_Connection);
if (!http_GetHdr(hp, H_Connection, &p)) {
if (hp->protover < 11)
return (SC_REQ_HTTP10);
return (SC_NULL);
}
ret = SC_NULL;
if (!http_GetHdr(hp, H_Connection, &p))
return (retval);
AN(p);
for (; *p; p++) {
if (vct_issp(*p))
......@@ -532,13 +533,15 @@ HTTP1_DoConnection(struct http *hp)
break;
u = pdiff(p, q);
if (u == 5 && !strncasecmp(p, "close", u))
ret = SC_REQ_CLOSE;
retval = SC_REQ_CLOSE;
if (u == 10 && !strncasecmp(p, "keep-alive", u))
retval = SC_NULL;
http_MarkHeader(hp, p, u, HDF_FILTER);
if (!*q)
break;
p = q;
}
return (ret);
return (retval);
}
/*--------------------------------------------------------------------*/
......
......@@ -197,13 +197,6 @@ RFC2616_Body(struct busyobj *bo, struct dstat *stats)
hp = bo->beresp;
if (hp->protover < 11 && !http_HdrIs(hp, H_Connection, "keep-alive"))
bo->should_close = 1;
else if (http_HdrIs(hp, H_Connection, "close"))
bo->should_close = 1;
else
bo->should_close = 0;
if (!strcasecmp(http_GetReq(bo->bereq), "head")) {
/*
* A HEAD request can never have a body in the reply,
......
......@@ -39,6 +39,5 @@ BO_FLAG(uncacheable, 0, 0, "")
BO_FLAG(abandon, 0, 0, "")
BO_FLAG(is_gzip, 0, 0, "")
BO_FLAG(is_gunzip, 0, 0, "")
BO_FLAG(should_close, 0, 0, "")
/*lint -restore */
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