Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[requesting how to proceed] saving on start #12

Closed
junhanamaki opened this issue Jul 16, 2015 · 4 comments
Closed

[requesting how to proceed] saving on start #12

junhanamaki opened this issue Jul 16, 2015 · 4 comments

Comments

@junhanamaki
Copy link
Contributor

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.

@bungle
Copy link
Owner

bungle commented Aug 3, 2015

Great, I will look at implementing API for that.

@bungle
Copy link
Owner

bungle commented Aug 4, 2015

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:

  1. session.new (creates only an session object, does not try to read client sent cookie)
  2. session.open (creates and opens a session and loads the previous state from client supplied cookie)
  3. 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

@junhanamaki
Copy link
Contributor Author

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

@bungle
Copy link
Owner

bungle commented Aug 26, 2015

I consider this to be fixed now. Please reopen if you still get problems with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants