Use byte string or utf8 depending on python version for wsgi

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
This commit is contained in:
Juan Antonio Osorio Robles 2016-11-21 18:43:21 +02:00
parent a58c7e5173
commit 11d8dde452
1 changed files with 7 additions and 3 deletions

View 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] = \