[master] ac4cf5099 vrt: Ensure backends always have a host_header
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Wed Oct 14 09:57:06 UTC 2020
commit ac4cf50993debbce6aa82b8907dcde457cac1bdc
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Wed Oct 14 11:51:59 2020 +0200
vrt: Ensure backends always have a host_header
This is enforced by libvcc for static backends, but not guaranteed for
dynamic backends. With no fallback we cannot meet the requirement since
HTTP/1.1 that requests always have a host header if it is unset from VCL,
and probes expect hosthdr to always be set.
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index 4eb18b8b9..763622798 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -586,6 +586,8 @@ VRT_new_backend_clustered(VRT_CTX, struct vsmw_cluster *vc,
struct vcl *vcl;
const struct vrt_backend_probe *vbp;
const struct vdi_methods *m;
+ const struct suckaddr *sa;
+ char abuf[VTCP_ADDRBUFSIZE];
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(vrt, VRT_BACKEND_MAGIC);
@@ -613,6 +615,19 @@ VRT_new_backend_clustered(VRT_CTX, struct vsmw_cluster *vc,
#undef DA
#undef DN
+ if (be->hosthdr == NULL) {
+ if (vrt->path != NULL)
+ sa = bogo_ip;
+ else if (cache_param->prefer_ipv6 && vrt->ipv6_suckaddr != NULL)
+ sa = vrt->ipv6_suckaddr;
+ else if (vrt->ipv4_suckaddr != NULL)
+ sa = vrt->ipv4_suckaddr;
+ else
+ sa = vrt->ipv6_suckaddr;
+ VTCP_name(sa, abuf, sizeof abuf, NULL, 0);
+ REPLACE(be->hosthdr, abuf);
+ }
+
be->vsc = VSC_vbe_New(vc, &be->vsc_seg,
"%s.%s", VCL_Name(ctx->vcl), vrt->vcl_name);
AN(be->vsc);
More information about the varnish-commit
mailing list