Skip to content

Commit

Permalink
Merge pull request #151 from joonas/user-agent-format
Browse files Browse the repository at this point in the history
Follow User-Agent header field recommendations
  • Loading branch information
joonas authored Sep 23, 2017
2 parents b55291b + ac5e3a0 commit 6590ae2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion godo.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func SetBaseURL(bu string) ClientOpt {
// SetUserAgent is a client option for setting the user agent.
func SetUserAgent(ua string) ClientOpt {
return func(c *Client) error {
c.UserAgent = fmt.Sprintf("%s+%s", ua, c.UserAgent)
c.UserAgent = fmt.Sprintf("%s %s", ua, c.UserAgent)
return nil
}
}
Expand Down
11 changes: 6 additions & 5 deletions godo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func testClientDefaultBaseURL(t *testing.T, c *Client) {

func testClientDefaultUserAgent(t *testing.T, c *Client) {
if c.UserAgent != userAgent {
t.Errorf("NewClick UserAgent = %v, expected %v", c.UserAgent, userAgent)
t.Errorf("NewClient UserAgent = %v, expected %v", c.UserAgent, userAgent)
}
}

Expand Down Expand Up @@ -193,7 +193,7 @@ func TestNewRequest_badURL(t *testing.T) {
}

func TestNewRequest_withCustomUserAgent(t *testing.T) {
ua := "testing"
ua := "testing/0.0.1"
c, err := New(nil, SetUserAgent(ua))

if err != nil {
Expand All @@ -202,7 +202,7 @@ func TestNewRequest_withCustomUserAgent(t *testing.T) {

req, _ := c.NewRequest(ctx, http.MethodGet, "/foo", nil)

expected := fmt.Sprintf("%s+%s", ua, userAgent)
expected := fmt.Sprintf("%s %s", ua, userAgent)
if got := req.Header.Get("User-Agent"); got != expected {
t.Errorf("New() UserAgent = %s; expected %s", got, expected)
}
Expand Down Expand Up @@ -506,13 +506,14 @@ func TestAddOptions(t *testing.T) {
}

func TestCustomUserAgent(t *testing.T) {
c, err := New(nil, SetUserAgent("testing"))
ua := "testing/0.0.1"
c, err := New(nil, SetUserAgent(ua))

if err != nil {
t.Fatalf("New() unexpected error: %v", err)
}

expected := fmt.Sprintf("%s+%s", "testing", userAgent)
expected := fmt.Sprintf("%s %s", ua, userAgent)
if got := c.UserAgent; got != expected {
t.Errorf("New() UserAgent = %s; expected %s", got, expected)
}
Expand Down

0 comments on commit 6590ae2

Please sign in to comment.