Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added proper subdomain support

  • Loading branch information...
commit f195d9244756b9809bd2b00601b437f3e278b0b9 1 parent 55040d3
@mitsuhiko authored
Showing with 38 additions and 2 deletions.
  1. +4 −0 CHANGES
  2. +9 −0 docs/config.rst
  3. +4 −2 flask.py
  4. +21 −0 tests/flask_tests.py
View
4 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
-----------
View
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
: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
6 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):
View
21 tests/flask_tests.py
@@ -836,6 +836,26 @@ def test_config_from_envvar(self):
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))
Please sign in to comment.
Something went wrong with that request. Please try again.