Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…ion middleware to set 'expires' in addition to 'max_age'. Thanks, mark@junklight.com

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1035 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 390666ac2bf8223bede4f78a97836051bc9f9526 1 parent 41d5cff
Adrian Holovaty adrianholovaty authored
3  django/middleware/sessions.py
View
@@ -71,6 +71,7 @@ def process_response(self, request, response):
session_key = request.session.session_key or sessions.get_new_session_key()
new_session = sessions.save(session_key, request.session._session,
datetime.datetime.now() + 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, domain=SESSION_COOKIE_DOMAIN)
+ max_age=SESSION_COOKIE_AGE, expires=expires, domain=SESSION_COOKIE_DOMAIN)
return response
4 django/utils/httpwrappers.py
View
@@ -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
4 docs/request_response.txt
View
@@ -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=".lawrence.com"`` will set a cookie that is readable by
the domains www.lawrence.com, blogs.lawrence.com and
Please sign in to comment.
Something went wrong with that request. Please try again.