Raise HTTPUnsupportedMediaType when content type is unsupported
Instead of 500 internal error, now cinder will raise HTTPUnsupportedMediaType when any unsupported content type is being used. Change-Id: I024769114caafe8d0e70babd93382702f45aafcc Closes-Bug: #1715094
This commit is contained in:
parent
0652085f23
commit
afae1e4b41
@ -718,12 +718,7 @@ class Resource(wsgi.Application):
|
||||
if len(request.body) == 0:
|
||||
LOG.debug("Empty body provided in request")
|
||||
return None, ''
|
||||
|
||||
try:
|
||||
content_type = request.get_content_type()
|
||||
except exception.InvalidContentType:
|
||||
LOG.debug("Unrecognized Content-Type provided in request")
|
||||
return None, ''
|
||||
|
||||
if not content_type:
|
||||
LOG.debug("No Content-Type provided in request")
|
||||
@ -832,9 +827,14 @@ class Resource(wsgi.Application):
|
||||
# content type
|
||||
action_args = self.get_action_args(request.environ)
|
||||
action = action_args.pop('action', None)
|
||||
# NOTE(sdague): we filter out InvalidContentTypes early so we
|
||||
# know everything is good from here on out.
|
||||
try:
|
||||
content_type, body = self.get_body(request)
|
||||
accept = request.best_match_content_type()
|
||||
|
||||
except exception.InvalidContentType:
|
||||
msg = _("Unsupported Content-Type")
|
||||
return Fault(webob.exc.HTTPUnsupportedMediaType(explanation=msg))
|
||||
# NOTE(Vek): Splitting the function up this way allows for
|
||||
# auditing by external tools that wrap the existing
|
||||
# function. If we try to audit __call__(), we can
|
||||
|
@ -366,9 +366,8 @@ class ResourceTest(test.TestCase):
|
||||
request.headers['Content-Type'] = 'application/none'
|
||||
request.body = b'foo'
|
||||
|
||||
content_type, body = resource.get_body(request)
|
||||
self.assertIsNone(content_type)
|
||||
self.assertEqual('', body)
|
||||
self.assertRaises(exception.InvalidContentType,
|
||||
resource.get_body, request)
|
||||
|
||||
def test_get_body_no_content_type(self):
|
||||
class Controller(object):
|
||||
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Cinder now will return 415 (HTTPUnsupportedMediaType) when any unsupported
|
||||
content type is specified in request header.
|
Loading…
Reference in New Issue
Block a user