Skip to content
Myr

Fixed an issue where the default `OPTIONS` response was

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

not exposing all valid methods in the `Allow` header. This fixes #97

authored by Armin Ronacher · committed by Armin Ronacher · parent 8a14a87 · Browse files · 3 files+33 added−4 removed
This commit

State

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

Trailers

  • Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>

Diff stats

3 files+33 added−4 removed

  • tests:+11 added−0 removed
  • other:+22 added−4 removed

3 files+33 added−4 removed

modified:flask/app.py+19 added-4 removed
17 unmodified lines
18from jinja2 import Environment1920from werkzeug import ImmutableDict21from werkzeug.routing import Map, Rule22from werkzeug.exceptions import HTTPException, InternalServerError22from werkzeug.exceptions import HTTPException, InternalServerError, \23 MethodNotAllowed2425from .helpers import _PackageBoundObject, url_for, get_flashed_messages, \26 _tojson_filter, _endpoint_from_view_func27from .wrappers import Request, Response
661 unmodified lines
689 rule = req.url_rule690 # if we provide automatic options for this URL and the691 # request came with the OPTIONS method, reply automatically 692 if rule.provide_automatic_options and req.method == 'OPTIONS':692 rv = self.response_class()693 rv.allow.update(rule.methods)694 return rv693 return self._make_default_options_response()694 # otherwise dispatch to the handler for that endpoint695 return self.view_functions[rule.endpoint](**req.view_args)696 except HTTPException, e:697 return self.handle_http_exception(e)698699 def _make_default_options_response(self):700 # This would be nicer in Werkzeug 0.7, which however currently701 # is not released. Werkzeug 0.7 provides a method called702 # allowed_methods() that returns all methods that are valid for703 # a given path.704 methods = []705 try:706 _request_ctx_stack.top.url_adapter.match(method='--')707 except MethodNotAllowed, e:708 methods = e.valid_methods709 except HTTPException, e:710 pass711 rv = self.response_class()712 rv.allow.update(methods)713 return rv714715 def make_response(self, rv):716 """Converts the return value from a view function to a real717 response object that is an instance of :attr:`response_class`.718
171 unmodified lines
modified:tests/flask_tests.py+11 added
118 unmodified lines
119 rv = app.test_client().open('/', method='OPTIONS')120 assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST']121 assert rv.data == ''122123 def test_options_on_multiple_rules(self):124 app = flask.Flask(__name__)125 @app.route('/', methods=['GET', 'POST'])126 def index():127 return 'Hello World'128 @app.route('/', methods=['PUT'])129 def index_put():130 return 'Aha!'131 rv = app.test_client().open('/', method='OPTIONS')132 assert sorted(rv.allow) == ['GET', 'HEAD', 'OPTIONS', 'POST', 'PUT']133134 def test_request_dispatching(self):135 app = flask.Flask(__name__)136 @app.route('/')137 def index():
1042 unmodified lines
modified:CHANGES+3 added
11 unmodified lines
12-------------1314Bugfix release, release date to be announced.1516- Fixed an issue where the default `OPTIONS` response was17 not exposing all valid methods in the `Allow` header.1819Version 0.620-----------2122Released on July 27th 2010, codename Whisky
142 unmodified lines