[master] a8e79f6 Simplify the trickery to find the right SLT for http header operations.

Poul-Henning Kamp phk at FreeBSD.org
Wed Jan 8 22:09:33 CET 2014


commit a8e79f6d0e79f55d863c68bb011098345e86355e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jan 8 21:05:10 2014 +0000

    Simplify the trickery to find the right SLT for http header operations.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 236ca87..e733c38 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -177,18 +177,6 @@ struct ws {
 };
 
 /*--------------------------------------------------------------------
- * HTTP Request/Response/Header handling structure.
- */
-
-enum httpwhence {
-	HTTP_Method	= 1,
-	HTTP_Resp,
-	HTTP_Bereq,
-	HTTP_Beresp,
-	HTTP_Obj
-};
-
-/*--------------------------------------------------------------------
  * Ban info event types
  */
 
@@ -197,7 +185,7 @@ struct http {
 	unsigned		magic;
 #define HTTP_MAGIC		0x6428b5c9
 
-	enum httpwhence		logtag;
+	enum VSL_tag_e		logtag;		/* Must be SLT_*Method */
 	struct vsl_log		*vsl;
 
 	struct ws		*ws;
@@ -998,7 +986,7 @@ void http_PrintfHeader(struct http *to, const char *fmt, ...)
 void http_SetHeader(struct http *to, const char *hdr);
 void http_SetH(const struct http *to, unsigned n, const char *fm);
 void http_ForceGet(const struct http *to);
-void HTTP_Setup(struct http *, struct ws *, struct vsl_log *, enum httpwhence);
+void HTTP_Setup(struct http *, struct ws *, struct vsl_log *, enum VSL_tag_e);
 void http_Teardown(struct http *ht);
 int http_GetHdr(const struct http *hp, const char *hdr, char **ptr);
 int http_GetHdrData(const struct http *hp, const char *hdr,
diff --git a/bin/varnishd/cache/cache_esi_deliver.c b/bin/varnishd/cache/cache_esi_deliver.c
index a2904c8..e76b437 100644
--- a/bin/varnishd/cache/cache_esi_deliver.c
+++ b/bin/varnishd/cache/cache_esi_deliver.c
@@ -69,7 +69,7 @@ ved_include(struct req *preq, const char *src, const char *host)
 
 	req->http0->conds = 0;
 
-	HTTP_Setup(req->http, req->ws, req->vsl, HTTP_Method);
+	HTTP_Setup(req->http, req->ws, req->vsl, SLT_ReqMethod);
 
 	http_SetH(req->http0, HTTP_HDR_URL, src);
 	if (host != NULL && *host != '\0')  {
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 088e0f1..4ee5b97 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -72,7 +72,7 @@ vbf_stp_mkbereq(const struct worker *wrk, struct busyobj *bo)
 	AZ(bo->should_close);
 	AZ(bo->storage_hint);
 
-	HTTP_Setup(bo->bereq0, bo->ws, bo->vsl, HTTP_Bereq);
+	HTTP_Setup(bo->bereq0, bo->ws, bo->vsl, SLT_BereqMethod);
 	http_FilterReq(bo->bereq0, bo->req->http,
 	    bo->do_pass ? HTTPH_R_PASS : HTTPH_R_FETCH);
 	if (!bo->do_pass) {
@@ -118,7 +118,7 @@ vbf_stp_startfetch(struct worker *wrk, struct busyobj *bo)
 	AZ(bo->should_close);
 	AZ(bo->storage_hint);
 
-	HTTP_Setup(bo->bereq, bo->ws, bo->vsl, HTTP_Bereq);
+	HTTP_Setup(bo->bereq, bo->ws, bo->vsl, SLT_BereqMethod);
 	HTTP_Copy(bo->bereq, bo->bereq0);
 
 	VCL_backend_fetch_method(bo->vcl, wrk, NULL, bo, bo->bereq->ws);
@@ -144,7 +144,7 @@ static void
 make_it_503(struct busyobj *bo)
 {
 
-	HTTP_Setup(bo->beresp, bo->ws, bo->vsl, HTTP_Beresp);
+	HTTP_Setup(bo->beresp, bo->ws, bo->vsl, SLT_BerespMethod);
 	http_SetH(bo->beresp, HTTP_HDR_PROTO, "HTTP/1.1");
 	http_SetResp(bo->beresp, "HTTP/1.1", 503, "Backend fetch failed");
 	http_SetHeader(bo->beresp, "Content-Length: 0");
@@ -164,7 +164,7 @@ vbf_stp_fetchhdr(struct worker *wrk, struct busyobj *bo)
 
 	xxxassert (wrk->handling == VCL_RET_FETCH);
 
-	HTTP_Setup(bo->beresp, bo->ws, bo->vsl, HTTP_Beresp);
+	HTTP_Setup(bo->beresp, bo->ws, bo->vsl, SLT_BerespMethod);
 
 	if (!bo->do_pass && bo->req != NULL)
 		vbf_release_req(bo); /* XXX: retry ?? */
@@ -433,7 +433,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 	hp = bo->beresp;
 	hp2 = obj->http;
 
-	hp2->logtag = HTTP_Obj;
+	hp2->logtag = SLT_ObjMethod;
 	http_FilterResp(hp, hp2, bo->uncacheable ? HTTPH_R_PASS : HTTPH_A_INS);
 	http_CopyHome(hp2);
 
@@ -594,7 +594,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
 
 	obj->vxid = bo->vsl->wid;
 
-	obj->http->logtag = HTTP_Obj;
+	obj->http->logtag = SLT_ObjMethod;
 	/* XXX: we should have our own HTTP_A_CONDFETCH */
 	http_FilterResp(bo->ims_obj->http, obj->http, HTTPH_A_INS);
 	http_CopyHome(obj->http);
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 711ea2b..93d60a9 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -41,49 +41,46 @@
 #include "tbl/http_headers.h"
 #undef HTTPH
 
-/*--------------------------------------------------------------------*/
-
-static const enum VSL_tag_e foo[] = {
-	[HTTP_Method]	= SLT_ReqMethod,
-	[HTTP_Resp]	= SLT_RespMethod,
-	[HTTP_Bereq]	= SLT_BereqMethod,
-	[HTTP_Beresp]	= SLT_BerespMethod,
-	[HTTP_Obj]	= SLT_ObjMethod,
-};
-
-static enum VSL_tag_e
-http2shmlog(const struct http *hp, int t)
-{
-
-	CHECK_OBJ_NOTNULL(hp, HTTP_MAGIC);
-	if (t > HTTP_HDR_FIRST)
-		t = HTTP_HDR_FIRST;
-	assert(hp->logtag >= HTTP_Method && hp->logtag <= HTTP_Obj); /*lint !e685*/
-	assert(t >= HTTP_HDR_METHOD && t <= HTTP_HDR_FIRST);
-	return ((enum VSL_tag_e)(foo[hp->logtag] + t));
-}
+/*--------------------------------------------------------------------
+ * These two functions are in an incestous relationship with the
+ * order of macros in include/tbl/vsl_tags_http.h
+ *
+ * The http->logtag is the SLT_*Method enum, and we add to that, to
+ * get the SLT_ to use.
+ */
 
 static void
 http_VSLH(const struct http *hp, unsigned hdr)
 {
+	int i;
 
 	if (hp->vsl != NULL) {
 		AN(hp->vsl->wid & (VSL_CLIENTMARKER|VSL_BACKENDMARKER));
-		VSLbt(hp->vsl, http2shmlog(hp, hdr), hp->hd[hdr]);
+		i = hdr;
+		if (i > HTTP_HDR_FIRST)
+			i = HTTP_HDR_FIRST;
+		i += hp->logtag;
+		VSLbt(hp->vsl, (enum VSL_tag_e)i, hp->hd[hdr]);
 	}
 }
 
 static void
 http_VSLH_del(const struct http *hp, unsigned hdr)
 {
+	int i;
 
 	if (hp->vsl != NULL) {
+		/* We don't support unsetting stuff in the first line */
+		assert (hdr >= HTTP_HDR_FIRST);
 		AN(hp->vsl->wid & (VSL_CLIENTMARKER|VSL_BACKENDMARKER));
-		VSLbt(hp->vsl, ((enum VSL_tag_e)(http2shmlog(hp, hdr) + 1)),
-		    hp->hd[hdr]);
+		i = (HTTP_HDR_UNSET - HTTP_HDR_METHOD);
+		i += hp->logtag;
+		VSLbt(hp->vsl, (enum VSL_tag_e)i, hp->hd[hdr]);
 	}
 }
 
+/*--------------------------------------------------------------------*/
+
 void
 http_VSL_log(const struct http *hp)
 {
@@ -145,7 +142,7 @@ HTTP_create(void *p, uint16_t nhttp)
 
 void
 HTTP_Setup(struct http *hp, struct ws *ws, struct vsl_log *vsl,
-    enum httpwhence  whence)
+    enum VSL_tag_e  whence)
 {
 	http_Teardown(hp);
 	hp->logtag = whence;
diff --git a/bin/varnishd/cache/cache_http1_fsm.c b/bin/varnishd/cache/cache_http1_fsm.c
index 7818260..46cddb7 100644
--- a/bin/varnishd/cache/cache_http1_fsm.c
+++ b/bin/varnishd/cache/cache_http1_fsm.c
@@ -297,7 +297,7 @@ http1_dissect(struct worker *wrk, struct req *req)
 	req->vcl = wrk->vcl;
 	wrk->vcl = NULL;
 
-	HTTP_Setup(req->http, req->ws, req->vsl, HTTP_Method);
+	HTTP_Setup(req->http, req->ws, req->vsl, SLT_ReqMethod);
 	req->err_code = HTTP1_DissectRequest(req);
 
 	/* If we could not even parse the request, just close */
diff --git a/bin/varnishd/cache/cache_req_fsm.c b/bin/varnishd/cache/cache_req_fsm.c
index 8c5b43f..11c5c84 100644
--- a/bin/varnishd/cache/cache_req_fsm.c
+++ b/bin/varnishd/cache/cache_req_fsm.c
@@ -103,7 +103,7 @@ cnt_deliver(struct worker *wrk, struct req *req)
 	if (!(req->obj->objcore->flags & OC_F_PRIVATE))
 		EXP_Touch(req->obj->objcore, req->t_resp);
 
-	HTTP_Setup(req->resp, req->ws, req->vsl, HTTP_Resp);
+	HTTP_Setup(req->resp, req->ws, req->vsl, SLT_RespMethod);
 
 	http_ClrHeader(req->resp);
 	http_FilterResp(req->obj->http, req->resp, 0);
@@ -594,7 +594,7 @@ cnt_pipe(struct worker *wrk, struct req *req)
 
 	req->acct_req.pipe++;
 	bo = VBO_GetBusyObj(wrk, req);
-	HTTP_Setup(bo->bereq, bo->ws, bo->vsl, HTTP_Bereq);
+	HTTP_Setup(bo->bereq, bo->ws, bo->vsl, SLT_BereqMethod);
 	http_FilterReq(bo->bereq, req->http, 0);	// XXX: 0 ?
 	http_PrintfHeader(bo->bereq,
 	    "X-Varnish: %u", req->vsl->wid & VSL_IDENTMASK);
diff --git a/bin/varnishd/storage/stevedore.c b/bin/varnishd/storage/stevedore.c
index c54b982..70b2dd2 100644
--- a/bin/varnishd/storage/stevedore.c
+++ b/bin/varnishd/storage/stevedore.c
@@ -283,7 +283,7 @@ STV_MkObject(struct stevedore *stv, struct busyobj *bo,
 	WS_Assert(bo->ws_o);
 	assert(bo->ws_o->e <= (char*)ptr + ltot);
 
-	HTTP_Setup(o->http, bo->ws_o, bo->vsl, HTTP_Obj);
+	HTTP_Setup(o->http, bo->ws_o, bo->vsl, SLT_ObjMethod);
 	o->http->magic = HTTP_MAGIC;
 	o->exp = bo->exp;
 	o->last_use = bo->t_fetch;
diff --git a/bin/varnishtest/tests/r01029.vtc b/bin/varnishtest/tests/r01029.vtc
index 745fb68..7058ef4 100644
--- a/bin/varnishtest/tests/r01029.vtc
+++ b/bin/varnishtest/tests/r01029.vtc
@@ -23,12 +23,12 @@ varnish v1 -vcl+backend {
 } -start
 
 client c1 {
-	txreq -url "/bar" -hdr "Accept-Encoding: gzip"
+	txreq -url "/bar" -hdr "Accept-Encoding: gzip,foo"
 	rxresp
 	gunzip
 	expect resp.bodylen == 5
 
-	txreq -url "/foo" -hdr "Accept-Encoding: gzip"
+	txreq -url "/foo" -hdr "Accept-Encoding: gzip,foo"
 	rxresp
 	expect resp.bodylen == 21
 } -run
diff --git a/include/tbl/vsl_tags_http.h b/include/tbl/vsl_tags_http.h
index 8d7e56d..3a3ae50 100644
--- a/include/tbl/vsl_tags_http.h
+++ b/include/tbl/vsl_tags_http.h
@@ -27,8 +27,11 @@
  *
  * Define the VSL tags for HTTP protocol messages
  *
- * The order of this table is not random, do not resort.
- * In particular, the FIRST and LOST entries must be last, in that order.
+ * NB: The order of this table is not random, DO NOT RESORT.
+ *
+ * Specifically FIRST, UNSET and LOST entries must be last, in that order.
+ *
+ * See bin/varnishd/cache/cache_http.c::http_VSLH() for the other side.
  *
  * Arguments:
  *	Tag-Name
@@ -64,6 +67,15 @@ SLTH(Header,	HTTP_HDR_FIRST,		1, 1, "header",
 	"\t+----- Header name\n"
 	"\n"
 )
+SLTH(Unset,	HTTP_HDR_UNSET,		0, 0, "unset header",
+	"HTTP header contents.\n\n"
+	"The format is::\n\n"
+	"\t%s: %s\n"
+	"\t|   |\n"
+	"\t|   +- Header value\n"
+	"\t+----- Header name\n"
+	"\n"
+)
 SLTH(Lost,	HTTP_HDR_LOST,		0, 0, "lost header",
 	""
 )



More information about the varnish-commit mailing list