Skip to content

Commit

Permalink
Update docker resolver with support for redirects
Browse files Browse the repository at this point in the history
Authorizes the request in case the host is redirected, supporting at most 10 redirects.
Inspired in the containerd's implementation for supporting redirects. containerd/containerd@b1d4140

Signed-off-by: Fabio Luz <fabio.luz@scarf.sh>
  • Loading branch information
fabioluz committed May 26, 2021
1 parent 97b3ffa commit 959902b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docker/docker_client.go
Expand Up @@ -545,6 +545,15 @@ func (c *dockerClient) makeRequestToResolvedURLOnce(ctx context.Context, method,
return nil, err
}
}
if c.client.CheckRedirect == nil {
c.client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
logrus.Printf("Redirecting host to %s", req.Host)
if len(via) >= 10 {
return errors.New("stopped after 10 redirects")
}
return errors.Wrap(c.setupRequestAuth(req, extraScope), "failed to authorize redirect")
}
}
logrus.Debugf("%s %s", method, url)
res, err := c.client.Do(req)
if err != nil {
Expand Down

0 comments on commit 959902b

Please sign in to comment.