joerussbowman / gaeutilities

gaeutilities - A collection of utilities to help with application development on Google Appengine
http://gaeutilities.appspot.com
BSD 3-Clause "New" or "Revised" License
78 stars 4 forks source link

CookieWriter seems to fail when cookies are resubmitted by browser #11

Closed posita closed 14 years ago

posita commented 14 years ago

I'm seeing "double encoding" behaviors when using CookieWriter. The first time I set the cookie it works:

Set-Cookie: sln_session_data="{\"sessid\": 8962091786886422048}"; expires=Mon, 15-Mar-2010 00:46:04 GMT

When the browser resubmits the cookie, the next session output from my app is something like:

Set-Cookie: sln_session_data="Set-Cookie: sln_session_data=\"{\\\"sessid\\\": 8962091786886422050}\""

Consider using this patch:

diff -Naruw appengine_utilities.orig/sessions.py appengine_utilities/sessions.py
--- appengine_utilities.orig/sessions.py    2009-09-27 20:20:26.000000000 -0700
+++ appengine_utilities/sessions.py 2010-03-14 16:15:12.000000000 -0700
@@ -552,9 +552,9 @@
                 # values available for all gets immediately.
             for k in self.cookie_vals:
                 self.cache[k] = self.cookie_vals[k]
-                # sync the input cookie with the output cookie
-                self.output_cookie["%s_data" % (self.cookie_name)] = \
-                    self.cookie["%s_data" % (self.cookie_name)]
+            # sync the input cookie with the output cookie
+            self.output_cookie["%s_data" % (self.cookie_name)] = \
+                simplejson.dumps(self.cookie_vals) #self.cookie["%s_data" % (self.cookie_name)]
         except:
             self.cookie_vals = {}
joerussbowman commented 14 years ago

Patch added, thanks again.

posita commented 14 years ago

One thing I haven't done is to verify if this patch works when using the DataStoreWriter (since the code is executed regardless of which writer is used). If you've got regression tests, I'd highly recommend running them before committing the patch (just to make sure I haven't inadvertently broken anything)....

joerussbowman commented 14 years ago

honestly, my regression tests is the demo application included, which I did run through, flipping back and forth between session types. I haven't put together anything more complex.