Don't send session cookie unless session is dirty.
authorFredrik Tolf <fredrik@dolda2000.com>
Fri, 27 May 2011 00:18:23 +0000 (02:18 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Fri, 27 May 2011 00:18:23 +0000 (02:18 +0200)
wrw/session.py

index 1fded4a..9e91ad9 100644 (file)
@@ -129,18 +129,17 @@ class db(object):
             except KeyError:
                 sess = session()
                 self.live[sess.id] = sess
-                req.oncommit(self.addcookie)
+                sess.new = True
         req.oncommit(self.ckfreeze)
         return sess
 
-    def addcookie(self, req):
-        sess = req.item(self.fetch)
-        cookie.add(req, self.cookiename, sess.id, self.path)
-
     def ckfreeze(self, req):
         sess = req.item(self.fetch)
         if sess.dirty():
             try:
+                if getattr(sess, "new", False):
+                    cookie.add(req, self.cookiename, sess.id, self.path)
+                    del sess.new
                 self.freeze(sess)
             except:
                 pass