Skip to content

Commit

Permalink
Merge pull request #5767 from thaJeztah/1.4_backport_fix_authorizatio…
Browse files Browse the repository at this point in the history
…n_on_redirect

[release/1.4 backport] Update docker resolver to authorize redirects
  • Loading branch information
dmcgowan committed Jul 21, 2021
2 parents e4418db + 30d0c91 commit a5cefba
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion remotes/docker/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,21 @@ func (r *request) do(ctx context.Context) (*http.Response, error) {
if err := r.authorize(ctx, req); err != nil {
return nil, errors.Wrap(err, "failed to authorize")
}
resp, err := ctxhttp.Do(ctx, r.host.Client, req)

var client = &http.Client{}
if r.host.Client != nil {
*client = *r.host.Client
}
if client.CheckRedirect == nil {
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
if len(via) >= 10 {
return errors.New("stopped after 10 redirects")
}
return errors.Wrap(r.authorize(ctx, req), "failed to authorize redirect")
}
}

resp, err := ctxhttp.Do(ctx, client, req)
if err != nil {
return nil, errors.Wrap(err, "failed to do request")
}
Expand Down

0 comments on commit a5cefba

Please sign in to comment.