@@ -29,6 +29,7 @@ import (
2929 "github.com/containerd/containerd/log"
3030 "github.com/containerd/containerd/reference"
3131 "github.com/containerd/containerd/remotes"
32+ "github.com/containerd/containerd/version"
3233 digest "github.com/opencontainers/go-digest"
3334 ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3435 "github.com/pkg/errors"
@@ -105,6 +106,7 @@ func DefaultHost(ns string) (string, error) {
105106type dockerResolver struct {
106107 auth Authorizer
107108 host func (string ) (string , error )
109+ uagent string
108110 plainHTTP bool
109111 client * http.Client
110112 tracker StatusTracker
@@ -118,12 +120,15 @@ func NewResolver(options ResolverOptions) remotes.Resolver {
118120 if options .Host == nil {
119121 options .Host = DefaultHost
120122 }
123+ ua := "containerd/" + version .Version
121124 if options .Authorizer == nil {
122125 options .Authorizer = NewAuthorizer (options .Client , options .Credentials )
126+ options .Authorizer .(* dockerAuthorizer ).ua = ua
123127 }
124128 return & dockerResolver {
125129 auth : options .Authorizer ,
126130 host : options .Host ,
131+ uagent : ua ,
127132 plainHTTP : options .PlainHTTP ,
128133 client : options .Client ,
129134 tracker : options .Tracker ,
@@ -293,6 +298,7 @@ func (r *dockerResolver) Pusher(ctx context.Context, ref string) (remotes.Pusher
293298type dockerBase struct {
294299 refspec reference.Spec
295300 base url.URL
301+ uagent string
296302
297303 client * http.Client
298304 auth Authorizer
@@ -324,6 +330,7 @@ func (r *dockerResolver) base(refspec reference.Spec) (*dockerBase, error) {
324330 return & dockerBase {
325331 refspec : refspec ,
326332 base : base ,
333+ uagent : r .uagent ,
327334 client : r .client ,
328335 auth : r .auth ,
329336 }, nil
@@ -349,6 +356,7 @@ func (r *dockerBase) authorize(ctx context.Context, req *http.Request) error {
349356func (r * dockerBase ) doRequest (ctx context.Context , req * http.Request ) (* http.Response , error ) {
350357 ctx = log .WithLogger (ctx , log .G (ctx ).WithField ("url" , req .URL .String ()))
351358 log .G (ctx ).WithField ("request.headers" , req .Header ).WithField ("request.method" , req .Method ).Debug ("do request" )
359+ req .Header .Set ("User-Agent" , r .uagent )
352360 if err := r .authorize (ctx , req ); err != nil {
353361 return nil , errors .Wrap (err , "failed to authorize" )
354362 }
0 commit comments