1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
package disco
import (
"net/http"
"github.com/hashicorp/go-cleanhttp"
)
const DefaultUserAgent = "terraform-svchost/1.0"
func defaultHttpTransport() http.RoundTripper {
t := cleanhttp.DefaultPooledTransport()
return &userAgentRoundTripper{
innerRt: t,
userAgent: DefaultUserAgent,
}
}
type userAgentRoundTripper struct {
innerRt 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.innerRt.RoundTrip(req)
}
|