Discussion:
delete_cookie() hidden behavior
Jimmy Mundane
2014-04-29 04:58:44 UTC
Permalink
Its minor, but this had me scratching my head today. Here's the gist:

@bottle.route('/setcookie')
def setcookie():
bottle.response.delete_cookie('foo')
bottle.response.set_cookie('foo', 'bar')
bottle.redirect('/getcookie')

@bottle.route('/getcookie')
def getcookie():
return bottle.request.get_cookie('foo')

I expected the route "/getcookie" to return the text "bar". Instead it
returns blank. Some digging revealed that delete_cookie() sets the
"expires" and "max_age" attributes to 0 and -1, respectively. Those
attributes stick, so even though I gave the cookie a new value, as far as
the browser was concerned it was already expired. A note about this
behavior in the documentation for delete_cookie() might save the next guy
from wasting some time.
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Jimmy Mundane
2014-04-29 05:20:32 UTC
Permalink
Its minor, but this had me scratching my head today. Here's the gist:

@bottle.route('/setcookie')
def setcookie():
bottle.response.delete_cookie('foo')
bottle.response.set_cookie('foo', 'bar')
bottle.redirect('/getcookie')

@bottle.route('/getcookie')
def getcookie():
return bottle.request.get_cookie('foo')

I expected the route "/getcookie" to return the text "bar". Instead it
returns blank. Some digging revealed that delete_cookie() sets the
"expires" and "max_age" attributes to 0 and -1, respectively. Those
attributes stick, so even though I gave the cookie a new value, as far as
the browser was concerned it was already expired. A note about this
behavior in the documentation for delete_cookie() might save the next guy
from wasting some time.
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.

---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...