@@ -229,7 +229,7 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize
229229 }
230230
231231 if cli .client == nil {
232- cli .client , err = newAPIClientFromEndpoint (cli .dockerEndpoint , cli .configFile )
232+ cli .client , err = newAPIClientFromEndpoint (opts . Common , cli .dockerEndpoint , cli .configFile )
233233 if err != nil {
234234 return err
235235 }
@@ -255,18 +255,26 @@ func NewAPIClientFromFlags(opts *cliflags.CommonOptions, configFile *configfile.
255255 if err != nil {
256256 return nil , errors .Wrap (err , "unable to resolve docker endpoint" )
257257 }
258- return newAPIClientFromEndpoint (endpoint , configFile )
258+ return newAPIClientFromEndpoint (opts , endpoint , configFile )
259259}
260260
261- func newAPIClientFromEndpoint (ep docker.Endpoint , configFile * configfile.ConfigFile ) (client.APIClient , error ) {
261+ func newAPIClientFromEndpoint (opts * cliflags. CommonOptions , ep docker.Endpoint , configFile * configfile.ConfigFile ) (client.APIClient , error ) {
262262 clientOpts , err := ep .ClientOpts ()
263263 if err != nil {
264264 return nil , err
265265 }
266- customHeaders := make (map [string ]string , len (configFile .HTTPHeaders ))
266+ customHeaders := make (map [string ]string , len (configFile .HTTPHeaders )+ len ( opts . HttpHeaders ) )
267267 for k , v := range configFile .HTTPHeaders {
268268 customHeaders [k ] = v
269269 }
270+
271+ for i := 0 ; i < len (opts .HttpHeaders ); i ++ {
272+ split := strings .Split (opts .HttpHeaders [i ], ":" )
273+ k := strings .TrimSpace (split [0 ])
274+ v := strings .TrimSpace (split [1 ])
275+ customHeaders [k ] = v
276+ }
277+
270278 customHeaders ["User-Agent" ] = UserAgent ()
271279 clientOpts = append (clientOpts , client .WithHTTPHeaders (customHeaders ))
272280 return client .NewClientWithOpts (clientOpts ... )
0 commit comments