You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
terraform/httpclient/useragent.go

27 lines
524 B

package httpclient
import (
"fmt"
"net/http"
"github.com/hashicorp/terraform/version"
)
const userAgentFormat = "Terraform/%s"
func UserAgentString() string {
return fmt.Sprintf(userAgentFormat, version.Version)
}
type userAgentRoundTripper struct {
inner http.RoundTripper
userAgent string
}
func (rt *userAgentRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
if _, ok := req.Header["User-Agent"]; !ok {
req.Header.Set("User-Agent", rt.userAgent)
}
return rt.inner.RoundTrip(req)
}