Skip to content

Commit

Permalink
Fixed #3586 -- Only output "Vary: Cookie" HTTP header when the sessio…
Browse files Browse the repository at this point in the history
…n 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
  • Loading branch information
malcolmt committed Mar 8, 2007
1 parent f5f4b80 commit c651b08
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions AUTHORS
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion django/contrib/sessions/middleware.py
Expand Up @@ -10,6 +10,7 @@
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):
Expand Down Expand Up @@ -46,6 +47,7 @@ def delete_test_cookie(self):


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:
Expand All @@ -72,12 +74,14 @@ def process_request(self, request):
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:
Expand Down

0 comments on commit c651b08

Please sign in to comment.