unsigned magic;
#define DIRECTOR_MAGIC 0x3336351d
const char *name;
+ char *vcl_name;
vdi_getfd_f *getfd;
vdi_fini_f *fini;
vdi_healthy *healthy;
for (i = 0; i < vs->nhosts; i++, vh++)
VBE_DropRef(vh->backend);
free(vs->hosts);
+ free(vs->dir.vcl_name);
vs->dir.magic = 0;
FREE_OBJ(vs);
}
vs->dir.magic = DIRECTOR_MAGIC;
vs->dir.priv = vs;
vs->dir.name = "random";
+ REPLACE(vs->dir.vcl_name, t->name);
vs->dir.getfd = vdi_random_getfd;
vs->dir.fini = vdi_random_fini;
vs->dir.healthy = vdi_random_healthy;
for (i = 0; i < vs->nhosts; i++, vh++)
VBE_DropRef(vh->backend);
free(vs->hosts);
+ free(vs->dir.vcl_name);
vs->dir.magic = 0;
vs->next_host = 0;
FREE_OBJ(vs);
vs->dir.magic = DIRECTOR_MAGIC;
vs->dir.priv = vs;
vs->dir.name = "round_robin";
+ REPLACE(vs->dir.vcl_name, t->name);
vs->dir.getfd = vdi_round_robin_getfd;
vs->dir.fini = vdi_round_robin_fini;
vs->dir.healthy = vdi_round_robin_healthy;
CAST_OBJ_NOTNULL(vs, d->priv, VDI_SIMPLE_MAGIC);
VBE_DropRef(vs->backend);
+ free(vs->dir.vcl_name);
vs->dir.magic = 0;
FREE_OBJ(vs);
}
vs->dir.magic = DIRECTOR_MAGIC;
vs->dir.priv = vs;
vs->dir.name = "simple";
+ REPLACE(vs->dir.vcl_name, t->host->vcl_name);
vs->dir.getfd = vdi_simple_getfd;
vs->dir.fini = vdi_simple_fini;
vs->dir.healthy = vdi_simple_healthy;
return (p);
}
+const char *
+VRT_backend_string(struct sess *sp)
+{
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+ CHECK_OBJ_NOTNULL(sp->director, DIRECTOR_MAGIC);
+ return (sp->director->vcl_name);
+}
+
/*--------------------------------------------------------------------*/
void
--- /dev/null
+# $Id$
+
+test "Check naming of backends"
+
+varnish v1 -vcl {
+ backend foo {
+ .host = "127.0.0.2";
+ .port = "9080";
+ }
+
+ sub vcl_recv {
+ error 200 "ok";
+ }
+
+ sub vcl_error {
+ set obj.http.X-Backend-Name = req.backend;
+ }
+} -start
+
+client c1 {
+ txreq -url "/"
+ rxresp
+ expect resp.http.X-Backend-Name == "foo"
+} -run
+
+varnish v1 -vcl {
+ director bar random {
+ {
+ .backend = {
+ .host = "127.0.0.2";
+ .port = "9080";
+ }
+ .weight = 1;
+ }
+ }
+
+ sub vcl_recv {
+ error 200 "ok";
+ }
+
+ sub vcl_error {
+ set obj.http.X-Backend-Name = req.backend;
+ }
+}
+
+client c1 {
+ txreq -url "/"
+ rxresp
+ expect resp.http.X-Backend-Name == "bar"
+} -run
+
+varnish v1 -vcl {
+ director baz round-robin {
+ { .backend = {
+ .host = "127.0.0.2";
+ .port = "9080";
+ } }
+ }
+
+ sub vcl_recv {
+ error 200 "ok";
+ }
+
+ sub vcl_error {
+ set obj.http.X-Backend-Name = req.backend;
+ }
+}
+
+client c1 {
+ txreq -url "/"
+ rxresp
+ expect resp.http.X-Backend-Name == "baz"
+} -run
char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa);
char *VRT_int_string(const struct sess *sp, int);
char *VRT_double_string(const struct sess *sp, double);
+const char *VRT_backend_string(struct sess *sp);
#define VRT_done(sp, hand) \
do { \
case FLOAT:
Fb(tl, 0, "VRT_double_string(sp, %s)", vp->rname);
break;
+ case BACKEND:
+ Fb(tl, 0, "VRT_backend_string(sp)");
+ break;
default:
vsb_printf(tl->sb,
"String representation of '%s' not implemented yet.\n",