r2938 - in trunk/varnish-cache: bin/varnishd bin/varnishtest/tests include lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Fri Jul 11 23:02:06 CEST 2008


Author: phk
Date: 2008-07-11 23:02:05 +0200 (Fri, 11 Jul 2008)
New Revision: 2938

Added:
   trunk/varnish-cache/bin/varnishtest/tests/v00008.vtc
Modified:
   trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c
   trunk/varnish-cache/include/vrt.h
   trunk/varnish-cache/lib/libvcl/vcc_backend.c
   trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
Log:

Add a backend property ".host_header" to set default content of Host:
header if client didn't provide one.

If .host_header is not specified, it defaults to .host.

Add testcase for this logic.

(Incidental change: Use "interval" instead of "rate" for backend pollers.)





Modified: trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c	2008-07-11 20:41:39 UTC (rev 2937)
+++ trunk/varnish-cache/bin/varnishd/cache_backend_cfg.c	2008-07-11 21:02:05 UTC (rev 2938)
@@ -219,7 +219,7 @@
 	 */
 	REPLACE(b->ident, vb->ident);
 	REPLACE(b->vcl_name, vb->vcl_name);
-	REPLACE(b->hosthdr, vb->hostname);
+	REPLACE(b->hosthdr, vb->hosthdr);
 
 	b->connect_timeout = vb->connect_timeout;
 

Added: trunk/varnish-cache/bin/varnishtest/tests/v00008.vtc
===================================================================
--- trunk/varnish-cache/bin/varnishtest/tests/v00008.vtc	                        (rev 0)
+++ trunk/varnish-cache/bin/varnishtest/tests/v00008.vtc	2008-07-11 21:02:05 UTC (rev 2938)
@@ -0,0 +1,44 @@
+# $Id$
+
+test "Test host header specification"
+
+server s1 {
+	rxreq
+	expect req.url == "/foo"
+	expect req.http.host == "snafu"
+	txresp -body "foo1"
+
+	rxreq
+	expect req.url == "/bar"
+	expect req.http.host == "127.0.0.1"
+	txresp -body "foo1"
+} -start
+
+varnish v1 -vcl+backend { } -start
+
+client c1 {
+	txreq -url "/foo" -hdr "Host: snafu"
+	rxresp
+	txreq -url "/bar"
+	rxresp
+} -run
+
+server s2 -listen 127.0.0.1:9180 {
+	rxreq
+	expect req.url == "/barf"
+	expect req.http.host == "FOObar"
+	txresp -body "foo1"
+} -start
+
+varnish v1 -vcl {
+	backend b1 {
+		.host = "127.0.0.1";
+		.port = "9180";
+		.host_header = "FOObar";
+	}
+} 
+
+client c1 {
+	txreq -url "/barf"
+	rxresp
+} -run

Modified: trunk/varnish-cache/include/vrt.h
===================================================================
--- trunk/varnish-cache/include/vrt.h	2008-07-11 20:41:39 UTC (rev 2937)
+++ trunk/varnish-cache/include/vrt.h	2008-07-11 21:02:05 UTC (rev 2938)
@@ -48,21 +48,21 @@
 struct vrt_backend_probe {
 	char		*request;
 	double		timeout;
-	double		rate;
+	double		interval;
 };
 
 /*
  * A backend is a host+port somewhere on the network
  */
 struct vrt_backend {
-	char				*portname;
-	char				*hostname;
+	char				*vcl_name;
+	char				*ident;
 
+	char				*hosthdr;
+
 	const unsigned char		*ipv4_sockaddr;
 	const unsigned char		*ipv6_sockaddr;
 
-	char				*vcl_name;
-	char				*ident;
 	double				connect_timeout;
 	struct vrt_backend_probe 	probe;
 };

Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_backend.c	2008-07-11 20:41:39 UTC (rev 2937)
+++ trunk/varnish-cache/lib/libvcl/vcc_backend.c	2008-07-11 21:02:05 UTC (rev 2938)
@@ -336,7 +336,12 @@
 	struct token *t_field;
 	struct token *t_did = NULL;
 
-	fs = vcc_FldSpec(tl, "?url", "?request", "?timeout", "?rate", NULL);
+	fs = vcc_FldSpec(tl,
+	    "?url",
+	    "?request",
+	    "?timeout",
+	    "?interval",
+	    NULL);
 
 	ExpectErr(tl, '{');
 	vcc_NextToken(tl);
@@ -376,8 +381,8 @@
 			vcc_TimeVal(tl);
 			ERRCHK(tl);
 			Fb(tl, 0, ",\n");
-		} else if (vcc_IdIs(t_field, "rate")) {
-			Fb(tl, 0, "\t\t.rate = ");
+		} else if (vcc_IdIs(t_field, "interval")) {
+			Fb(tl, 0, "\t\t.interval = ");
 			vcc_TimeVal(tl);
 			ERRCHK(tl);
 			Fb(tl, 0, ",\n");
@@ -421,12 +426,17 @@
 	struct token *t_first;
 	struct token *t_host = NULL;
 	struct token *t_port = NULL;
+	struct token *t_hosthdr = NULL;
 	const char *ep;
 	struct fld_spec *fs;
 	struct vsb *vsb;
 
 	fs = vcc_FldSpec(tl,
-	    "!host", "?port", "?connect_timeout", "?probe", NULL);
+	    "!host",
+	    "?port",
+	    "?host_header",
+	    "?connect_timeout",
+	    "?probe", NULL);
 	t_first = tl->t;
 
 	ExpectErr(tl, '{');
@@ -439,6 +449,11 @@
 	*nbh = tl->nbackend_host++;
 	Fb(tl, 0, "\nstatic const struct vrt_backend bh_%d = {\n", *nbh);
 
+	Fb(tl, 0, "\t.vcl_name = \"%.*s", PF(name));
+	if (serial)
+		Fb(tl, 0, "[%d]", serial);
+	Fb(tl, 0, "\",\n");
+
 	/* Check for old syntax */
 	if (tl->t->tok == ID && vcc_IdIs(tl->t, "set")) {
 		vsb_printf(tl->sb,
@@ -471,6 +486,13 @@
 			vcc_NextToken(tl);
 			ExpectErr(tl, ';');
 			vcc_NextToken(tl);
+		} else if (vcc_IdIs(t_field, "host_header")) {
+			ExpectErr(tl, CSTR);
+			assert(tl->t->dec != NULL);
+			t_hosthdr = tl->t;
+			vcc_NextToken(tl);
+			ExpectErr(tl, ';');
+			vcc_NextToken(tl);
 		} else if (vcc_IdIs(t_field, "connect_timeout")) {
 			Fb(tl, 0, "\t.connect_timeout = ");
 			vcc_TimeVal(tl);
@@ -499,9 +521,6 @@
 		vcc_ErrWhere(tl, t_host);
 		return;
 	}
-	Fb(tl, 0, "\t.hostname = ");
-	EncToken(tl->fb, t_host);
-	Fb(tl, 0, ",\n");
 
 	/* Check that the portname makes sense */
 	if (t_port != NULL) {
@@ -512,22 +531,28 @@
 			vcc_ErrWhere(tl, t_port);
 			return;
 		}
-		Fb(tl, 0, "\t.portname = ");
-		EncToken(tl->fb, t_port);
-		Fb(tl, 0, ",\n");
 		Emit_Sockaddr(tl, t_host, t_port->dec);
 	} else {
-		Fb(tl, 0, "\t.portname = \"80\",\n");
 		Emit_Sockaddr(tl, t_host, "80");
 	}
 	ERRCHK(tl);
 
 	ExpectErr(tl, '}');
+
+	/* We have parsed it all, emit the ident string */
 	vcc_EmitBeIdent(tl->fb, name, qual, serial, t_first, tl->t);
-	Fb(tl, 0, "\t.vcl_name = \"%.*s", PF(name));
-	if (serial)
-		Fb(tl, 0, "[%d]", serial);
-	Fb(tl, 0, "\"\n};\n");
+
+	/* Emit the hosthdr field, fall back to .host if not specified */
+	Fb(tl, 0, "\t.hosthdr = ");
+	if (t_hosthdr != NULL)
+		EncToken(tl->fb, t_hosthdr);
+	else
+		EncToken(tl->fb, t_host);
+	Fb(tl, 0, ",\n");
+
+	/* Close the struct */
+	Fb(tl, 0, "};\n");
+
 	vcc_NextToken(tl);
 
 	tl->fb = NULL;

Modified: trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2008-07-11 20:41:39 UTC (rev 2937)
+++ trunk/varnish-cache/lib/libvcl/vcc_fixed_token.c	2008-07-11 21:02:05 UTC (rev 2938)
@@ -386,21 +386,21 @@
 	vsb_cat(sb, "struct vrt_backend_probe {\n");
 	vsb_cat(sb, "	char		*request;\n");
 	vsb_cat(sb, "	double		timeout;\n");
-	vsb_cat(sb, "	double		rate;\n");
+	vsb_cat(sb, "	double		interval;\n");
 	vsb_cat(sb, "};\n");
 	vsb_cat(sb, "\n");
 	vsb_cat(sb, "/*\n");
 	vsb_cat(sb, " * A backend is a host+port somewhere on the network\n");
 	vsb_cat(sb, " */\n");
 	vsb_cat(sb, "struct vrt_backend {\n");
-	vsb_cat(sb, "	char				*portname;\n");
-	vsb_cat(sb, "	char				*hostname;\n");
+	vsb_cat(sb, "	char				*vcl_name;\n");
+	vsb_cat(sb, "	char				*ident;\n");
 	vsb_cat(sb, "\n");
+	vsb_cat(sb, "	char				*hosthdr;\n");
+	vsb_cat(sb, "\n");
 	vsb_cat(sb, "	const unsigned char		*ipv4_sockaddr;\n");
 	vsb_cat(sb, "	const unsigned char		*ipv6_sockaddr;\n");
 	vsb_cat(sb, "\n");
-	vsb_cat(sb, "	char				*vcl_name;\n");
-	vsb_cat(sb, "	char				*ident;\n");
 	vsb_cat(sb, "	double				connect_timeout;\n");
 	vsb_cat(sb, "	struct vrt_backend_probe 	probe;\n");
 	vsb_cat(sb, "};\n");




More information about the varnish-commit mailing list