HTTP backend user-defined headers (#1487)

Signed-off-by: David Sims <simsdj82@gmail.com>
This commit is contained in:
David Sims
2024-04-16 22:45:56 +10:00
committed by GitHub
parent d6f2783752
commit 1f3db74281
6 changed files with 101 additions and 3 deletions

View File

@@ -34,6 +34,7 @@ type httpClient struct {
// HTTP
Client *retryablehttp.Client
Headers map[string]string
Username string
Password string
@@ -53,7 +54,12 @@ func (c *httpClient) httpRequest(method string, url *url.URL, data *[]byte, what
if err != nil {
return nil, fmt.Errorf("Failed to make %s HTTP request: %w", what, err)
}
// Set up basic auth
// Add user-defined headers
for k, v := range c.Headers {
req.Header.Set(k, v)
}
if c.Username != "" {
req.SetBasicAuth(c.Username, c.Password)
}