Skip to content

Commit 27f2298

Browse files
committed
add Client field to HttpGetter
Add Client field to allow an http.Client instance to be provided for http requests. Continue to default to the `http.DefaultClient` to maintain previous behavior.
1 parent 6aae8e4 commit 27f2298

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

get_http.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ type HttpGetter struct {
3636
// Netrc, if true, will lookup and use auth information found
3737
// in the user's netrc file if available.
3838
Netrc bool
39+
40+
// Client is the http.Client to use for Get requests.
41+
// This defaults to http.DefaultClient if left unset.
42+
Client *http.Client
3943
}
4044

4145
func (g *HttpGetter) ClientMode(u *url.URL) (ClientMode, error) {
@@ -57,13 +61,17 @@ func (g *HttpGetter) Get(dst string, u *url.URL) error {
5761
}
5862
}
5963

64+
if g.Client == nil {
65+
g.Client = http.DefaultClient
66+
}
67+
6068
// Add terraform-get to the parameter.
6169
q := u.Query()
6270
q.Add("terraform-get", "1")
6371
u.RawQuery = q.Encode()
6472

6573
// Get the URL
66-
resp, err := http.Get(u.String())
74+
resp, err := g.Client.Get(u.String())
6775
if err != nil {
6876
return err
6977
}
@@ -106,7 +114,11 @@ func (g *HttpGetter) GetFile(dst string, u *url.URL) error {
106114
}
107115
}
108116

109-
resp, err := http.Get(u.String())
117+
if g.Client == nil {
118+
g.Client = http.DefaultClient
119+
}
120+
121+
resp, err := g.Client.Get(u.String())
110122
if err != nil {
111123
return err
112124
}

0 commit comments

Comments
 (0)