From d6a5cb920b61f9a5b88223d628d12c73fc6e73f9 Mon Sep 17 00:00:00 2001 From: Cameron Moore Date: Wed, 6 Feb 2019 17:18:52 -0600 Subject: [PATCH] Build User-Agent string only once --- client.go | 2 +- middleware.go | 2 +- redirect.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index cd5af53b..266d1bef 100644 --- a/client.go +++ b/client.go @@ -61,7 +61,7 @@ var ( jsonCheck = regexp.MustCompile(`(?i:(application|text)/(json|.*\+json|json\-.*)(;|$))`) xmlCheck = regexp.MustCompile(`(?i:(application|text)/(xml|.*\+xml)(;|$))`) - hdrUserAgentValue = "go-resty/%s (https://github.com/go-resty/resty)" + hdrUserAgentValue = "go-resty/" + Version + " (https://github.com/go-resty/resty)" bufPool = &sync.Pool{New: func() interface{} { return &bytes.Buffer{} }} ) diff --git a/middleware.go b/middleware.go index 49d82eba..88014b50 100644 --- a/middleware.go +++ b/middleware.go @@ -106,7 +106,7 @@ func parseRequestHeader(c *Client, r *Request) error { } if IsStringEmpty(hdr.Get(hdrUserAgentKey)) { - hdr.Set(hdrUserAgentKey, fmt.Sprintf(hdrUserAgentValue, Version)) + hdr.Set(hdrUserAgentKey, hdrUserAgentValue) } ct := hdr.Get(hdrContentTypeKey) diff --git a/redirect.go b/redirect.go index b426134a..b9b7894b 100644 --- a/redirect.go +++ b/redirect.go @@ -94,6 +94,6 @@ func checkHostAndAddHeaders(cur *http.Request, pre *http.Request) { cur.Header[key] = val } } else { // only library User-Agent header is added - cur.Header.Set(hdrUserAgentKey, fmt.Sprintf(hdrUserAgentValue, Version)) + cur.Header.Set(hdrUserAgentKey, hdrUserAgentValue) } }