Skip to content

Commit 50bc684

Browse files
committed
Remove http.DefaultClient altogether
Use a global http.Client from cleanhttp for all http requests, unless specifically overridden.
1 parent 18ee990 commit 50bc684

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

get.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ var Getters map[string]Getter
5151
// syntax is schema::url, example: git::https://foo.com
5252
var forcedRegexp = regexp.MustCompile(`^([A-Za-z0-9]+)::(.+)$`)
5353

54+
// httpClient is the default client to be used by HttpGetters.
55+
var httpClient = cleanhttp.DefaultClient()
56+
5457
func init() {
5558
httpGetter := &HttpGetter{
56-
Netrc: true,
57-
Client: cleanhttp.DefaultClient(),
59+
Netrc: true,
5860
}
5961

6062
Getters = map[string]Getter{

get_http.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type HttpGetter struct {
3838
Netrc bool
3939

4040
// Client is the http.Client to use for Get requests.
41-
// This defaults to http.DefaultClient if left unset.
41+
// This defaults to a cleanhttp.DefaultClient if left unset.
4242
Client *http.Client
4343
}
4444

@@ -62,7 +62,7 @@ func (g *HttpGetter) Get(dst string, u *url.URL) error {
6262
}
6363

6464
if g.Client == nil {
65-
g.Client = http.DefaultClient
65+
g.Client = httpClient
6666
}
6767

6868
// Add terraform-get to the parameter.
@@ -115,7 +115,7 @@ func (g *HttpGetter) GetFile(dst string, u *url.URL) error {
115115
}
116116

117117
if g.Client == nil {
118-
g.Client = http.DefaultClient
118+
g.Client = httpClient
119119
}
120120

121121
resp, err := g.Client.Get(u.String())

0 commit comments

Comments
 (0)