cert-manager/pkg/util/useragent_roundtripper.go
Euan Kemp 7f12fb346c issuer/acme: move 'user-agent' logic to util
This logic should be shared by things like the aws client as well.
2018-04-06 18:09:11 -07:00

29 lines
852 B
Go

package util
import (
"net/http"
)
// UserAgentRoundTripper implements the http.RoundTripper interface and adds a User-Agent
// header.
type userAgentRoundTripper struct {
inner http.RoundTripper
}
// CertManagerUserAgent is the user agent that http clients in this codebase should use
const CertManagerUserAgent = "jetstack-cert-manager/" + AppVersion
// UserAgentRoundTripper returns a RoundTripper that functions identically to
// the provided 'inner' round tripper, other than also setting a user agent.
func UserAgentRoundTripper(inner http.RoundTripper) http.RoundTripper {
return UserAgentRoundTripper{
inner: inner,
}
}
// RoundTrip implements http.RoundTripper
func (u userAgentRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Add("User-Agent", CertManagerUserAgent)
return u.inner.RoundTrip(req)
}