Skip to content

Commit

Permalink
Add os/architecture to user agent
Browse files Browse the repository at this point in the history
  • Loading branch information
kytrinyx committed Aug 28, 2014
1 parent 709ec58 commit ac6dbfd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"os"
"path/filepath"
"runtime"
"strings"

"github.com/codegangsta/cli"
Expand All @@ -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{
Expand Down
3 changes: 2 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"

"github.com/exercism/cli/config"
Expand Down Expand Up @@ -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"))
Expand Down

0 comments on commit ac6dbfd

Please sign in to comment.