Commit 63da3d8b authored by Cristian Maglie's avatar Cristian Maglie Committed by Roberto Sora

Removed globals.HTTPClientHeader global (#438)

To increase thread-safery and allow adding extra headers if needed.
parent 39530c00
......@@ -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)
......
......@@ -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)
......
......@@ -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 {
......
......@@ -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}}
}
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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)
......
......@@ -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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment