Added proper subdomain support

This commit is contained in:
Armin Ronacher 2010-06-29 01:13:40 +02:00
parent 55040d3efa
commit f195d92447
4 changed files with 38 additions and 2 deletions

View File

@ -8,6 +8,10 @@ Version 0.5
Codename to be decided, release date to be announced.
- fixed a bug with subdomains that was caused by the inability to
specify the server name. The server name can now be set with
the `SERVER_NAME` config key.
Version 0.4
-----------

View File

@ -59,8 +59,17 @@ The following configuration values are used internally by Flask:
``PERMANENT_SESSION_LIFETIME`` the lifetime of a permanent session as
:class:`datetime.timedelta` object.
``USE_X_SENDFILE`` enable/disable x-sendfile
``LOGGER_NAME`` the name of the logger
``SERVER_NAME`` the name of the server. Required for
subdomain support (eg: ``'localhost'``)
=============================== =========================================
.. versionadded:: 0.4
``LOGGER_NAME``
.. versionadded:: 0.5
``SERVER_NAME``
Configuring from Files
----------------------

View File

@ -141,7 +141,8 @@ class _RequestContext(object):
def __init__(self, app, environ):
self.app = app
self.url_adapter = app.url_map.bind_to_environ(environ)
self.url_adapter = app.url_map.bind_to_environ(environ,
server_name=app.config['SERVER_NAME'])
self.request = app.request_class(environ)
self.session = app.open_session(self.request)
if self.session is None:
@ -889,7 +890,8 @@ class Flask(_PackageBoundObject):
'SESSION_COOKIE_NAME': 'session',
'PERMANENT_SESSION_LIFETIME': timedelta(days=31),
'USE_X_SENDFILE': False,
'LOGGER_NAME': None
'LOGGER_NAME': None,
'SERVER_NAME': None
})
def __init__(self, import_name):

View File

@ -836,6 +836,26 @@ class ConfigTestCase(unittest.TestCase):
os.environ = env
class SubdomainTestCase(unittest.TestCase):
def test_basic_support(self):
app = flask.Flask(__name__)
app.config['SERVER_NAME'] = 'localhost'
@app.route('/')
def normal_index():
return 'normal index'
@app.route('/', subdomain='test')
def test_index():
return 'test index'
c = app.test_client()
rv = c.get('/', 'http://localhost/')
assert rv.data == 'normal index'
rv = c.get('/', 'http://test.localhost/')
assert rv.data == 'test index'
def suite():
from minitwit_tests import MiniTwitTestCase
from flaskr_tests import FlaskrTestCase
@ -847,6 +867,7 @@ def suite():
suite.addTest(unittest.makeSuite(SendfileTestCase))
suite.addTest(unittest.makeSuite(LoggingTestCase))
suite.addTest(unittest.makeSuite(ConfigTestCase))
suite.addTest(unittest.makeSuite(SubdomainTestCase))
if flask.json_available:
suite.addTest(unittest.makeSuite(JSONTestCase))
suite.addTest(unittest.makeSuite(MiniTwitTestCase))