[master] 3544388 More RFC2616 related argument cleanup

Poul-Henning Kamp phk at varnish-cache.org
Sun Feb 19 11:34:46 CET 2012


commit 354438810d1eed7111647cf3ba4ec997e173b86a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Sun Feb 19 10:34:33 2012 +0000

    More RFC2616 related argument cleanup

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index a8cf350..f722e7e 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -998,8 +998,8 @@ char *WS_Snapshot(struct ws *ws);
 
 /* rfc2616.c */
 void RFC2616_Ttl(struct busyobj *, unsigned xid);
-enum body_status RFC2616_Body(const struct sess *sp);
-unsigned RFC2616_Req_Gzip(const struct sess *sp);
+enum body_status RFC2616_Body(struct busyobj *, struct dstat *);
+unsigned RFC2616_Req_Gzip(const struct http *);
 int RFC2616_Do_Cond(const struct sess *sp);
 
 /* stevedore.c */
diff --git a/bin/varnishd/cache/cache_center.c b/bin/varnishd/cache/cache_center.c
index a58b834..b921fee 100644
--- a/bin/varnishd/cache/cache_center.c
+++ b/bin/varnishd/cache/cache_center.c
@@ -238,7 +238,7 @@ cnt_prepresp(struct sess *sp, struct worker *wrk, struct req *req)
 	}
 
 	if (cache_param->http_gzip_support && req->obj->gziped &&
-	    !RFC2616_Req_Gzip(sp)) {
+	    !RFC2616_Req_Gzip(req->http)) {
 		/*
 		 * We don't know what it uncompresses to
 		 * XXX: we could cache that
@@ -552,22 +552,24 @@ static int
 cnt_fetch(struct sess *sp, struct worker *wrk, struct req *req)
 {
 	int i, need_host_hdr;
+	struct busyobj *bo;
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
 	CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
 
 	CHECK_OBJ_NOTNULL(req->vcl, VCL_CONF_MAGIC);
-	CHECK_OBJ_NOTNULL(wrk->busyobj, BUSYOBJ_MAGIC);
+	bo = wrk->busyobj;
+	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 
 	AN(req->director);
-	AZ(wrk->busyobj->vbc);
-	AZ(wrk->busyobj->should_close);
+	AZ(bo->vbc);
+	AZ(bo->should_close);
 	AZ(req->storage_hint);
 
-	http_Setup(wrk->busyobj->beresp, wrk->busyobj->ws, wrk->busyobj->vsl);
+	http_Setup(bo->beresp, bo->ws, bo->vsl);
 
-	need_host_hdr = !http_GetHdr(wrk->busyobj->bereq, H_Host, NULL);
+	need_host_hdr = !http_GetHdr(bo->bereq, H_Host, NULL);
 
 	i = FetchHdr(sp, need_host_hdr, req->objcore == NULL);
 	/*
@@ -589,35 +591,35 @@ cnt_fetch(struct sess *sp, struct worker *wrk, struct req *req)
 		 * and we rely on their content outside of VCL, so collect them
 		 * into one line here.
 		 */
-		http_CollectHdr(wrk->busyobj->beresp, H_Cache_Control);
-		http_CollectHdr(wrk->busyobj->beresp, H_Vary);
+		http_CollectHdr(bo->beresp, H_Cache_Control);
+		http_CollectHdr(bo->beresp, H_Vary);
 
 		/*
 		 * Figure out how the fetch is supposed to happen, before the
 		 * headers are adultered by VCL
 		 * NB: Also sets other wrk variables
 		 */
-		wrk->busyobj->body_status = RFC2616_Body(sp);
+		bo->body_status = RFC2616_Body(bo, &wrk->stats);
 
-		req->err_code = http_GetStatus(wrk->busyobj->beresp);
+		req->err_code = http_GetStatus(bo->beresp);
 
 		/*
 		 * What does RFC2616 think about TTL ?
 		 */
-		EXP_Clr(&wrk->busyobj->exp);
-		wrk->busyobj->exp.entered = W_TIM_real(wrk);
-		RFC2616_Ttl(wrk->busyobj, sp->req->xid);
+		EXP_Clr(&bo->exp);
+		bo->exp.entered = W_TIM_real(wrk);
+		RFC2616_Ttl(bo, sp->req->xid);
 
 		/* pass from vclrecv{} has negative TTL */
 		if (req->objcore == NULL)
-			wrk->busyobj->exp.ttl = -1.;
+			bo->exp.ttl = -1.;
 
-		AZ(wrk->busyobj->do_esi);
-		AZ(wrk->busyobj->do_pass);
+		AZ(bo->do_esi);
+		AZ(bo->do_pass);
 
 		VCL_fetch_method(sp);
 
-		if (req->objcore != NULL && wrk->busyobj->do_pass)
+		if (req->objcore != NULL && bo->do_pass)
 			req->objcore->flags |= OC_F_PASS;
 
 		switch (req->handling) {
@@ -630,11 +632,11 @@ cnt_fetch(struct sess *sp, struct worker *wrk, struct req *req)
 		}
 
 		/* We are not going to fetch the body, Close the connection */
-		VDI_CloseFd(wrk, &wrk->busyobj->vbc);
+		VDI_CloseFd(wrk, &bo->vbc);
 	}
 
 	/* Clean up partial fetch */
-	AZ(wrk->busyobj->vbc);
+	AZ(bo->vbc);
 
 	if (req->objcore != NULL) {
 		CHECK_OBJ_NOTNULL(req->objcore, OBJCORE_MAGIC);
@@ -1384,7 +1386,7 @@ cnt_recv(struct sess *sp, const struct worker *wrk, struct req *req)
 	if (cache_param->http_gzip_support &&
 	     (recv_handling != VCL_RET_PIPE) &&
 	     (recv_handling != VCL_RET_PASS)) {
-		if (RFC2616_Req_Gzip(sp)) {
+		if (RFC2616_Req_Gzip(req->http)) {
 			http_Unset(req->http, H_Accept_Encoding);
 			http_SetHeader(req->http, "Accept-Encoding: gzip");
 		} else {
diff --git a/bin/varnishd/cache/cache_rfc2616.c b/bin/varnishd/cache/cache_rfc2616.c
index 2dafbd2..60bb6a9 100644
--- a/bin/varnishd/cache/cache_rfc2616.c
+++ b/bin/varnishd/cache/cache_rfc2616.c
@@ -179,27 +179,27 @@ RFC2616_Ttl(struct busyobj *bo, unsigned xid)
  */
 
 enum body_status
-RFC2616_Body(const struct sess *sp)
+RFC2616_Body(struct busyobj *bo, struct dstat *stats)
 {
 	struct http *hp;
 	char *b;
 
-	hp = sp->wrk->busyobj->beresp;
+	hp = bo->beresp;
 
 	if (hp->protover < 11 && !http_HdrIs(hp, H_Connection, "keep-alive"))
-		sp->wrk->busyobj->should_close = 1;
+		bo->should_close = 1;
 	else if (http_HdrIs(hp, H_Connection, "close"))
-		sp->wrk->busyobj->should_close = 1;
+		bo->should_close = 1;
 	else
-		sp->wrk->busyobj->should_close = 0;
+		bo->should_close = 0;
 
-	if (!strcasecmp(http_GetReq(sp->wrk->busyobj->bereq), "head")) {
+	if (!strcasecmp(http_GetReq(bo->bereq), "head")) {
 		/*
 		 * A HEAD request can never have a body in the reply,
 		 * no matter what the headers might say.
 		 * [RFC2516 4.3 p33]
 		 */
-		sp->wrk->stats.fetch_head++;
+		stats->fetch_head++;
 		return (BS_NONE);
 	}
 
@@ -208,7 +208,7 @@ RFC2616_Body(const struct sess *sp)
 		 * 1xx responses never have a body.
 		 * [RFC2616 4.3 p33]
 		 */
-		sp->wrk->stats.fetch_1xx++;
+		stats->fetch_1xx++;
 		return (BS_NONE);
 	}
 
@@ -217,7 +217,7 @@ RFC2616_Body(const struct sess *sp)
 		 * 204 is "No Content", obviously don't expect a body.
 		 * [RFC2616 10.2.5 p60]
 		 */
-		sp->wrk->stats.fetch_204++;
+		stats->fetch_204++;
 		return (BS_NONE);
 	}
 
@@ -226,23 +226,23 @@ RFC2616_Body(const struct sess *sp)
 		 * 304 is "Not Modified" it has no body.
 		 * [RFC2616 10.3.5 p63]
 		 */
-		sp->wrk->stats.fetch_304++;
+		stats->fetch_304++;
 		return (BS_NONE);
 	}
 
 	if (http_HdrIs(hp, H_Transfer_Encoding, "chunked")) {
-		 sp->wrk->stats.fetch_chunked++;
+		 stats->fetch_chunked++;
 		return (BS_CHUNKED);
 	}
 
 	if (http_GetHdr(hp, H_Transfer_Encoding, &b)) {
-		sp->wrk->stats.fetch_bad++;
+		stats->fetch_bad++;
 		return (BS_ERROR);
 	}
 
 	if (http_GetHdr(hp, H_Content_Length,
-	    &sp->wrk->busyobj->h_content_length)) {
-		sp->wrk->stats.fetch_length++;
+	    &bo->h_content_length)) {
+		stats->fetch_length++;
 		return (BS_LENGTH);
 	}
 
@@ -251,7 +251,7 @@ RFC2616_Body(const struct sess *sp)
 		 * Keep alive with neither TE=Chunked or C-Len is impossible.
 		 * We assume a zero length body.
 		 */
-		sp->wrk->stats.fetch_zero++;
+		stats->fetch_zero++;
 		return (BS_ZERO);
 	}
 
@@ -259,7 +259,7 @@ RFC2616_Body(const struct sess *sp)
 		/*
 		 * In this case, it is safe to just read what comes.
 		 */
-		sp->wrk->stats.fetch_close++;
+		stats->fetch_close++;
 		return (BS_EOF);
 	}
 
@@ -267,14 +267,14 @@ RFC2616_Body(const struct sess *sp)
 		/*
 		 * With no Connection header, assume EOF.
 		 */
-		sp->wrk->stats.fetch_oldhttp++;
+		stats->fetch_oldhttp++;
 		return (BS_EOF);
 	}
 
 	/*
 	 * Fall back to EOF transfer.
 	 */
-	sp->wrk->stats.fetch_eof++;
+	stats->fetch_eof++;
 	return (BS_EOF);
 }
 
@@ -283,7 +283,7 @@ RFC2616_Body(const struct sess *sp)
  */
 
 unsigned
-RFC2616_Req_Gzip(const struct sess *sp)
+RFC2616_Req_Gzip(const struct http *hp)
 {
 
 
@@ -292,7 +292,7 @@ RFC2616_Req_Gzip(const struct sess *sp)
 	 * p104 says to not do q values for x-gzip, so we just test
 	 * for its existence.
 	 */
-	if (http_GetHdrData(sp->req->http, H_Accept_Encoding, "x-gzip", NULL))
+	if (http_GetHdrData(hp, H_Accept_Encoding, "x-gzip", NULL))
 		return (1);
 
 	/*
@@ -300,7 +300,7 @@ RFC2616_Req_Gzip(const struct sess *sp)
 	 * We do not care a hoot if the client prefers some other
 	 * compression more than gzip: Varnish only does gzip.
 	 */
-	if (http_GetHdrQ(sp->req->http, H_Accept_Encoding, "gzip") > 0.)
+	if (http_GetHdrQ(hp, H_Accept_Encoding, "gzip") > 0.)
 		return (1);
 
 	/* Bad client, no gzip. */
diff --git a/bin/varnishd/cache/cache_vrt_var.c b/bin/varnishd/cache/cache_vrt_var.c
index 50f4411..82aeb9c 100644
--- a/bin/varnishd/cache/cache_vrt_var.c
+++ b/bin/varnishd/cache/cache_vrt_var.c
@@ -355,7 +355,7 @@ VRT_r_req_can_gzip(struct sess *sp)
 {
 
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-	return (RFC2616_Req_Gzip(sp));
+	return (RFC2616_Req_Gzip(sp->req->http));
 }
 
 



More information about the varnish-commit mailing list