Skip to content

Commit

Permalink
Merge "Use HTTP_METHOD_NOT_ALLOWED when invalid method is specified"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Mar 31, 2014
2 parents e88a2ce + 5fc844d commit bb16da6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions swift3/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
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
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -950,7 +953,7 @@ def handle_request(self, env, start_response):
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)

Expand Down
2 changes: 1 addition & 1 deletion swift3/test/unit/test_swift3.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def test_bad_method(self):
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))
Expand Down

0 comments on commit bb16da6

Please sign in to comment.