From cbb906e41ff761af938a387f9be4dd94a9fd1b7d Mon Sep 17 00:00:00 2001 From: Ken Cochrane Date: Wed, 25 Sep 2013 11:33:09 -0400 Subject: [PATCH 1/2] fix the error message so it is the same as the regex issue #1999 --- docs/registry.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/registry.go b/docs/registry.go index 770399ea..e7bc5fea 100644 --- a/docs/registry.go +++ b/docs/registry.go @@ -72,7 +72,7 @@ func validateRepositoryName(repositoryName string) error { } validRepo := regexp.MustCompile(`^([a-z0-9-_.]+)$`) if !validRepo.MatchString(name) { - return fmt.Errorf("Invalid repository name (%s), only [a-zA-Z0-9-_.] are allowed", name) + return fmt.Errorf("Invalid repository name (%s), only [a-z0-9-_.] are allowed", name) } return nil } From 8d77082c92fdedd7d80702afc828873082884435 Mon Sep 17 00:00:00 2001 From: Jonathan Rudenberg Date: Tue, 8 Oct 2013 15:21:32 -0400 Subject: [PATCH 2/2] Fix some error cases where a HTTP body might not be closed Refs #2126 --- docs/registry.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/registry.go b/docs/registry.go index e7bc5fea..0079215c 100644 --- a/docs/registry.go +++ b/docs/registry.go @@ -160,16 +160,16 @@ func (r *Registry) GetRemoteHistory(imgID, registry string, token []string) ([]s } req.Header.Set("Authorization", "Token "+strings.Join(token, ", ")) res, err := doWithCookies(r.client, req) - if err != nil || res.StatusCode != 200 { - if res != nil { - if res.StatusCode == 401 { - return nil, ErrLoginRequired - } - return nil, utils.NewHTTPRequestError(fmt.Sprintf("Internal server error: %d trying to fetch remote history for %s", res.StatusCode, imgID), res) - } + if err != nil { return nil, err } defer res.Body.Close() + if res.StatusCode != 200 { + if res.StatusCode == 401 { + return nil, ErrLoginRequired + } + return nil, utils.NewHTTPRequestError(fmt.Sprintf("Server error: %d trying to fetch remote history for %s", res.StatusCode, imgID), res) + } jsonString, err := ioutil.ReadAll(res.Body) if err != nil { @@ -240,6 +240,7 @@ func (r *Registry) GetRemoteImageLayer(imgID, registry string, token []string) ( return nil, err } if res.StatusCode != 200 { + res.Body.Close() return nil, fmt.Errorf("Server error: Status %d while fetching image layer (%s)", res.StatusCode, imgID) }