Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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 authored November 01, 2005
3  django/middleware/sessions.py
@@ -71,6 +71,7 @@ def process_response(self, request, response):
71 71
             session_key = request.session.session_key or sessions.get_new_session_key()
72 72
             new_session = sessions.save(session_key, request.session._session,
73 73
                 datetime.datetime.now() + datetime.timedelta(seconds=SESSION_COOKIE_AGE))
  74
+            expires = datetime.datetime.strftime(datetime.datetime.utcnow() + datetime.timedelta(seconds=SESSION_COOKIE_AGE), "%a, %d-%b-%Y %H:%M:%S GMT")
74 75
             response.set_cookie(SESSION_COOKIE_NAME, session_key,
75  
-                max_age=SESSION_COOKIE_AGE, domain=SESSION_COOKIE_DOMAIN)
  76
+                max_age=SESSION_COOKIE_AGE, expires=expires, domain=SESSION_COOKIE_DOMAIN)
76 77
         return response
4  django/utils/httpwrappers.py
@@ -172,9 +172,9 @@ def has_header(self, header):
172 172
                 return True
173 173
         return False
174 174
 
175  
-    def set_cookie(self, key, value='', max_age=None, path='/', domain=None, secure=None):
  175
+    def set_cookie(self, key, value='', max_age=None, expires=None, path='/', domain=None, secure=None):
176 176
         self.cookies[key] = value
177  
-        for var in ('max_age', 'path', 'domain', 'secure'):
  177
+        for var in ('max_age', 'path', 'domain', 'secure', 'expires'):
178 178
             val = locals()[var]
179 179
             if val is not None:
180 180
                 self.cookies[key][var.replace('_', '-')] = val
4  docs/request_response.txt
@@ -284,12 +284,14 @@ Methods
284 284
     Returns ``True`` or ``False`` based on a case-insensitive check for a
285 285
     header with the given name.
286 286
 
287  
-``set_cookie(key, value='', max_age=None, path='/', domain=None, secure=None)``
  287
+``set_cookie(key, value='', max_age=None, expires=None, path='/', domain=None, secure=None)``
288 288
     Sets a cookie. The parameters are the same as in the `cookie Morsel`_
289 289
     object in the Python standard library.
290 290
 
291 291
         * ``max_age`` should be a number of seconds, or ``None`` (default) if
292 292
           the cookie should last only as long as the client's browser session.
  293
+        * ``expires`` should be a string in the format
  294
+          ``"Wdy, DD-Mon-YY HH:MM:SS GMT"``.
293 295
         * Use ``domain`` if you want to set a cross-domain cookie. For example,
294 296
           ``domain=".lawrence.com"`` will set a cookie that is readable by
295 297
           the domains www.lawrence.com, blogs.lawrence.com and

0 notes on commit 390666a

Please sign in to comment.
Something went wrong with that request. Please try again.