Browse Source

Added proper subdomain support

pull/112/head
Armin Ronacher 15 years ago
parent
commit
f195d92447
  1. 4
      CHANGES
  2. 9
      docs/config.rst
  3. 6
      flask.py
  4. 21
      tests/flask_tests.py

4
CHANGES

@ -8,6 +8,10 @@ Version 0.5
Codename to be decided, release date to be announced. 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 Version 0.4
----------- -----------

9
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 ``PERMANENT_SESSION_LIFETIME`` the lifetime of a permanent session as
:class:`datetime.timedelta` object. :class:`datetime.timedelta` object.
``USE_X_SENDFILE`` enable/disable x-sendfile ``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 Configuring from Files
---------------------- ----------------------

6
flask.py

@ -141,7 +141,8 @@ class _RequestContext(object):
def __init__(self, app, environ): def __init__(self, app, environ):
self.app = app 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.request = app.request_class(environ)
self.session = app.open_session(self.request) self.session = app.open_session(self.request)
if self.session is None: if self.session is None:
@ -889,7 +890,8 @@ class Flask(_PackageBoundObject):
'SESSION_COOKIE_NAME': 'session', 'SESSION_COOKIE_NAME': 'session',
'PERMANENT_SESSION_LIFETIME': timedelta(days=31), 'PERMANENT_SESSION_LIFETIME': timedelta(days=31),
'USE_X_SENDFILE': False, 'USE_X_SENDFILE': False,
'LOGGER_NAME': None 'LOGGER_NAME': None,
'SERVER_NAME': None
}) })
def __init__(self, import_name): def __init__(self, import_name):

21
tests/flask_tests.py

@ -836,6 +836,26 @@ class ConfigTestCase(unittest.TestCase):
os.environ = env 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(): def suite():
from minitwit_tests import MiniTwitTestCase from minitwit_tests import MiniTwitTestCase
from flaskr_tests import FlaskrTestCase from flaskr_tests import FlaskrTestCase
@ -847,6 +867,7 @@ def suite():
suite.addTest(unittest.makeSuite(SendfileTestCase)) suite.addTest(unittest.makeSuite(SendfileTestCase))
suite.addTest(unittest.makeSuite(LoggingTestCase)) suite.addTest(unittest.makeSuite(LoggingTestCase))
suite.addTest(unittest.makeSuite(ConfigTestCase)) suite.addTest(unittest.makeSuite(ConfigTestCase))
suite.addTest(unittest.makeSuite(SubdomainTestCase))
if flask.json_available: if flask.json_available:
suite.addTest(unittest.makeSuite(JSONTestCase)) suite.addTest(unittest.makeSuite(JSONTestCase))
suite.addTest(unittest.makeSuite(MiniTwitTestCase)) suite.addTest(unittest.makeSuite(MiniTwitTestCase))
Loading…
Cancel
Save