Skip to content

Commit ac6dbfd

Browse files
committed
Add os/architecture to user agent
1 parent 709ec58 commit ac6dbfd

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111
"os"
1212
"path/filepath"
13+
"runtime"
1314
"strings"
1415

1516
"github.com/codegangsta/cli"
@@ -23,9 +24,12 @@ const (
2324
// but with the http://exercism.io app being a prototype, a
2425
// lot of things get out of hand.
2526
Version = "1.6.2"
27+
)
28+
29+
var (
2630
// UserAgent is sent along as a header to HTTP requests that the
2731
// CLI makes. This helps with debugging.
28-
UserAgent = "github.com/exercism/cli v" + Version
32+
UserAgent = fmt.Sprintf("github.com/exercism/cli v%s (%s/%s)", Version, runtime.GOOS, runtime.GOARCH)
2933
)
3034

3135
var FetchEndpoints = map[string]string{

main_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http/httptest"
99
"os"
1010
"path/filepath"
11+
"strings"
1112
"testing"
1213

1314
"github.com/exercism/cli/config"
@@ -162,7 +163,7 @@ var submitHandler = func(rw http.ResponseWriter, r *http.Request) {
162163
return
163164
}
164165

165-
userAgentMatches := r.Header.Get("User-Agent") == fmt.Sprintf("github.com/exercism/cli v%s", Version)
166+
userAgentMatches := strings.HasPrefix(r.Header.Get("User-Agent"), fmt.Sprintf("github.com/exercism/cli v%s", Version))
166167

167168
if !userAgentMatches {
168169
fmt.Printf("User agent mismatch: %s\n", r.Header.Get("User-Agent"))

0 commit comments

Comments
 (0)