Skip to content
Myr

Store session after callbacks. This fixes #351

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 7f4c12b · Browse files · 3 files+22 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

3 files+22 added−2 removed

  • other:+22 added−2 removed

3 files+22 added−2 removed

modified:flask/testsuite/basic.py+17 added
277 unmodified lines
278 self.assert_('set-cookie' in rv.headers)279 match = re.search(r'\bexpires=([^;]+)', rv.headers['set-cookie'])280 self.assert_(match is None)281282 def test_session_stored_last(self):283 app = flask.Flask(__name__)284 app.secret_key = 'development-key'285 app.testing = True286287 @app.after_request288 def modify_session(response):289 flask.session['foo'] = 42290 return response291 @app.route('/')292 def dump_session_contents():293 return repr(flask.session.get('foo'))294295 c = app.test_client()296 self.assert_equal(c.get('/').data, 'None')297 self.assert_equal(c.get('/').data, '42')298299 def test_flashes(self):300 app = flask.Flask(__name__)301 app.secret_key = 'testkey'302
766 unmodified lines
modified:flask/app.py+2 added-2 removed
1401 unmodified lines
1402 instance of :attr:`response_class`.1403 """1404 ctx = _request_ctx_stack.top1405 bp = ctx.request.blueprint1406 if not self.session_interface.is_null_session(ctx.session):1407 self.save_session(ctx.session, response)1406 funcs = ()1407 if bp is not None and bp in self.after_request_funcs:1408 funcs = reversed(self.after_request_funcs[bp])1409 if None in self.after_request_funcs:1410 funcs = chain(funcs, reversed(self.after_request_funcs[None]))1411 for handler in funcs:1412 response = handler(response)1413 if not self.session_interface.is_null_session(ctx.session):1414 self.save_session(ctx.session, response)1415 return response14161417 def do_teardown_request(self):1418 """Called after the actual request dispatching and will
100 unmodified lines
modified:CHANGES+3 added
18 unmodified lines
19 environ ``werkzeug.request`` will be `None` after the response was20 returned to the WSGI server but has the advantage that the garbage21 collector is not needed on CPython to tear down the request unless22 the user created circular dependencies themselves.23- Session is now stored after callbacks so that if the session payload24 is stored in the session you can still modify it in an after25 request callback.2627Version 0.8.128-------------29
294 unmodified lines