[requesting how to proceed] saving on start
junhanamaki opened this issue · 4 comments
Hi.
I've been using your library and I've noticed that when I do session.start() for the first time it will set a Set-Cookie in header, because it calls method regenerate. This is not desired when I just want to read and check if session exists. I could do this by first checking if a cookie named session is present, but I think it would be best to delegate this to resty-session, especially since we could change the name of the key and so on, so for now I removed the save instruct on regenerate (since I don't use it directly and I end up calling save after setting some data anyway). What do you think is the best way to proceed?
Thanks for the awesome library btw.
Great, I will look at implementing API for that.
Hi,
In my latest commit:
c35ec80
I did introduce a new method/function:
session.open
This works the same as session.start, but it will not set up a cookie or check if it needs to be reneved.
So you can check if session is present like this:
local session, present = session.open()
if present then
ngx.print("session was present")
else
ngx.pring("no session was present")
end
-- You can also check session.present and it works the same:
local session = session.open()
if session.present then
ngx.print("session was present")
else
ngx.pring("no session was present")
end
Can you please check that this fixes your issue. I may then make a new release.
So, to create a session you can use one of these constructors:
session.new
(creates only an session object, does not try to read client sent cookie)session.open
(creates and opens a session and loads the previous state from client supplied cookie)session.start
(creates and opens a session, loads the previous state and also manages the cookie renewing. In case of a new session will also set up a cookie).
So you can:
local s = session.new()
s:open()
s:start()
-- which is same as:
local s = session.open()
s:start()
-- which is same as:
local s = session.start()
See also a new documentation on readme. There are new fields as well, like:
session.present
session.opened
session.started
session.destroyed
Regards
Aapo
Hi.
Thanks for the quick input and work, this is exactly what I was hoping for!
... Yet we removed sessions via cookie from the project so we're not using resty-session anymore, so it's not trivial for me to test it at the moment. However as soon as I can I'll try to rollback to a previous version to test it and report to you.
Best regards,
Jun Hanamaki
I consider this to be fixed now. Please reopen if you still get problems with it.