Fix user-agent prefix to have docker instead of suffix. (#3074)

This commit is contained in:
Harshavardhana 2016-10-24 13:44:15 -07:00 committed by GitHub
parent 21d41ad7fd
commit 7fc598b73f
4 changed files with 9 additions and 9 deletions

View File

@ -25,7 +25,7 @@ import (
// Global constants for Minio. // Global constants for Minio.
const ( const (
minGoVersion = ">= 1.7.1" // minimum Go runtime version minGoVersion = ">= 1.7" // Minio requires at least Go v1.7
) )
// minio configuration related constants. // minio configuration related constants.

View File

@ -20,7 +20,6 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"os" "os"
@ -138,8 +137,6 @@ func parseReleaseData(data string) (time.Time, error) {
// Minio (OS; ARCH) APP/VER APP/VER // Minio (OS; ARCH) APP/VER APP/VER
var ( var (
userAgentSuffix = "Minio/" + Version + " " + "Minio/" + ReleaseTag + " " + "Minio/" + CommitID userAgentSuffix = "Minio/" + Version + " " + "Minio/" + ReleaseTag + " " + "Minio/" + CommitID
userAgentPrefix = "Minio (" + runtime.GOOS + "; " + runtime.GOARCH + ") "
userAgent = userAgentPrefix + userAgentSuffix
) )
// Check if the operating system is a docker container. // Check if the operating system is a docker container.
@ -200,8 +197,15 @@ func getReleaseUpdate(updateURL string, duration time.Duration) (updateMsg updat
return return
} }
userAgentPrefix := func() string {
if isDocker() {
return "Minio (" + runtime.GOOS + "; " + runtime.GOARCH + "; " + "docker) "
}
return "Minio (" + runtime.GOOS + "; " + runtime.GOARCH + ") "
}()
// Set user agent. // Set user agent.
req.Header.Set("User-Agent", userAgent+" "+fmt.Sprintf("Docker/%t", isDocker())) req.Header.Set("User-Agent", userAgentPrefix+" "+userAgentSuffix)
// Fetch new update. // Fetch new update.
resp, err := client.Do(req) resp, err := client.Do(req)

View File

@ -37,8 +37,6 @@ func TestReleaseUpdateVersion(t *testing.T) {
fmt.Fprintln(w, "fbe246edbd382902db9a4035df7dce8cb441357d minio.RELEASE.2016-10-07T01-16-39Z") fmt.Fprintln(w, "fbe246edbd382902db9a4035df7dce8cb441357d minio.RELEASE.2016-10-07T01-16-39Z")
})) }))
userAgentSuffix = "Minio/" + Version + " " + "Minio/" + ReleaseTag + " " + "Minio/" + CommitID userAgentSuffix = "Minio/" + Version + " " + "Minio/" + ReleaseTag + " " + "Minio/" + CommitID
userAgentPrefix = "Minio (" + runtime.GOOS + "; " + runtime.GOARCH + ") "
userAgent = userAgentPrefix + userAgentSuffix
defer ts.Close() defer ts.Close()
testCases := []struct { testCases := []struct {
updateURL string updateURL string

View File

@ -37,8 +37,6 @@ func TestReleaseUpdateVersion(t *testing.T) {
fmt.Fprintln(w, "fbe246edbd382902db9a4035df7dce8cb441357d minio.RELEASE.2016-10-07T01-16-39Z") fmt.Fprintln(w, "fbe246edbd382902db9a4035df7dce8cb441357d minio.RELEASE.2016-10-07T01-16-39Z")
})) }))
userAgentSuffix = "Minio/" + Version + " " + "Minio/" + ReleaseTag + " " + "Minio/" + CommitID userAgentSuffix = "Minio/" + Version + " " + "Minio/" + ReleaseTag + " " + "Minio/" + CommitID
userAgentPrefix = "Minio (" + runtime.GOOS + "; " + runtime.GOARCH + ") "
userAgent = userAgentPrefix + userAgentSuffix
defer ts.Close() defer ts.Close()
testCases := []struct { testCases := []struct {
updateURL string updateURL string