Merge pull request #797 from dotcloud/registry-fix-missing-body-close
registry.go: Fixed missing Body.Close()
This commit is contained in:
commit
30421a801d
1 changed files with 18 additions and 5 deletions
|
@ -64,7 +64,11 @@ func (r *Registry) LookupRemoteImage(imgId, registry string, authConfig *auth.Au
|
||||||
}
|
}
|
||||||
req.SetBasicAuth(authConfig.Username, authConfig.Password)
|
req.SetBasicAuth(authConfig.Username, authConfig.Password)
|
||||||
res, err := rt.RoundTrip(req)
|
res, err := rt.RoundTrip(req)
|
||||||
return err == nil && res.StatusCode == 307
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
res.Body.Close()
|
||||||
|
return res.StatusCode == 307
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Registry) getImagesInRepository(repository string, authConfig *auth.AuthConfig) ([]map[string]string, error) {
|
func (r *Registry) getImagesInRepository(repository string, authConfig *auth.AuthConfig) ([]map[string]string, error) {
|
||||||
|
@ -152,16 +156,19 @@ func (r *Registry) GetRemoteTags(registries []string, repository string, token [
|
||||||
}
|
}
|
||||||
req.Header.Set("Authorization", "Token "+strings.Join(token, ", "))
|
req.Header.Set("Authorization", "Token "+strings.Join(token, ", "))
|
||||||
res, err := r.client.Do(req)
|
res, err := r.client.Do(req)
|
||||||
defer res.Body.Close()
|
|
||||||
utils.Debugf("Got status code %d from %s", res.StatusCode, endpoint)
|
utils.Debugf("Got status code %d from %s", res.StatusCode, endpoint)
|
||||||
if err != nil || (res.StatusCode != 200 && res.StatusCode != 404) {
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
if res.StatusCode != 200 && res.StatusCode != 404 {
|
||||||
continue
|
continue
|
||||||
} else if res.StatusCode == 404 {
|
} else if res.StatusCode == 404 {
|
||||||
return nil, fmt.Errorf("Repository not found")
|
return nil, fmt.Errorf("Repository not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
result := make(map[string]string)
|
result := make(map[string]string)
|
||||||
|
|
||||||
rawJson, err := ioutil.ReadAll(res.Body)
|
rawJson, err := ioutil.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -470,9 +477,15 @@ func NewRegistry(root string) *Registry {
|
||||||
// If the auth file does not exist, keep going
|
// If the auth file does not exist, keep going
|
||||||
authConfig, _ := auth.LoadConfig(root)
|
authConfig, _ := auth.LoadConfig(root)
|
||||||
|
|
||||||
|
httpTransport := &http.Transport{
|
||||||
|
DisableKeepAlives: true,
|
||||||
|
}
|
||||||
|
|
||||||
r := &Registry{
|
r := &Registry{
|
||||||
authConfig: authConfig,
|
authConfig: authConfig,
|
||||||
client: &http.Client{},
|
client: &http.Client{
|
||||||
|
Transport: httpTransport,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
r.client.Jar = cookiejar.NewCookieJar()
|
r.client.Jar = cookiejar.NewCookieJar()
|
||||||
return r
|
return r
|
||||||
|
|
Loading…
Reference in a new issue