Repository: docker/docker-py

Issue:
Client.build crashes when trying to pull a new image if HttpHeaders are set in config file
```python

import docker

c = docker.Client()
c.build('https://github.com/docker/compose.git')
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-d78c607c9627> in <module>()
----> 1 c.build('https://github.com/docker/compose.git')

/home/joffrey/.envs/pydocker/local/lib/python2.7/site-packages/docker/api/build.pyc in build(self, path, tag, quiet, fileobj, nocache, rm, stream, timeout, custom_context, encoding, pull, forcerm, dockerfile, container_limits, decode, buildargs, gzip)
    102             headers=headers,
    103             stream=stream,
--> 104             timeout=timeout,
    105         )
    106 

/home/joffrey/.envs/pydocker/local/lib/python2.7/site-packages/docker/utils/decorators.pyc in inner(self, *args, **kwargs)
     44                 kwargs['headers'] = self._auth_configs['HttpHeaders']
     45             else:
---> 46                 kwargs['headers'].update(self._auth_configs['HttpHeaders'])
     47         return f(self, *args, **kwargs)
     48     return inner

AttributeError: 'NoneType' object has no attribute 'update'
```

Discussion:

Patch:
diff --git a/docker/utils/decorators.py b/docker/utils/decorators.py
index 7c41a5f8..46c28a80 100644
--- a/docker/utils/decorators.py
+++ b/docker/utils/decorators.py
@@ -40,7 +40,7 @@ def minimum_version(version):
 def update_headers(f):
     def inner(self, *args, **kwargs):
         if 'HttpHeaders' in self._auth_configs:
-            if 'headers' not in kwargs:
+            if not kwargs.get('headers'):
                 kwargs['headers'] = self._auth_configs['HttpHeaders']
             else:
                 kwargs['headers'].update(self._auth_configs['HttpHeaders'])


Test patch:
diff --git a/tests/unit/utils_test.py b/tests/unit/utils_test.py
index 0f7a58c9..47ced433 100644
--- a/tests/unit/utils_test.py
+++ b/tests/unit/utils_test.py
@@ -20,9 +20,11 @@ from docker.utils import (
     create_host_config, Ulimit, LogConfig, parse_bytes, parse_env_file,
     exclude_paths, convert_volume_binds, decode_json_header, tar,
     split_command, create_ipam_config, create_ipam_pool, parse_devices,
+    update_headers,
 )
-from docker.utils.utils import create_endpoint_config
+
 from docker.utils.ports import build_port_bindings, split_port
+from docker.utils.utils import create_endpoint_config
 
 from .. import base
 from ..helpers import make_tree
@@ -34,6 +36,37 @@ TEST_CERT_DIR = os.path.join(
 )
 
 
+class DecoratorsTest(base.BaseTestCase):
+    def test_update_headers(self):
+        sample_headers = {
+            'X-Docker-Locale': 'en-US',
+        }
+
+        def f(self, headers=None):
+            return headers
+
+        client = Client()
+        client._auth_configs = {}
+
+        g = update_headers(f)
+        assert g(client, headers=None) is None
+        assert g(client, headers={}) == {}
+        assert g(client, headers={'Content-type': 'application/json'}) == {
+            'Content-type': 'application/json',
+        }
+
+        client._auth_configs = {
+            'HttpHeaders': sample_headers
+        }
+
+        assert g(client, headers=None) == sample_headers
+        assert g(client, headers={}) == sample_headers
+        assert g(client, headers={'Content-type': 'application/json'}) == {
+            'Content-type': 'application/json',
+            'X-Docker-Locale': 'en-US',
+        }
+
+
 class HostConfigTest(base.BaseTestCase):
     def test_create_host_config_no_options(self):
         config = create_host_config(version='1.19')