Add version to xenolf-acme in User-Agent. (#719)

Also, remove "Go-http-client/1.1". In practice this added detail doesn't
wind up being useful in diagnosing problems, particularly since it can
be deduced from the xenolf-acme version.

* add UA comments.
This commit is contained in:
Jacob Hoffman-Andrews 2018-11-15 14:02:34 -08:00 committed by Ludovic Fernandez
parent 09a3292757
commit a5f0a3ff80
2 changed files with 8 additions and 8 deletions

View file

@ -42,12 +42,14 @@ var (
)
const (
// defaultGoUserAgent is the Go HTTP package user agent string. Too
// bad it isn't exported. If it changes, we should update it here, too.
defaultGoUserAgent = "Go-http-client/1.1"
// ourUserAgent is the User-Agent of this underlying library package.
ourUserAgent = "xenolf-acme"
// NOTE: Update this with each tagged release.
ourUserAgent = "xenolf-acme/1.2.1"
// ourUserAgentComment is part of the UA comment linked to the version status of this underlying library package.
// values: detach|release
// NOTE: Update this with each tagged release.
ourUserAgentComment = "detach"
// caCertificatesEnvVar is the environment variable name that can be used to
// specify the path to PEM encoded CA Certificates that can be used to
@ -205,6 +207,6 @@ func post(j *jws, uri string, reqBody []byte, respBody interface{}) (*http.Respo
// userAgent builds and returns the User-Agent string to use in requests.
func userAgent() string {
ua := fmt.Sprintf("%s %s (%s; %s) %s", UserAgent, ourUserAgent, runtime.GOOS, runtime.GOARCH, defaultGoUserAgent)
ua := fmt.Sprintf("%s %s (%s; %s; %s)", UserAgent, ourUserAgent, ourUserAgentComment, runtime.GOOS, runtime.GOARCH)
return strings.TrimSpace(ua)
}

View file

@ -55,7 +55,6 @@ func TestHTTPUserAgent(t *testing.T) {
func TestUserAgent(t *testing.T) {
ua := userAgent()
assert.Contains(t, ua, defaultGoUserAgent)
assert.Contains(t, ua, ourUserAgent)
if strings.HasSuffix(ua, " ") {
t.Errorf("UA should not have trailing spaces; got '%s'", ua)
@ -65,7 +64,6 @@ func TestUserAgent(t *testing.T) {
UserAgent = "MyApp/1.2.3"
ua = userAgent()
assert.Contains(t, ua, defaultGoUserAgent)
assert.Contains(t, ua, ourUserAgent)
assert.Contains(t, ua, UserAgent)
}