Added required_methods

This commit is contained in:
Armin Ronacher 2012-05-08 12:51:26 +01:00
parent 2053d04db0
commit dbfd406a21
3 changed files with 14 additions and 1 deletions

View file

@ -915,6 +915,10 @@ class Flask(_PackageBoundObject):
# a tuple of only `GET` as default.
if methods is None:
methods = getattr(view_func, 'methods', None) or ('GET',)
methods = set(methods)
# Methods that should always be added
required_methods = set(getattr(view_func, 'required_methods', ()))
# starting with Flask 0.8 the view_func object can disable and
# force-enable the automatic options handling.
@ -923,11 +927,14 @@ class Flask(_PackageBoundObject):
if provide_automatic_options is None:
if 'OPTIONS' not in methods:
methods = tuple(methods) + ('OPTIONS',)
provide_automatic_options = True
required_methods.add('OPTIONS')
else:
provide_automatic_options = False
# Add the required methods now.
methods |= required_methods
# due to a werkzeug bug we need to make sure that the defaults are
# None if they are an empty dictionary. This should not be necessary
# with Werkzeug 0.7