Skip to content

Commit bc12da7

Browse files
authored
Merge pull request #5766 from thaJeztah/1.5_backport_fix_authorization_on_redirect
[release/1.5 backport] Update docker resolver to authorize redirects
2 parents 47d0f52 + 4c1722e commit bc12da7

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

remotes/docker/resolver.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,21 @@ func (r *request) do(ctx context.Context) (*http.Response, error) {
550550
if err := r.authorize(ctx, req); err != nil {
551551
return nil, errors.Wrap(err, "failed to authorize")
552552
}
553-
resp, err := ctxhttp.Do(ctx, r.host.Client, req)
553+
554+
var client = &http.Client{}
555+
if r.host.Client != nil {
556+
*client = *r.host.Client
557+
}
558+
if client.CheckRedirect == nil {
559+
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
560+
if len(via) >= 10 {
561+
return errors.New("stopped after 10 redirects")
562+
}
563+
return errors.Wrap(r.authorize(ctx, req), "failed to authorize redirect")
564+
}
565+
}
566+
567+
resp, err := ctxhttp.Do(ctx, client, req)
554568
if err != nil {
555569
return nil, errors.Wrap(err, "failed to do request")
556570
}

0 commit comments

Comments
 (0)