Fixed #508 -- Added support for 'expires' in cookies and changed session 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
This commit is contained in:
parent
41d5cff745
commit
390666ac2b
|
@ -71,6 +71,7 @@ class SessionMiddleware:
|
|||
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
|
||||
|
|
|
@ -172,9 +172,9 @@ class HttpResponse:
|
|||
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=".lawrence.com"`` will set a cookie that is readable by
|
||||
the domains www.lawrence.com, blogs.lawrence.com and
|
||||
|
|
Loading…
Reference in New Issue