forked from orbit-oss/flask
Change Flask.__init__ to accept two new keyword arguments, host_matching and static_host. (#1560)
This enables host_matching to be set properly by the time the constructor adds the static route, and enables the static route to be properly associated with the required host. Previously, you could only enable host_matching once your app was already instantiated (e.g. app.url_map.host_matching = True), but at that point the constructor would have already added the static route without host matching and an associated host, leaving the static route in a broken state. Fixes #1559.
This commit is contained in:
parent
ec18fe9477
commit
00d6e339ec
4 changed files with 46 additions and 7 deletions
|
|
@ -1188,6 +1188,25 @@ def test_static_url_path():
|
|||
assert flask.url_for('static', filename='index.html') == '/foo/index.html'
|
||||
|
||||
|
||||
def test_static_route_with_host_matching():
|
||||
app = flask.Flask(__name__, host_matching=True, static_host='example.com')
|
||||
c = app.test_client()
|
||||
rv = c.get('http://example.com/static/index.html')
|
||||
assert rv.status_code == 200
|
||||
rv.close()
|
||||
with app.test_request_context():
|
||||
rv = flask.url_for('static', filename='index.html', _external=True)
|
||||
assert rv == 'http://example.com/static/index.html'
|
||||
# Providing static_host without host_matching=True should error.
|
||||
with pytest.raises(Exception):
|
||||
flask.Flask(__name__, static_host='example.com')
|
||||
# Providing host_matching=True with static_folder but without static_host should error.
|
||||
with pytest.raises(Exception):
|
||||
flask.Flask(__name__, host_matching=True)
|
||||
# Providing host_matching=True without static_host but with static_folder=None should not error.
|
||||
flask.Flask(__name__, host_matching=True, static_folder=None)
|
||||
|
||||
|
||||
def test_none_response():
|
||||
app = flask.Flask(__name__)
|
||||
app.testing = True
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue