Skip to content

Commit

Permalink
fix(outputs.influxdb*): Support setting Host header (#14481)
Browse files Browse the repository at this point in the history
  • Loading branch information
slai authored Dec 19, 2023
1 parent 448260a commit 08fd16f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
6 changes: 5 additions & 1 deletion plugins/outputs/influxdb/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion plugins/outputs/influxdb_v2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net/url"
"path"
"strconv"
"strings"
"time"

"github.com/influxdata/telegraf"
Expand Down Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit 08fd16f

Please sign in to comment.