Browse files

Fixed #508 -- Added support for 'expires' in cookies and changed sess…

…ion middleware to set 'expires' in addition to 'max_age'. Thanks,

git-svn-id: bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 41d5cff commit 390666ac2bf8223bede4f78a97836051bc9f9526 @adrianholovaty adrianholovaty committed Nov 1, 2005
Showing with 7 additions and 4 deletions.
  1. +2 −1 django/middleware/
  2. +2 −2 django/utils/
  3. +3 −1 docs/request_response.txt
@@ -71,6 +71,7 @@ def process_response(self, request, response):
session_key = request.session.session_key or sessions.get_new_session_key()
new_session =, request.session._session, + datetime.timedelta(seconds=SESSION_COOKIE_AGE))
+ expires = datetime.datetime.strftime(datetime.datetime.utcnow() + datetime.timedelta(seconds=SESSION_COOKIE_AGE), "%a, %d-%b-%Y %H:%M:%S GMT")
response.set_cookie(SESSION_COOKIE_NAME, session_key,
+ max_age=SESSION_COOKIE_AGE, expires=expires, domain=SESSION_COOKIE_DOMAIN)
return response
@@ -172,9 +172,9 @@ def has_header(self, header):
return True
return False
- def set_cookie(self, key, value='', max_age=None, path='/', domain=None, secure=None):
+ def set_cookie(self, key, value='', max_age=None, expires=None, path='/', domain=None, secure=None):
self.cookies[key] = value
- for var in ('max_age', 'path', 'domain', 'secure'):
+ for var in ('max_age', 'path', 'domain', 'secure', 'expires'):
val = locals()[var]
if val is not None:
self.cookies[key][var.replace('_', '-')] = val
@@ -284,12 +284,14 @@ Methods
Returns ``True`` or ``False`` based on a case-insensitive check for a
header with the given name.
-``set_cookie(key, value='', max_age=None, path='/', domain=None, secure=None)``
+``set_cookie(key, value='', max_age=None, expires=None, path='/', domain=None, secure=None)``
Sets a cookie. The parameters are the same as in the `cookie Morsel`_
object in the Python standard library.
* ``max_age`` should be a number of seconds, or ``None`` (default) if
the cookie should last only as long as the client's browser session.
+ * ``expires`` should be a string in the format
+ ``"Wdy, DD-Mon-YY HH:MM:SS GMT"``.
* Use ``domain`` if you want to set a cross-domain cookie. For example,
``domain=""`` will set a cookie that is readable by
the domains, and

0 comments on commit 390666a

Please sign in to comment.