Skip to content
Myr

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

5 files+43 added−3 removed

modified:docs/config.rst+9 added-1 removed
75 unmodified lines
76``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 lines
140.. versionadded:: 0.7141 ``PROPAGATE_EXCEPTIONS``, ``PRESERVE_CONTEXT_ON_EXCEPTION``142143.. versionadded:: 0.8137 ``TRAP_BAD_REQUEST_ERRORS``, ``TRAP_HTTP_EXCEPTIONS``144 ``TRAP_BAD_REQUEST_ERRORS``, ``TRAP_HTTP_EXCEPTIONS``,145 ``APPLICATION_ROOT``146147Configuring from Files148----------------------149
200 unmodified lines
modified:flask/app.py+1 added
234 unmodified lines
235 '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 lines
modified:flask/sessions.py+10 added-2 removed
125 unmodified lines
126 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]129130 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 '/'136137 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 session
34 unmodified lines
175176 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 lines
338 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()341342 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)350351 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()363364 def test_missing_session(self):365 app = flask.Flask(__name__)366 def expect_exception(f, *args, **kwargs):367 try:
1856 unmodified lines
modified:CHANGES+1 added
30 unmodified lines
31 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.3637Version 0.7.338-------------39
238 unmodified lines