Ticket #8061: temporary-session-key.diff
File temporary-session-key.diff, 4.1 KB (added by , 16 years ago) |
---|
-
django/contrib/sessions/middleware.py
22 22 if accessed: 23 23 patch_vary_headers(response, ('Cookie',)) 24 24 if modified or settings.SESSION_SAVE_EVERY_REQUEST: 25 if request.session.get_expire_at_browser_close():26 max_age = None27 expires = None28 else:29 max_age = request.session.get_expiry_age()30 expires_time = time.time() + max_age31 expires = cookie_date(expires_time)32 25 # Save the session data and refresh the client cookie. 33 26 request.session.save() 34 response.set_cookie(settings.SESSION_COOKIE_NAME,35 request.session.session_key , max_age=max_age,36 expires=expires, domain=settings.SESSION_COOKIE_DOMAIN,37 path=settings.SESSION_COOKIE_PATH,38 secure=settings.SESSION_COOKIE_SECURE or None)27 self.set_session_cookie(request, response, 28 request.session.session_key) 29 elif settings.SESSION_COOKIE_NAME not in request.COOKIES: 30 # Set a temporary cookie 31 self.set_session_cookie(request, response, '') 39 32 return response 33 34 def set_session_cookie(self, request, response, key): 35 if request.session.get_expire_at_browser_close(): 36 max_age = None 37 expires = None 38 else: 39 max_age = request.session.get_expiry_age() 40 expires_time = time.time() + max_age 41 expires = cookie_date(expires_time) 42 response.set_cookie(settings.SESSION_COOKIE_NAME, key, 43 max_age=max_age, expires=expires, 44 domain=settings.SESSION_COOKIE_DOMAIN, 45 path=settings.SESSION_COOKIE_PATH, 46 secure=settings.SESSION_COOKIE_SECURE or None) -
django/contrib/sessions/backends/base.py
18 18 """ 19 19 Base class for all Session classes. 20 20 """ 21 TEST_COOKIE_NAME = 'testcookie'22 TEST_COOKIE_VALUE = 'worked'23 21 24 22 def __init__(self, session_key=None): 25 23 self._session_key = session_key 26 24 self.accessed = False 27 25 self.modified = False 26 self._cookie_received = (session_key is not None) 28 27 29 28 def __contains__(self, key): 30 29 return key in self._session … … 62 61 return value 63 62 64 63 def set_test_cookie(self): 65 self[self.TEST_COOKIE_NAME] = self.TEST_COOKIE_VALUE 64 from warnings import warn 65 warn('set_test_cookie is deprecated. It is no longer required.') 66 66 67 67 def test_cookie_worked(self): 68 return self.get(self.TEST_COOKIE_NAME) == self.TEST_COOKIE_VALUE 68 from warnings import warn 69 warn('test_cookie_worked is deprecated. Use request.accepts_cookies()') 70 return self.accepts_cookies() 69 71 70 72 def delete_test_cookie(self): 71 del self[self.TEST_COOKIE_NAME] 73 from warnings import warn 74 warn('delete_test_cookie is deprecated. It is no longer required.') 72 75 76 def accepts_cookies(self): 77 return self._cookie_received 78 73 79 def encode(self, session_dict): 74 80 "Returns the given session dictionary pickled and encoded as a string." 75 81 pickled = pickle.dumps(session_dict, pickle.HIGHEST_PROTOCOL) … … 141 147 try: 142 148 return self._session_cache 143 149 except AttributeError: 144 if self._session_key is None: 150 if self._session_key: 151 self._session_cache = self.load() 152 else: 145 153 self._session_cache = {} 146 else:147 self._session_cache = self.load()148 154 return self._session_cache 149 155 150 156 _session = property(_get_session)