Skip to content
Myr

View functions can opt out of the default OPTIONS implementation

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent f8b9f4d · Browse files · 3 files+32 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+32 added−4 removed

  • tests:+17 added−0 removed
  • other:+15 added−4 removed

3 files+32 added−4 removed

modified:flask/app.py+13 added-4 removed
701 unmodified lines
702 if endpoint is None:703 endpoint = _endpoint_from_view_func(view_func)704 options['endpoint'] = endpoint705 methods = options.pop('methods', None)706707 # if the methods are not given and the view_func object knows its708 # methods we can use that instead. If neither exists, we go with709 # a tuple of only `GET` as default.710 if methods is None:711 methods = getattr(view_func, 'methods', None) or ('GET',)711 provide_automatic_options = False712 if 'OPTIONS' not in methods:713 methods = tuple(methods) + ('OPTIONS',)714 provide_automatic_options = True712713 # starting with Flask 0.8 the view_func object can disable and714 # force-enable the automatic options handling.715 provide_automatic_options = getattr(view_func,716 'provide_automatic_options', None)717718 if provide_automatic_options is None:719 if 'OPTIONS' not in methods:720 methods = tuple(methods) + ('OPTIONS',)721 provide_automatic_options = True722 else:723 provide_automatic_options = False724725 # due to a werkzeug bug we need to make sure that the defaults are726 # None if they are an empty dictionary. This should not be necessary727 # with Werkzeug 0.7728 options['defaults'] = options.get('defaults') or None
593 unmodified lines
modified:tests/flask_tests.py+17 added
192 unmodified lines
193 return 'Aha!'194 rv = app.test_client().open('/', method='OPTIONS')195 assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']196197 def test_options_handling_disabled(self):198 app = flask.Flask(__name__)199 def index():200 return 'Hello World!'201 index.provide_automatic_options = False202 app.route('/')(index)203 rv = app.test_client().open('/', method='OPTIONS')204 assert rv.status_code == 405205206 app = flask.Flask(__name__)207 def index2():208 return 'Hello World!'209 index2.provide_automatic_options = True210 app.route('/', methods=['OPTIONS'])(index2)211 rv = app.test_client().open('/', method='OPTIONS')212 assert sorted(rv.allow) == ['OPTIONS']213214 def test_request_dispatching(self):215 app = flask.Flask(__name__)216 @app.route('/')217 def index():
1750 unmodified lines
modified:CHANGES+2 added
10 unmodified lines
11- Refactored session support into a session interface so that12 the implementation of the sessions can be changed without13 having to override the Flask class.14- Empty session cookies are now deleted properly automatically.15- View functions can now opt out of getting the automatic16 OPTIONS implementation.1718Version 0.7.219-------------20
230 unmodified lines