Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #512: cp-session_timeout.diff

Line 
1 Index: sessionfilter.py
2 ===================================================================
3 RCS file: /cvs/third-party/CherryPy/cherrypy/filters/sessionfilter.py,v
4 retrieving revision 1.1.1.2
5 diff -u -U15 -p -r1.1.1.2 sessionfilter.py
6 --- sessionfilter.py    12 Apr 2006 13:30:47 -0000      1.1.1.2
7 +++ sessionfilter.py    21 Apr 2006 15:50:19 -0000
8 @@ -140,34 +140,41 @@ class SessionFilter(basefilter.BaseFilte
9          else:
10              # No session_id yet
11              sess.session_id = sess.generate_session_id()
12              sess.session_data = {'_id': sess.session_id}
13              sess.on_create_session(sess.session_data)
14          # Set response cookie
15          cookie = cherrypy.response.simple_cookie
16          cookie[cookie_name] = sess.session_id
17          cookie[cookie_name]['path'] = cookie_path
18          # We'd like to use the "max-age" param as
19          #   http://www.faqs.org/rfcs/rfc2109.html indicates but IE doesn't
20          #   save it to disk and the session is lost if people close
21          #   the browser
22          #   So we have to use the old "expires" ... sigh ...
23          #cookie[cookie_name]['max-age'] = sess.session_timeout * 60
24 -        gmt_expiration_time = time.gmtime(time.time() +
25 -                (sess.session_timeout * 60))
26 -        cookie[cookie_name]['expires'] = time.strftime(
27 -                "%a, %d-%b-%Y %H:%M:%S GMT", gmt_expiration_time)
28 +
29 +        # If the cookie's 'expires' flag is set, most browsers will make the
30 +        # cookie persistent, so that it lives on past a browser restart.  If
31 +        # it is unset, the cookie should expire as soon as the browser is
32 +        # closed.  The latter behavior may be desireable, and thus can be
33 +        # turned on by settting the session_timeout to 0.
34 +        if sess.session_timeout > 0:
35 +            gmt_expiration_time = time.gmtime(time.time() +
36 +                    (sess.session_timeout * 60))
37 +            cookie[cookie_name]['expires'] = time.strftime(
38 +                    "%a, %d-%b-%Y %H:%M:%S GMT", gmt_expiration_time)
39          if cookie_domain is not None:
40              cookie[cookie_name]['domain'] = cookie_domain
41          if cookie_secure is True:
42              cookie[cookie_name]['secure'] = 1
43      
44      def before_finalize(self):
45          def saveData(body, sess):
46              # If the body is a generator, we have to save the data
47              #   *after* the generator has been consumed
48              if isinstance(body, types.GeneratorType):
49                  for line in body:
50                      yield line
51              
52              # Save session data
53              if sess.to_be_loaded is False:

Hosted by WebFaction

Log in as guest/cpguest to create tickets