]> err.no Git - varnish/commitdiff
Add a backend property ".host_header" to set default content of Host:
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 11 Jul 2008 21:02:05 +0000 (21:02 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 11 Jul 2008 21:02:05 +0000 (21:02 +0000)
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.)

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2938 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_backend_cfg.c
varnish-cache/bin/varnishtest/tests/v00008.vtc [new file with mode: 0644]
varnish-cache/include/vrt.h
varnish-cache/lib/libvcl/vcc_backend.c
varnish-cache/lib/libvcl/vcc_fixed_token.c

index 0a24bb648d367f4641f79a5da5143cd9171ccca0..8d05076a96f6294a2fe9d626d0dd3b9f503683bd 100644 (file)
@@ -219,7 +219,7 @@ VBE_AddBackend(struct cli *cli, const struct vrt_backend *vb)
         */
        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;
 
diff --git a/varnish-cache/bin/varnishtest/tests/v00008.vtc b/varnish-cache/bin/varnishtest/tests/v00008.vtc
new file mode 100644 (file)
index 0000000..84e9e88
--- /dev/null
@@ -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
index e7290dcbc800d8ef2668f4216c2c68c44cad18a4..7ef1a4b7b1dd96bebb731a1c62c4d0a99f94145b 100644 (file)
@@ -48,21 +48,21 @@ struct sockaddr;
 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;
 };
index d8367071c93db2e298fbc554373e8ae7a20a0567..0f43b548ec7ebfa764f37c06c6d2f3cafff03039 100644 (file)
@@ -336,7 +336,12 @@ vcc_ParseProbe(struct tokenlist *tl)
        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_ParseProbe(struct tokenlist *tl)
                        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 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, const
        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 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, const
        *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_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, const
                        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_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, const
                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_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, const
                        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;
index 905124d110dcee2a16c7e3b70698c0c6fbfeaff3..b0d87486daca226777e5d2ace6e490ebaba37c14 100644 (file)
@@ -386,21 +386,21 @@ vcl_output_lang_h(struct vsb *sb)
        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");