diff options
author | Zuul <zuul@review.openstack.org> | 2018-12-24 23:09:14 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2018-12-24 23:09:15 +0000 |
commit | cd6076dcab2e59c5002dc781d190935be1ede16b (patch) | |
tree | 4aa14729485c996485f754b5d5f70104036726b6 /nova/api/openstack/wsgi.py | |
parent | 23177809f437eee8e7440cf85dc68c8dcd3914bb (diff) | |
parent | 68a689b0f3e5bcdd8939fdadef21de38d06f4dd2 (diff) | |
download | nova-cd6076dcab2e59c5002dc781d190935be1ede16b.tar.gz |
Merge "Clean up header encoding handling in compute API"
Diffstat (limited to 'nova/api/openstack/wsgi.py')
-rw-r--r-- | nova/api/openstack/wsgi.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index e95cb612d3..b9a9b9c741 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -274,6 +274,9 @@ class ResponseObject(object): Utility method for serializing the wrapped object. Returns a webob.Response object. + + Header values are set to the appropriate Python type and + encoding demanded by PEP 3333: whatever the native str type is. """ serializer = self.serializer @@ -284,24 +287,24 @@ class ResponseObject(object): response = webob.Response(body=body) response.status_int = self.code for hdr, val in self._headers.items(): - if not isinstance(val, six.text_type): - val = six.text_type(val) if six.PY2: - # In Py2.X Headers must be byte strings + # In Py2.X Headers must be a UTF-8 encode str. response.headers[hdr] = encodeutils.safe_encode(val) else: - # In Py3.X Headers must be utf-8 strings + # In Py3.X Headers must be a str that was first safely + # encoded to UTF-8 (to catch any bad encodings) and then + # decoded back to a native str. response.headers[hdr] = encodeutils.safe_decode( encodeutils.safe_encode(val)) # Deal with content_type if not isinstance(content_type, six.text_type): content_type = six.text_type(content_type) if six.PY2: - # In Py2.X Headers must be byte strings + # In Py2.X Headers must be a UTF-8 encode str. response.headers['Content-Type'] = encodeutils.safe_encode( content_type) else: - # In Py3.X Headers must be utf-8 strings + # In Py3.X Headers must be a str. response.headers['Content-Type'] = encodeutils.safe_decode( encodeutils.safe_encode(content_type)) return response @@ -571,10 +574,10 @@ class Resource(wsgi.Application): if not isinstance(val, six.text_type): val = six.text_type(val) if six.PY2: - # In Py2.X Headers must be byte strings + # In Py2.X Headers must be UTF-8 encoded string response.headers[hdr] = encodeutils.safe_encode(val) else: - # In Py3.X Headers must be utf-8 strings + # In Py3.X Headers must be a string response.headers[hdr] = encodeutils.safe_decode( encodeutils.safe_encode(val)) |