Skip to content

Commit

Permalink
Include user-agent for faas-cli invoke
Browse files Browse the repository at this point in the history
Typically, the default user-agent should not be used when
making a HTTP request from Go. This change includes the CLI's
name.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Jun 8, 2024
1 parent 7eaa545 commit 50e6ca8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion proxy/invoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ import (
"bytes"
"io"
"os"
"runtime"

"fmt"
"net/http"
"strings"
"time"

"github.com/openfaas/faas-cli/version"
)

// InvokeFunction a function
Expand Down Expand Up @@ -58,6 +61,8 @@ func InvokeFunction(gateway string, name string, bytesIn *[]byte, contentType st
return nil, fmt.Errorf("cannot connect to OpenFaaS on URL: %s", gateway)
}

req.Header.Set("User-Agent", fmt.Sprintf("faas-cli/%s (openfaas; %s; %s)", version.BuildVersion(), runtime.GOOS, runtime.GOARCH))

req.Header.Add("Content-Type", contentType)
// Add additional headers to request
for name, value := range headerMap {
Expand All @@ -69,7 +74,6 @@ func InvokeFunction(gateway string, name string, bytesIn *[]byte, contentType st
// SetAuth(req, gateway)

res, err := client.Do(req)

if err != nil {
fmt.Println()
fmt.Println(err)
Expand Down

0 comments on commit 50e6ca8

Please sign in to comment.