Skip to content

Commit

Permalink
Add default user agent to sdk requests
Browse files Browse the repository at this point in the history
Signed-off-by: Han Verstraete (OpenFaaS Ltd) <[email protected]>
  • Loading branch information
welteki authored and alexellis committed Aug 2, 2024
1 parent 51a111a commit 7487801
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,13 @@ type Client struct {
fnTokenCache TokenCache
}

// Wrap http request Do function to support debug capabilities
// Wrap http request Do function to add default headers and support debug capabilities
func (s *Client) do(req *http.Request) (*http.Response, error) {
// Add default user-agent header
if len(req.Header.Get("User-Agent")) == 0 {
req.Header.Set("User-Agent", "openfaas-go-sdk")
}

if os.Getenv("FAAS_DEBUG") == "1" {
dump, err := dumpRequest(req)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions client_credentials_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func obtainClientCredentialsToken(clientID, clientSecret, tokenURL, scope, grant
return nil, err
}
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("User-Agent", "openfaas-go-sdk")

res, err := http.DefaultClient.Do(req)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func ExchangeIDToken(tokenURL, rawIDToken string, options ...ExchangeOption) (*T
}

req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.Header.Set("User-Agent", "openfaas-go-sdk")

if os.Getenv("FAAS_DEBUG") == "1" {
dump, err := dumpRequest(req)
Expand Down

0 comments on commit 7487801

Please sign in to comment.