]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
Use byte string or utf8 depending on python version for wsgi
authorJuan Antonio Osorio Robles <jaosorior@redhat.com>
Mon, 21 Nov 2016 16:43:21 +0000 (18:43 +0200)
committerJuan Antonio Osorio Robles <jaosorior@redhat.com>
Mon, 21 Nov 2016 16:59:06 +0000 (16:59 +0000)
A recent change to the wsgi code broke deployments running over
httpd/mod_wsgi. This is because for py2.X mod_wsgi accepts byte
strings and breaks with utf8. However, for py3.X, utf8 is
accepted. So this acts accordingly.

Change-Id: I81739bc3de9d623b718987b5fc18eaf851533902
Closes-Bug: #1643511

nova/api/openstack/wsgi.py

index 4925501fa39b0557ed3f294a1781971c89313992..f8dc412ed8aabeec16c2c34929e84f1d28a8b52a 100644 (file)
@@ -692,9 +692,13 @@ class Resource(wsgi.Application):
 
         if hasattr(response, 'headers'):
             for hdr, val in list(response.headers.items()):
-                # Headers must be utf-8 strings
-                response.headers[hdr] = encodeutils.safe_decode(
-                        utils.utf8(val))
+                if six.PY2:
+                    # In Py2.X Headers must be byte strings
+                    response.headers[hdr] = utils.utf8(val)
+                else:
+                    # In Py3.X Headers must be utf-8 strings
+                    response.headers[hdr] = encodeutils.safe_decode(
+                            utils.utf8(val))
 
             if not request.api_version_request.is_null():
                 response.headers[API_VERSION_REQUEST_HEADER] = \