From 70b93ea693d565f0911968a81a853b48dfbd7fe4 Mon Sep 17 00:00:00 2001 From: Dhia Ayachi Date: Fri, 13 May 2022 14:05:22 -0400 Subject: [PATCH] When a host header is defined override `req.Host` in the metrics ui (#13071) * When a host header is defined override the req.Host in the metrics ui endpoint. * add changelog --- .changelog/13071.txt | 3 +++ agent/ui_endpoint.go | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changelog/13071.txt diff --git a/.changelog/13071.txt b/.changelog/13071.txt new file mode 100644 index 000000000..2493e5875 --- /dev/null +++ b/.changelog/13071.txt @@ -0,0 +1,3 @@ +```release-note:bug +Fix a bug when configuring an `add_headers` directive named `Host` the header is not set for `v1/internal/ui/metrics-proxy/` endpoint. +``` diff --git a/agent/ui_endpoint.go b/agent/ui_endpoint.go index c9fb82d08..1a8d5591a 100644 --- a/agent/ui_endpoint.go +++ b/agent/ui_endpoint.go @@ -740,7 +740,11 @@ func (s *HTTPHandlers) UIMetricsProxy(resp http.ResponseWriter, req *http.Reques // Add any configured headers for _, h := range cfg.AddHeaders { - req.Header.Set(h.Name, h.Value) + if strings.ToLower(h.Name) == "host" { + req.Host = h.Value + } else { + req.Header.Set(h.Name, h.Value) + } } log.Debug("proxying request", "to", u.String())