Fixed #3586 -- Only output "Vary: Cookie" HTTP header when the session object
is accessed. Leads to better caching performance. Thanks, Owen Griffiths. git-svn-id: http://code.djangoproject.com/svn/django/trunk@4680 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f5f4b807e4
commit
c651b08f39
1
AUTHORS
1
AUTHORS
|
@ -89,6 +89,7 @@ answer newbie questions, and generally made Django that much better:
|
||||||
Baishampayan Ghose
|
Baishampayan Ghose
|
||||||
martin.glueck@gmail.com
|
martin.glueck@gmail.com
|
||||||
Simon Greenhill <dev@simon.net.nz>
|
Simon Greenhill <dev@simon.net.nz>
|
||||||
|
Owen Griffiths
|
||||||
Espen Grindhaug <http://grindhaug.org/>
|
Espen Grindhaug <http://grindhaug.org/>
|
||||||
Brian Harring <ferringb@gmail.com>
|
Brian Harring <ferringb@gmail.com>
|
||||||
Brant Harris
|
Brant Harris
|
||||||
|
|
|
@ -10,6 +10,7 @@ TEST_COOKIE_VALUE = 'worked'
|
||||||
class SessionWrapper(object):
|
class SessionWrapper(object):
|
||||||
def __init__(self, session_key):
|
def __init__(self, session_key):
|
||||||
self.session_key = session_key
|
self.session_key = session_key
|
||||||
|
self.accessed = False
|
||||||
self.modified = False
|
self.modified = False
|
||||||
|
|
||||||
def __contains__(self, key):
|
def __contains__(self, key):
|
||||||
|
@ -46,6 +47,7 @@ class SessionWrapper(object):
|
||||||
|
|
||||||
def _get_session(self):
|
def _get_session(self):
|
||||||
# Lazily loads session from storage.
|
# Lazily loads session from storage.
|
||||||
|
self.accessed = True
|
||||||
try:
|
try:
|
||||||
return self._session_cache
|
return self._session_cache
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
@ -72,12 +74,14 @@ class SessionMiddleware(object):
|
||||||
def process_response(self, request, response):
|
def process_response(self, request, response):
|
||||||
# If request.session was modified, or if response.session was set, save
|
# If request.session was modified, or if response.session was set, save
|
||||||
# those changes and set a session cookie.
|
# those changes and set a session cookie.
|
||||||
patch_vary_headers(response, ('Cookie',))
|
|
||||||
try:
|
try:
|
||||||
|
accessed = request.session.accessed
|
||||||
modified = request.session.modified
|
modified = request.session.modified
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
|
if accessed:
|
||||||
|
patch_vary_headers(response, ('Cookie',))
|
||||||
if modified or settings.SESSION_SAVE_EVERY_REQUEST:
|
if modified or settings.SESSION_SAVE_EVERY_REQUEST:
|
||||||
session_key = request.session.session_key or Session.objects.get_new_session_key()
|
session_key = request.session.session_key or Session.objects.get_new_session_key()
|
||||||
if settings.SESSION_EXPIRE_AT_BROWSER_CLOSE:
|
if settings.SESSION_EXPIRE_AT_BROWSER_CLOSE:
|
||||||
|
|
Loading…
Reference in New Issue