Search code examples
pythoncookiestornado

Tornado secure cookie expiration (aka secure session cookie)


How can I set in Tornado a secure cookie that expires when the browser is closed?
If I use set_cookie I can do this without passing extra arguments (I just set the cookie), but how if I have to use set_secure_cookie?

I tried almost everything:

  • passing nothing: expiration is set to its default value, that is 1 month
  • passing an integer value: the value is considered as day, i.e. 1 means 1 day
  • passing a float value: it works, for example setting 0.1 it means almost one hour and a half

Solution

  • It seems to me that you are really on the right track. You try lower and lower values, and the cookie has a lower and lower expiration time.

    Pass expires_days=None to make it a session cookie (which expires when the browser is closed).