Added the APPLICATION_ROOT configuration variable which is used by session backends.
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 45d963d · Browse files · 5 files·+43 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+43 added−3 removed
- tests:+22 added−0 removed
- other:+21 added−3 removed
Provenance
- Commit
c844d02- Tree
f8b8b15- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
45d963d
5 files changed+43 added−3 removed
modified:docs/config.rst+9 added-1 removed
75 unmodified lines76 ``LOGGER_NAME`` the name of the logger77 ``SERVER_NAME`` the name and port number of the server.78 Required for subdomain support (e.g.:79 ``'localhost:5000'``)80+``APPLICATION_ROOT`` If the application does not occupy81+ a whole domain or subdomain this can82+ be set to the path where the application83+ is configured to live. This is for84+ session cookie as path value. If85+ domains are used, this should be86+ ``None``.87 ``MAX_CONTENT_LENGTH`` If set to a value in bytes, Flask will88 reject incoming requests with a89 content length greater than this by90 returning a 413 status code.49 unmodified lines140 .. versionadded:: 0.7141 ``PROPAGATE_EXCEPTIONS``, ``PRESERVE_CONTEXT_ON_EXCEPTION``142 143 .. versionadded:: 0.8137- ``TRAP_BAD_REQUEST_ERRORS``, ``TRAP_HTTP_EXCEPTIONS``144+ ``TRAP_BAD_REQUEST_ERRORS``, ``TRAP_HTTP_EXCEPTIONS``,145+ ``APPLICATION_ROOT``146 147 Configuring from Files148 ----------------------149 200 unmodified linesmodified:flask/app.py+1 added
234 unmodified lines235 'PERMANENT_SESSION_LIFETIME': timedelta(days=31),236 'USE_X_SENDFILE': False,237 'LOGGER_NAME': None,238 'SERVER_NAME': None,239+ 'APPLICATION_ROOT': None,240 'MAX_CONTENT_LENGTH': None,241 'TRAP_BAD_REQUEST_ERRORS': False,242 'TRAP_HTTP_EXCEPTIONS': False243 })1294 unmodified linesmodified:flask/sessions.py+10 added-2 removed
125 unmodified lines126 if app.config['SERVER_NAME'] is not None:127 # chop of the port which is usually not supported by browsers128 return '.' + app.config['SERVER_NAME'].rsplit(':', 1)[0]129 130+ def get_cookie_path(self, app):131+ """Returns the path for which the cookie should be valid. The132+ default implementation uses the value from the ``APPLICATION_ROOT``133+ configuration variable or uses ``/`` if it's `None`.134+ """135+ return app.config['APPLICATION_ROOT'] or '/'136+137 def get_expiration_time(self, app, session):138 """A helper method that returns an expiration date for the session139 or `None` if the session is linked to the browser session. The140 default implementation returns now + the permanent session34 unmodified lines175 176 def save_session(self, app, session, response):177 expires = self.get_expiration_time(app, session)178 domain = self.get_cookie_domain(app)179+ path = self.get_cookie_path(app)180 if session.modified and not session:173- response.delete_cookie(app.session_cookie_name,181+ response.delete_cookie(app.session_cookie_name, path=path,182 domain=domain)183 else:176- session.save_cookie(response, app.session_cookie_name,184+ session.save_cookie(response, app.session_cookie_name, path=path,185 expires=expires, httponly=True, domain=domain)modified:tests/flask_tests.py+22 added
337 unmodified lines338 rv = app.test_client().get('/', 'http://example.com:8080/')339 assert 'domain=.example.com' in rv.headers['set-cookie'].lower()340 assert 'httponly' in rv.headers['set-cookie'].lower()341 342+ def test_session_using_application_root(self):343+ class PrefixPathMiddleware(object):344+ def __init__(self, app, prefix):345+ self.app = app346+ self.prefix = prefix347+ def __call__(self, environ, start_response):348+ environ['SCRIPT_NAME'] = self.prefix349+ return self.app(environ, start_response)350+351+ app = flask.Flask(__name__)352+ app.wsgi_app = PrefixPathMiddleware(app.wsgi_app, '/bar')353+ app.config.update(354+ SECRET_KEY='foo',355+ APPLICATION_ROOT='/bar'356+ )357+ @app.route('/')358+ def index():359+ flask.session['testing'] = 42360+ return 'Hello World'361+ rv = app.test_client().get('/', 'http://example.com:8080/')362+ assert 'path=/bar' in rv.headers['set-cookie'].lower()363+364 def test_missing_session(self):365 app = flask.Flask(__name__)366 def expect_exception(f, *args, **kwargs):367 try:1856 unmodified linesmodified:CHANGES+1 added
30 unmodified lines31 drop files that are modified at runtime (uploads etc.). Also this is32 conceptionally only instance depending and outside version control so it's33 the perfect place to put configuration files etc. For more information34 see :ref:`instance-folders`.35+- Added the ``APPLICATION_ROOT`` configuration variable.36 37 Version 0.7.338 -------------39 238 unmodified lines