Skip to content

Commit

Permalink
make UserAgent optional
Browse files Browse the repository at this point in the history
Go will use a default value if nothing is set, so there's no need to error out
if one isn't specifically set.

If we don't like the Go-default user agent for some reason, we should define
our own reasonable default, rather than mandating that one be specified.

I haven't been able to find a requirement for this anywhere.
  • Loading branch information
ewollesen committed Nov 2, 2023
1 parent a5ca88f commit c79ab93
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
4 changes: 3 additions & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ func (c *Client) createRequest(ctx context.Context, method string, url string, m
return nil, errors.New("url is missing")
}

mutators = append(mutators, request.NewHeaderMutator("User-Agent", c.userAgent))
if c.userAgent != "" {
mutators = append(mutators, request.NewHeaderMutator("User-Agent", c.userAgent))
}

var body io.Reader
if requestBody != nil {
Expand Down
3 changes: 0 additions & 3 deletions client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ func (c *Config) Validate() error {
} else if _, err := url.Parse(c.Address); err != nil {
return errors.New("address is invalid")
}
if c.UserAgent == "" {
return errors.New("user agent is missing")
}

return nil
}
Expand Down
5 changes: 0 additions & 5 deletions client/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ var _ = Describe("Config", func() {
Expect(cfg.Validate()).To(MatchError("address is invalid"))
})

It("returns an error if the user agent is missing", func() {
cfg.UserAgent = ""
Expect(cfg.Validate()).To(MatchError("user agent is missing"))
})

It("returns success", func() {
Expect(cfg.Validate()).To(Succeed())
Expect(cfg.Address).To(Equal(address))
Expand Down

0 comments on commit c79ab93

Please sign in to comment.