Merge "Use HTTP_METHOD_NOT_ALLOWED when invalid method is specified"

This commit is contained in:
Jenkins 2014-03-31 11:14:50 +00:00 committed by Gerrit Code Review
commit bb16da6aa2
2 changed files with 6 additions and 3 deletions

View File

@ -71,7 +71,7 @@ from swift.common.http import HTTP_OK, HTTP_CREATED, HTTP_ACCEPTED, \
HTTP_NO_CONTENT, HTTP_BAD_REQUEST, HTTP_UNAUTHORIZED, HTTP_FORBIDDEN, \
HTTP_NOT_FOUND, HTTP_CONFLICT, HTTP_UNPROCESSABLE_ENTITY, is_success, \
HTTP_NOT_IMPLEMENTED, HTTP_LENGTH_REQUIRED, HTTP_SERVICE_UNAVAILABLE, \
HTTP_REQUEST_ENTITY_TOO_LARGE
HTTP_REQUEST_ENTITY_TOO_LARGE, HTTP_METHOD_NOT_ALLOWED
MAX_BUCKET_LISTING = 1000
@ -112,6 +112,9 @@ def get_err_response(code):
'EntityTooLarge':
(HTTP_BAD_REQUEST, 'Your proposed upload exceeds the maximum '
'allowed object size.'),
'MethodNotAllowed':
(HTTP_METHOD_NOT_ALLOWED, 'The specified method is not allowed '
'against this resource.'),
'NoSuchBucket':
(HTTP_NOT_FOUND, 'The specified bucket does not exist'),
'SignatureDoesNotMatch':
@ -950,7 +953,7 @@ class Swift3Middleware(object):
if hasattr(controller, req.method):
res = getattr(controller, req.method)(env, start_response)
else:
return get_err_response('InvalidURI')(env, start_response)
return get_err_response('MethodNotAllowed')(env, start_response)
return res(env, start_response)

View File

@ -219,7 +219,7 @@ class TestSwift3(unittest.TestCase):
dom = xml.dom.minidom.parseString("".join(resp))
self.assertEquals(dom.firstChild.nodeName, 'Error')
code = dom.getElementsByTagName('Code')[0].childNodes[0].nodeValue
self.assertEquals(code, 'InvalidURI')
self.assertEquals(code, 'MethodNotAllowed')
def _test_method_error(self, cl, method, path, status, headers={}):
local_app = swift3.filter_factory({})(cl(status))