mirror of https://github.com/docker/cli.git
				
				
				
			Merge pull request #2756 from thaJeztah/fix_overwrite_headers
Fix initializing client modifying custom HTTPHeaders
This commit is contained in:
		
						commit
						b4097f7ef2
					
				| 
						 | 
				
			
			@ -308,9 +308,9 @@ func newAPIClientFromEndpoint(ep docker.Endpoint, configFile *configfile.ConfigF
 | 
			
		|||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	customHeaders := configFile.HTTPHeaders
 | 
			
		||||
	if customHeaders == nil {
 | 
			
		||||
		customHeaders = map[string]string{}
 | 
			
		||||
	customHeaders := make(map[string]string, len(configFile.HTTPHeaders))
 | 
			
		||||
	for k, v := range configFile.HTTPHeaders {
 | 
			
		||||
		customHeaders[k] = v
 | 
			
		||||
	}
 | 
			
		||||
	customHeaders["User-Agent"] = UserAgent()
 | 
			
		||||
	clientOpts = append(clientOpts, client.WithHTTPHeaders(customHeaders))
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,6 +45,7 @@ func TestNewAPIClientFromFlags(t *testing.T) {
 | 
			
		|||
	}
 | 
			
		||||
	assert.Check(t, is.DeepEqual(expectedHeaders, apiclient.(*client.Client).CustomHTTPHeaders()))
 | 
			
		||||
	assert.Check(t, is.Equal(api.DefaultVersion, apiclient.ClientVersion()))
 | 
			
		||||
	assert.DeepEqual(t, configFile.HTTPHeaders, map[string]string{"My-Header": "Custom-Value"})
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestNewAPIClientFromFlagsForDefaultSchema(t *testing.T) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue