Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing the User Agent doesn't work as expected #100

Merged
merged 1 commit into from
Jun 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Changing the User Agent doesn't work as expected
Fixes #99
  • Loading branch information
tbalthazar committed Jun 14, 2016
commit cb325e7136b5f311ab43259c6d1940163534b1a5
2 changes: 1 addition & 1 deletion godo.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Requ

req.Header.Add("Content-Type", mediaType)
req.Header.Add("Accept", mediaType)
req.Header.Add("User-Agent", userAgent)
req.Header.Add("User-Agent", c.UserAgent)
return req, nil
}

Expand Down
16 changes: 16 additions & 0 deletions godo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ func TestNewRequest_badURL(t *testing.T) {
testURLParseError(t, err)
}

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

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

req, _ := c.NewRequest("GET", "/foo", nil)

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)
}
}

func TestDo(t *testing.T) {
setup()
defer teardown()
Expand Down