Skip to content

Commit bf1a667

Browse files
authored
Merge pull request #5504 from dmcgowan/fix-authorization-on-redirect
Update docker resolver to authorize redirects
2 parents bd8ca8f + b1d4140 commit bf1a667

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
@@ -539,7 +539,21 @@ func (r *request) do(ctx context.Context) (*http.Response, error) {
539539
if err := r.authorize(ctx, req); err != nil {
540540
return nil, errors.Wrap(err, "failed to authorize")
541541
}
542-
resp, err := ctxhttp.Do(ctx, r.host.Client, req)
542+
543+
var client = &http.Client{}
544+
if r.host.Client != nil {
545+
*client = *r.host.Client
546+
}
547+
if client.CheckRedirect == nil {
548+
client.CheckRedirect = func(req *http.Request, via []*http.Request) error {
549+
if len(via) >= 10 {
550+
return errors.New("stopped after 10 redirects")
551+
}
552+
return errors.Wrap(r.authorize(ctx, req), "failed to authorize redirect")
553+
}
554+
}
555+
556+
resp, err := ctxhttp.Do(ctx, client, req)
543557
if err != nil {
544558
return nil, errors.Wrap(err, "failed to do request")
545559
}

0 commit comments

Comments
 (0)