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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]