Added proper subdomain support
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 55040d3 · Browse files · 4 files·+38 added−2 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+38 added−2 removed
- tests:+21 added−0 removed
- other:+17 added−2 removed
Provenance
- Commit
f195d92- Tree
21e9b86- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
55040d3
4 files changed+38 added−2 removed
modified:docs/config.rst+9 added
57 unmodified lines58 ``SESSION_COOKIE_NAME`` the name of the session cookie59 ``PERMANENT_SESSION_LIFETIME`` the lifetime of a permanent session as60 :class:`datetime.timedelta` object.61 ``USE_X_SENDFILE`` enable/disable x-sendfile62+``LOGGER_NAME`` the name of the logger63+``SERVER_NAME`` the name of the server. Required for64+ subdomain support (eg: ``'localhost'``)65 =============================== =========================================66 67+.. versionadded:: 0.468+ ``LOGGER_NAME``69+70+.. versionadded:: 0.571+ ``SERVER_NAME``72+73 Configuring from Files74 ----------------------75 76 Configuration becomes more useful if you can configure from a file, and58 unmodified linesmodified:tests/flask_tests.py+21 added
834 unmodified lines835 finally:836 os.environ = env837 838 839+class SubdomainTestCase(unittest.TestCase):840+841+ def test_basic_support(self):842+ app = flask.Flask(__name__)843+ app.config['SERVER_NAME'] = 'localhost'844+ @app.route('/')845+ def normal_index():846+ return 'normal index'847+ @app.route('/', subdomain='test')848+ def test_index():849+ return 'test index'850+851+ c = app.test_client()852+ rv = c.get('/', 'http://localhost/')853+ assert rv.data == 'normal index'854+855+ rv = c.get('/', 'http://test.localhost/')856+ assert rv.data == 'test index'857+858+859 def suite():860 from minitwit_tests import MiniTwitTestCase861 from flaskr_tests import FlaskrTestCase862 suite = unittest.TestSuite()3 unmodified lines866 suite.addTest(unittest.makeSuite(ModuleTestCase))867 suite.addTest(unittest.makeSuite(SendfileTestCase))868 suite.addTest(unittest.makeSuite(LoggingTestCase))869 suite.addTest(unittest.makeSuite(ConfigTestCase))870+ suite.addTest(unittest.makeSuite(SubdomainTestCase))871 if flask.json_available:872 suite.addTest(unittest.makeSuite(JSONTestCase))873 suite.addTest(unittest.makeSuite(MiniTwitTestCase))874 suite.addTest(unittest.makeSuite(FlaskrTestCase))5 unmodified linesmodified:CHANGES+4 added
6 unmodified lines7 -----------8 9 Codename to be decided, release date to be announced.10 11+- fixed a bug with subdomains that was caused by the inability to12+ specify the server name. The server name can now be set with13+ the `SERVER_NAME` config key.14+15 Version 0.416 -----------17 18 Released on June 18th 2010, codename Rakia65 unmodified linesmodified:flask.py+4 added-2 removed
139 unmodified lines140 """141 142 def __init__(self, app, environ):143 self.app = app144- self.url_adapter = app.url_map.bind_to_environ(environ)144+ self.url_adapter = app.url_map.bind_to_environ(environ,145+ server_name=app.config['SERVER_NAME'])146 self.request = app.request_class(environ)147 self.session = app.open_session(self.request)148 if self.session is None:149 self.session = _NullSession()739 unmodified lines889 'SECRET_KEY': None,890 'SESSION_COOKIE_NAME': 'session',891 'PERMANENT_SESSION_LIFETIME': timedelta(days=31),892 'USE_X_SENDFILE': False,892- 'LOGGER_NAME': None893+ 'LOGGER_NAME': None,894+ 'SERVER_NAME': None895 })896 897 def __init__(self, import_name):898 _PackageBoundObject.__init__(self, import_name)623 unmodified lines