Skip to content

Commit

Permalink
fix(outputs.influxdb_v2): Fix http auth/agent header
Browse files Browse the repository at this point in the history
  • Loading branch information
DStrand1 committed Jan 8, 2025
1 parent 0c7c424 commit 575c96c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions plugins/outputs/influxdb_v2/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,21 @@ type httpClient struct {
}

func (c *httpClient) Init() error {
token, err := c.token.Get()
if err != nil {
return fmt.Errorf("getting token failed: %w", err)
}

if c.headers == nil {
c.headers = make(map[string]string, 2)
}
c.headers["Authorization"] = "Token " + token.String()
token.Destroy()
c.headers["User-Agent"] = c.userAgent

if _, ok := c.headers["Authorization"]; !ok {
token, err := c.token.Get()
if err != nil {
return fmt.Errorf("getting token failed: %w", err)
}
c.headers["Authorization"] = "Token " + token.String()
token.Destroy()
}
if _, ok := c.headers["User-Agent"]; !ok {
c.headers["User-Agent"] = c.userAgent
}

var proxy func(*http.Request) (*url.URL, error)
if c.proxy != nil {
Expand Down

0 comments on commit 575c96c

Please sign in to comment.