From 0eb2666d0ffaa104838539eb4fe56a826ef88868 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Thu, 6 Sep 2018 12:13:22 -0400 Subject: [PATCH] Support using custom User-Agent --- writeas.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/writeas.go b/writeas.go index 25c3965..1cb292a 100644 --- a/writeas.go +++ b/writeas.go @@ -27,6 +27,9 @@ type Client struct { token string // Client making requests to the API client *http.Client + + // UserAgent overrides the default User-Agent header + UserAgent string } // defaultHTTPTimeout is the default http.Client timeout. @@ -151,7 +154,11 @@ func (c *Client) doRequest(r *http.Request, result interface{}) (*impart.Envelop } func (c *Client) prepareRequest(r *http.Request) { - r.Header.Add("User-Agent", "go-writeas v1") + ua := c.UserAgent + if ua == "" { + ua = "go-writeas v1" + } + r.Header.Add("User-Agent", ua) r.Header.Add("Content-Type", "application/json") if c.token != "" { r.Header.Add("Authorization", "Token "+c.token)