Merge pull request #18360 from hashicorp/svh/b-close-body

svchost/disco: make sure to close the response body
This commit is contained in:
Sander van Harmelen 2018-06-29 19:33:10 +02:00 committed by GitHub
commit 9ba33e1958
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 1 deletions

View File

@ -78,6 +78,7 @@ type Storage struct {
registry *registry.Client
}
// NewStorage returns a new initialized Storage object.
func NewStorage(dir string, services *disco.Disco, creds auth.CredentialsSource) *Storage {
regClient := registry.NewClient(services, creds, nil)

View File

@ -43,6 +43,7 @@ type Client struct {
creds auth.CredentialsSource
}
// NewClient returns a new initialized registry client.
func NewClient(services *disco.Disco, creds auth.CredentialsSource, client *http.Client) *Client {
if services == nil {
services = disco.NewDisco()

View File

@ -42,6 +42,7 @@ type Disco struct {
Transport http.RoundTripper
}
// NewDisco returns a new initialized Disco object.
func NewDisco() *Disco {
return &Disco{}
}
@ -117,7 +118,7 @@ func (d *Disco) DiscoverServiceURL(host svchost.Hostname, serviceID string) *url
func (d *Disco) discover(host svchost.Hostname) Host {
discoURL := &url.URL{
Scheme: "https",
Host: string(host),
Host: host.String(),
Path: discoPath,
}
@ -166,6 +167,8 @@ func (d *Disco) discover(host svchost.Hostname) Host {
log.Printf("[WARN] Failed to request discovery document: %s", err)
return ret // empty
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
log.Printf("[WARN] Failed to request discovery document: %s", resp.Status)
return ret // empty