summaryrefslogtreecommitdiffstats
path: root/keystone/common/wsgi.py
diff options
context:
space:
mode:
authorDolph Mathews <dolph.mathews@gmail.com>2012-06-21 13:29:00 -0500
committerDolph Mathews <dolph.mathews@gmail.com>2012-07-13 10:42:07 -0500
commit4b97716e4a68cb55652fe2bfd62373adf2b417c5 (patch)
tree4105fb7c2712a9f4839f558179dbe8eef49efdcd /keystone/common/wsgi.py
parenta7d73d2c4bb42a70eab2fa299c2d79fa2c8ac10f (diff)
downloadkeystone-4b97716e4a68cb55652fe2bfd62373adf2b417c5.tar.gz
keystone-4b97716e4a68cb55652fe2bfd62373adf2b417c5.tar.xz
keystone-4b97716e4a68cb55652fe2bfd62373adf2b417c5.zip
Webob needs body to calc Content-Length (bug 1016171)
- Refactored render_response() and added relevant tests Change-Id: I121e8cc641fe11a036106cbfd206f0aa1f6da560
Diffstat (limited to 'keystone/common/wsgi.py')
-rw-r--r--keystone/common/wsgi.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/keystone/common/wsgi.py b/keystone/common/wsgi.py
index 3d06abe4..8857d645 100644
--- a/keystone/common/wsgi.py
+++ b/keystone/common/wsgi.py
@@ -490,17 +490,22 @@ class ExtensionRouter(Router):
return _factory
-def render_response(body=None, status=(200, 'OK'), headers=None):
+def render_response(body=None, status=None, headers=None):
"""Forms a WSGI response."""
- resp = webob.Response()
- resp.status = '%s %s' % status
- resp.headerlist = headers or [('Content-Type', 'application/json'),
- ('Vary', 'X-Auth-Token')]
-
- if body is not None:
- resp.body = jsonutils.dumps(body, cls=utils.SmarterEncoder)
-
- return resp
+ headers = headers or []
+ headers.append(('Vary', 'X-Auth-Token'))
+
+ if body is None:
+ body = ''
+ status = status or (204, 'No Content')
+ else:
+ body = jsonutils.dumps(body, cls=utils.SmarterEncoder)
+ headers.append(('Content-Type', 'application/json'))
+ status = status or (200, 'OK')
+
+ return webob.Response(body=body,
+ status='%s %s' % status,
+ headerlist=headers)
def render_exception(error):