Raise HTTPMethodNotAllowed instead of modifying response directly (#896)

In the default responder that is used when a resource does not support a specific method, raise raise HTTPMethodNotAllowed instead of modifying response directly. This improves visibility for custom error handlers and middleware.

Fixes #895
This commit is contained in:
ksonj
2016-09-14 00:09:11 +02:00
committed by Kurt Griffiths
parent 0c1aaa5f85
commit 18beacf2a8

View File

@@ -16,8 +16,8 @@
from falcon.errors import HTTPBadRequest
from falcon.errors import HTTPNotFound
from falcon.errors import HTTPMethodNotAllowed
from falcon.status_codes import HTTP_204
from falcon.status_codes import HTTP_405
def path_not_found(req, resp, **kwargs):
@@ -38,11 +38,9 @@ def create_method_not_allowed(allowed_methods):
returned in the Allow header.
"""
allowed = ', '.join(allowed_methods)
def method_not_allowed(req, resp, **kwargs):
resp.status = HTTP_405
resp.set_header('Allow', allowed)
"""Raise 405 HTTPMethodNotAllowed error"""
raise HTTPMethodNotAllowed(allowed_methods)
return method_not_allowed