From 08fd16f3dfccc9d4d32a13a497c9a7a8e4a561bb Mon Sep 17 00:00:00 2001 From: Sam Lai <70988+slai@users.noreply.github.com> Date: Tue, 19 Dec 2023 14:49:40 +0000 Subject: [PATCH] fix(outputs.influxdb*): Support setting Host header (#14481) --- plugins/outputs/influxdb/http.go | 6 +++++- plugins/outputs/influxdb_v2/http.go | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/plugins/outputs/influxdb/http.go b/plugins/outputs/influxdb/http.go index fa88bae8a..fcacad8d1 100644 --- a/plugins/outputs/influxdb/http.go +++ b/plugins/outputs/influxdb/http.go @@ -509,7 +509,11 @@ func (c *httpClient) addHeaders(req *http.Request) error { } for header, value := range c.config.Headers { - req.Header.Set(header, value) + if strings.EqualFold(header, "host") { + req.Host = value + } else { + req.Header.Set(header, value) + } } return nil diff --git a/plugins/outputs/influxdb_v2/http.go b/plugins/outputs/influxdb_v2/http.go index b4d2a92cc..b4194cb69 100644 --- a/plugins/outputs/influxdb_v2/http.go +++ b/plugins/outputs/influxdb_v2/http.go @@ -13,6 +13,7 @@ import ( "net/url" "path" "strconv" + "strings" "time" "github.com/influxdata/telegraf" @@ -410,7 +411,11 @@ func (c *httpClient) requestBodyReader(metrics []telegraf.Metric) io.ReadCloser func (c *httpClient) addHeaders(req *http.Request) { for header, value := range c.Headers { - req.Header.Set(header, value) + if strings.EqualFold(header, "host") { + req.Host = value + } else { + req.Header.Set(header, value) + } } }