diff options
author | Dolph Mathews <dolph.mathews@gmail.com> | 2012-06-14 13:47:06 -0500 |
---|---|---|
committer | Dolph Mathews <dolph.mathews@gmail.com> | 2012-06-19 14:17:24 -0500 |
commit | 489c6b60d115af1416d48f058b86d78ff15ca787 (patch) | |
tree | 51541b9a572044ae5e79856b2b75b1d7d2d19a91 /keystone/middleware | |
parent | 66a0b63dabffe4cb1d239be3ab68885e2f49f513 (diff) | |
download | keystone-489c6b60d115af1416d48f058b86d78ff15ca787.tar.gz keystone-489c6b60d115af1416d48f058b86d78ff15ca787.tar.xz keystone-489c6b60d115af1416d48f058b86d78ff15ca787.zip |
400 on unrecognized content type (bug 1012282)
Unrecognized content type:
http://paste.openstack.org/raw/18537/
Malformed JSON:
http://paste.openstack.org/raw/18536/
Change-Id: I76afbf9300bcb1c11bed74eddbe4972c451c5877
Diffstat (limited to 'keystone/middleware')
-rw-r--r-- | keystone/middleware/core.py | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/keystone/middleware/core.py b/keystone/middleware/core.py index 0f6c1e63..aa02c62b 100644 --- a/keystone/middleware/core.py +++ b/keystone/middleware/core.py @@ -98,21 +98,25 @@ class JsonBodyMiddleware(wsgi.Middleware): """ def process_request(self, request): - # Ignore unrecognized content types. Empty string indicates - # the client did not explicitly set the header - if not request.content_type in ('application/json', ''): - return - + # Abort early if we don't have any work to do params_json = request.body if not params_json: return + # Reject unrecognized content types. Empty string indicates + # the client did not explicitly set the header + if not request.content_type in ('application/json', ''): + e = exception.ValidationError(attribute='application/json', + target='Content-Type header') + return wsgi.render_exception(e) + params_parsed = {} try: params_parsed = json.loads(params_json) except ValueError: - msg = 'Malformed json in request body' - raise webob.exc.HTTPBadRequest(explanation=msg) + e = exception.ValidationError(attribute='valid JSON', + target='request body') + return wsgi.render_exception(e) finally: if not params_parsed: params_parsed = {} |