-
Notifications
You must be signed in to change notification settings - Fork 20
Do not return new cookies when session isn’t changed #53
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
base: main
Are you sure you want to change the base?
Conversation
9ef8469 to
06ff52c
Compare
|
This looks okay to me. It seems robust to compare with the original value. @jeremyevans do you have any opinion on this? |
|
For reference, I did something like this in the past: https://github.com/socketry/utopia/blob/main/lib/utopia/session/lazy_hash.rb Tracking whether any changes were made. But if you changed it to a new value and then back to the original, my code would not pick that up, but this PR would. |
06ff52c to
b086a5b
Compare
jeremyevans
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are my thoughts from a brief review. Note that I don't follow rack-session development, so this is not a particularly informed review.
lib/rack/session/cookie.rb
Outdated
| return if request.session.to_h == request.get_header(RACK_SESSION_WAS) && | ||
| !request.get_header(RACK_SESSION_OPTIONS).fetch(:renew, false) && | ||
| !cookie[:expires] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would reverse the order of operations here. Only do the request.session conversion if the other two cheaper checks pass.
As mentioned in the other comment, instead of request.session.to_h, I would compare using marshal/json to avoid issues when modifying nested structures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opt to compare using ruby object here to avoid ordering mismatch that could happen during marshal/json. I think we don't intend to modify RACK_SESSION_WAS, I hope that could work in this case. Please let me know what you think.
|
@jeremyevans Thanks for the review. I have updated the code in 445c2d1 |
Close #52