Skip to content

Commit

Permalink
add Client field to HttpGetter
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jbardin committed Aug 11, 2017
1 parent 6aae8e4 commit 27f2298
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions get_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ type HttpGetter struct {
// Netrc, if true, will lookup and use auth information found
// in the user's netrc file if available.
Netrc bool

// Client is the http.Client to use for Get requests.
// This defaults to http.DefaultClient if left unset.
Client *http.Client
}

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

if g.Client == nil {
g.Client = http.DefaultClient
}

// Add terraform-get to the parameter.
q := u.Query()
q.Add("terraform-get", "1")
u.RawQuery = q.Encode()

// Get the URL
resp, err := http.Get(u.String())
resp, err := g.Client.Get(u.String())
if err != nil {
return err
}
Expand Down Expand Up @@ -106,7 +114,11 @@ func (g *HttpGetter) GetFile(dst string, u *url.URL) error {
}
}

resp, err := http.Get(u.String())
if g.Client == nil {
g.Client = http.DefaultClient
}

resp, err := g.Client.Get(u.String())
if err != nil {
return err
}
Expand Down

0 comments on commit 27f2298

Please sign in to comment.