[master] db403d9 Unify the handling of the Connection: header between client/backend
Poul-Henning Kamp
phk at FreeBSD.org
Mon Jul 14 14:32:47 CEST 2014
commit db403d956980f60c49ac7753152b34162df51192
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Jul 14 12:32:26 2014 +0000
Unify the handling of the Connection: header between client/backend
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index e1b37a4..586181e 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -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
diff --git a/bin/varnishd/cache/cache_busyobj.c b/bin/varnishd/cache/cache_busyobj.c
index e49b88e..4ebfdc4 100644
--- a/bin/varnishd/cache/cache_busyobj.c
+++ b/bin/varnishd/cache/cache_busyobj.c
@@ -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);
}
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index cf1da26..536eece 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -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);
diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c
index 35d4bc2..054b279 100644
--- a/bin/varnishd/cache/cache_fetch_proc.c
+++ b/bin/varnishd/cache/cache_fetch_proc.c
@@ -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);
diff --git a/bin/varnishd/cache/cache_http1_fetch.c b/bin/varnishd/cache/cache_http1_fetch.c
index 47b5029..57fc5d5 100644
--- a/bin/varnishd/cache/cache_http1_fetch.c
+++ b/bin/varnishd/cache/cache_http1_fetch.c
@@ -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);
}
diff --git a/bin/varnishd/cache/cache_http1_proto.c b/bin/varnishd/cache/cache_http1_proto.c
index 1fe77ba..6abd62e 100644
--- a/bin/varnishd/cache/cache_http1_proto.c
+++ b/bin/varnishd/cache/cache_http1_proto.c
@@ -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);
}
/*--------------------------------------------------------------------*/
diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c
index 7969769..1b8f891 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -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,
diff --git a/include/tbl/bo_flags.h b/include/tbl/bo_flags.h
index ac52ef7..bc01dbe 100644
--- a/include/tbl/bo_flags.h
+++ b/include/tbl/bo_flags.h
@@ -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 */
More information about the varnish-commit
mailing list