[libvirt] [PATCH sandbox 18/24] docker: fix setting of Accept header

Daniel P. Berrange berrange at redhat.com
Fri Jul 15 13:08:10 UTC 2016


The code for adding the Accept header was doing so based
on whether 'if json' but 'json' resolved to a module
import name, not a local boolean. So the header was always
added even for requests not expected to be json.

Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
---
 libvirt-sandbox/image/sources/docker.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/libvirt-sandbox/image/sources/docker.py b/libvirt-sandbox/image/sources/docker.py
index 01cf498..658d90a 100644
--- a/libvirt-sandbox/image/sources/docker.py
+++ b/libvirt-sandbox/image/sources/docker.py
@@ -266,8 +266,6 @@ class DockerSource(base.Source):
         debug("Fetching %s..." % url)
 
         req = urllib2.Request(url=url)
-        if json:
-            req.add_header("Accept", "application/json")
         for h in headers.keys():
             req.add_header(h, headers[h])
 
@@ -283,6 +281,11 @@ class DockerSource(base.Source):
 
     def _get_json(self, template, server, path, headers):
         try:
+            if headers is None:
+                headers = {}
+            else:
+                headers = copy.copy(headers)
+            headers["Accept"] = "application/json")
             res = self._get_url(template, server, path, headers)
             data = json.loads(res.read())
             debug("OK\n")
-- 
2.7.4




More information about the libvir-list mailing list