From ac6dbfd81a86e7a9a5a9b68521b0226c40d8e813 Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Thu, 28 Aug 2014 08:02:45 -0700 Subject: [PATCH] Add os/architecture to user agent --- main.go | 6 +++++- main_test.go | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 7390ad321..fa712330d 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "net/http" "os" "path/filepath" + "runtime" "strings" "github.com/codegangsta/cli" @@ -23,9 +24,12 @@ const ( // but with the http://exercism.io app being a prototype, a // lot of things get out of hand. Version = "1.6.2" +) + +var ( // UserAgent is sent along as a header to HTTP requests that the // CLI makes. This helps with debugging. - UserAgent = "github.com/exercism/cli v" + Version + UserAgent = fmt.Sprintf("github.com/exercism/cli v%s (%s/%s)", Version, runtime.GOOS, runtime.GOARCH) ) var FetchEndpoints = map[string]string{ diff --git a/main_test.go b/main_test.go index 6582421ce..b0a2c5dd8 100644 --- a/main_test.go +++ b/main_test.go @@ -8,6 +8,7 @@ import ( "net/http/httptest" "os" "path/filepath" + "strings" "testing" "github.com/exercism/cli/config" @@ -162,7 +163,7 @@ var submitHandler = func(rw http.ResponseWriter, r *http.Request) { return } - userAgentMatches := r.Header.Get("User-Agent") == fmt.Sprintf("github.com/exercism/cli v%s", Version) + userAgentMatches := strings.HasPrefix(r.Header.Get("User-Agent"), fmt.Sprintf("github.com/exercism/cli v%s", Version)) if !userAgentMatches { fmt.Printf("User agent mismatch: %s\n", r.Header.Get("User-Agent"))