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) + } } }