Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Removed globals.HTTPClientHeader global #438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Removed globals.HTTPClientHeader global
To increase thread-safery and allow adding extra headers if needed.
  • Loading branch information
cmaglie committed Oct 7, 2019
commit 4bfb29a00c3df50e8e348b2e0fde1146a19d171e
2 changes: 1 addition & 1 deletion 2 cli/core/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 2 cli/core/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 2 cli/core/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 3 additions & 5 deletions 8 cli/globals/globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}}
}
2 changes: 1 addition & 1 deletion 2 cli/instance/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 2 cli/lib/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 2 cli/lib/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions 4 cli/lib/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion 2 commands/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.