From 6e936c8fd32357e839cb9337e621b1e152b9fd8b Mon Sep 17 00:00:00 2001 From: shin- Date: Thu, 25 Apr 2013 09:36:05 -0700 Subject: [PATCH] Follow redirections when sending PUT request in PushRepository --- registry.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/registry.go b/registry.go index c6179efd6d..45a9d3bbfc 100644 --- a/registry.go +++ b/registry.go @@ -466,6 +466,20 @@ func (graph *Graph) PushRepository(stdout io.Writer, remote string, localRepo Re return err } res.Body.Close() + for res.StatusCode >= 300 && res.StatusCode < 400 { + Debugf("Redirected to %s\n", res.Header.Get("Location")) + req, err = http.NewRequest("PUT", res.Header.Get("Location"), nil) + if err != nil { + return err + } + req.SetBasicAuth(authConfig.Username, authConfig.Password) + res, err = client.Do(req) + if err != nil { + return err + } + res.Body.Close() + } + if res.StatusCode != 200 && res.StatusCode != 201 { return fmt.Errorf("Error: Status %d trying to push repository %s", res.StatusCode, remote) }