diff --git a/cli/core/download.go b/cli/core/download.go index 0506ab96148..22d00875689 100644 --- a/cli/core/download.go +++ b/cli/core/download.go @@ -64,7 +64,7 @@ func runDownloadCommand(cmd *cobra.Command, args []string) { Version: platformRef.Version, } _, err := core.PlatformDownload(context.Background(), platformDownloadreq, output.ProgressBar(), - globals.HTTPClientHeader) + globals.NewHTTPClientHeader()) if err != nil { feedback.Errorf("Error downloading %s: %v", args[i], err) os.Exit(errorcodes.ErrNetwork) diff --git a/cli/core/install.go b/cli/core/install.go index 29e3022eaec..cc0135a0fa3 100644 --- a/cli/core/install.go +++ b/cli/core/install.go @@ -65,7 +65,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) { Version: platformRef.Version, } _, err := core.PlatformInstall(context.Background(), plattformInstallReq, output.ProgressBar(), - output.TaskProgress(), globals.HTTPClientHeader) + output.TaskProgress(), globals.NewHTTPClientHeader()) if err != nil { feedback.Errorf("Error during install: %v", err) os.Exit(errorcodes.ErrGeneric) diff --git a/cli/core/upgrade.go b/cli/core/upgrade.go index 838d16d67cd..5bee93f1441 100644 --- a/cli/core/upgrade.go +++ b/cli/core/upgrade.go @@ -90,7 +90,7 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) { Architecture: platformRef.Architecture, } - _, err := core.PlatformUpgrade(context.Background(), r, output.ProgressBar(), output.TaskProgress(), globals.HTTPClientHeader) + _, err := core.PlatformUpgrade(context.Background(), r, output.ProgressBar(), output.TaskProgress(), globals.NewHTTPClientHeader()) if err == core.ErrAlreadyLatest { feedback.Printf("Platform %s is already at the latest version", platformRef) } else if err != nil { diff --git a/cli/globals/globals.go b/cli/globals/globals.go index 12863bc0b83..ef718d4c696 100644 --- a/cli/globals/globals.go +++ b/cli/globals/globals.go @@ -31,8 +31,6 @@ var ( Debug bool // OutputFormat can be "text" or "json" OutputFormat string - // HTTPClientHeader is the object that will be propagated to configure the clients inside the downloaders - HTTPClientHeader = getHTTPClientHeader() // VersionInfo contains all info injected during build VersionInfo = version.NewInfo(filepath.Base(os.Args[0])) // Config FIXMEDOC @@ -46,9 +44,9 @@ var ( LogLevel string ) -func getHTTPClientHeader() http.Header { +// NewHTTPClientHeader returns the http.Header object that must be used by the clients inside the downloaders +func NewHTTPClientHeader() http.Header { userAgentValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s", VersionInfo.Application, VersionInfo.VersionString, runtime.GOARCH, runtime.GOOS, runtime.Version(), VersionInfo.Commit) - downloaderHeaders := http.Header{"User-Agent": []string{userAgentValue}} - return downloaderHeaders + return http.Header{"User-Agent": []string{userAgentValue}} } diff --git a/cli/instance/instance.go b/cli/instance/instance.go index d4aec847902..037130624ed 100644 --- a/cli/instance/instance.go +++ b/cli/instance/instance.go @@ -36,7 +36,7 @@ func initInstance() *rpc.InitResp { logrus.Info("Initializing package manager") req := packageManagerInitReq() - resp, err := commands.Init(context.Background(), req, output.ProgressBar(), output.TaskProgress(), globals.HTTPClientHeader) + resp, err := commands.Init(context.Background(), req, output.ProgressBar(), output.TaskProgress(), globals.NewHTTPClientHeader()) if err != nil { feedback.Errorf("Error initializing package manager: %v", err) os.Exit(errorcodes.ErrGeneric) diff --git a/cli/lib/download.go b/cli/lib/download.go index f458b117471..11b10602e07 100644 --- a/cli/lib/download.go +++ b/cli/lib/download.go @@ -60,7 +60,7 @@ func runDownloadCommand(cmd *cobra.Command, args []string) { Version: library.Version, } _, err := lib.LibraryDownload(context.Background(), libraryDownloadReq, output.ProgressBar(), - globals.HTTPClientHeader) + globals.NewHTTPClientHeader()) if err != nil { feedback.Errorf("Error downloading %s: %v", library, err) os.Exit(errorcodes.ErrNetwork) diff --git a/cli/lib/install.go b/cli/lib/install.go index cfcae9fe76a..94be4e706dc 100644 --- a/cli/lib/install.go +++ b/cli/lib/install.go @@ -60,7 +60,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) { Version: library.Version, } err := lib.LibraryInstall(context.Background(), libraryInstallReq, output.ProgressBar(), - output.TaskProgress(), globals.HTTPClientHeader) + output.TaskProgress(), globals.NewHTTPClientHeader()) if err != nil { feedback.Errorf("Error installing %s: %v", library, err) os.Exit(errorcodes.ErrGeneric) diff --git a/cli/lib/upgrade.go b/cli/lib/upgrade.go index fe4a90fc510..06ef2a73abe 100644 --- a/cli/lib/upgrade.go +++ b/cli/lib/upgrade.go @@ -50,13 +50,13 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) { instance := instance.CreateInstaceIgnorePlatformIndexErrors() if len(args) == 0 { - err := lib.LibraryUpgradeAll(instance.Id, output.ProgressBar(), output.TaskProgress(), globals.HTTPClientHeader) + err := lib.LibraryUpgradeAll(instance.Id, output.ProgressBar(), output.TaskProgress(), globals.NewHTTPClientHeader()) if err != nil { feedback.Errorf("Error upgrading libraries: %v", err) os.Exit(errorcodes.ErrGeneric) } } else { - err := lib.LibraryUpgrade(instance.Id, args, output.ProgressBar(), output.TaskProgress(), globals.HTTPClientHeader) + err := lib.LibraryUpgrade(instance.Id, args, output.ProgressBar(), output.TaskProgress(), globals.NewHTTPClientHeader()) if err != nil { feedback.Errorf("Error upgrading libraries: %v", err) os.Exit(errorcodes.ErrGeneric) diff --git a/commands/board/list.go b/commands/board/list.go index 24df2573882..29865093ed1 100644 --- a/commands/board/list.go +++ b/commands/board/list.go @@ -40,7 +40,7 @@ var ( func apiByVidPid(url string) ([]*rpc.BoardListItem, error) { retVal := []*rpc.BoardListItem{} req, _ := http.NewRequest("GET", url, nil) - req.Header = globals.HTTPClientHeader + req.Header = globals.NewHTTPClientHeader() req.Header.Set("Content-Type", "application/json") if res, err := http.DefaultClient.Do(req); err == nil {