Ticket #3586: automatic_vary.diff

File automatic_vary.diff, 1.4 KB (added by anonymous, 9 years ago)
  • contrib/sessions/middleware.py

     
    1010class SessionWrapper(object):
    1111    def __init__(self, session_key):
    1212        self.session_key = session_key
     13        self.accessed = False
    1314        self.modified = False
    1415
    1516    def __contains__(self, key):
     
    4647
    4748    def _get_session(self):
    4849        # Lazily loads session from storage.
     50        self.accessed = True
    4951        try:
    5052            return self._session_cache
    5153        except AttributeError:
     
    7274    def process_response(self, request, response):
    7375        # If request.session was modified, or if response.session was set, save
    7476        # those changes and set a session cookie.
    75         patch_vary_headers(response, ('Cookie',))
    7677        try:
     78            accessed = request.session.accessed
    7779            modified = request.session.modified
    7880        except AttributeError:
    7981            pass
    8082        else:
     83            if accessed:
     84                patch_vary_headers(response, ('Cookie',))
    8185            if modified or settings.SESSION_SAVE_EVERY_REQUEST:
    8286                session_key = request.session.session_key or Session.objects.get_new_session_key()
    8387                if settings.SESSION_EXPIRE_AT_BROWSER_CLOSE:
Back to Top