diff --git a/CHANGES b/CHANGES index d77a1f50..3490f0e2 100644 --- a/CHANGES +++ b/CHANGES @@ -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 ----------- diff --git a/docs/config.rst b/docs/config.rst index 73d7c8fb..fabf6dc4 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -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 ---------------------- diff --git a/flask.py b/flask.py index a769692e..34e903cc 100644 --- a/flask.py +++ b/flask.py @@ -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): diff --git a/tests/flask_tests.py b/tests/flask_tests.py index f0f15a7b..cbf2711f 100644 --- a/tests/flask_tests.py +++ b/tests/flask_tests.py @@ -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))