Mark session as written when updating options#142
Merged
appleboy merged 1 commit intogin-contrib:masterfrom Dec 21, 2021
Merged
Mark session as written when updating options#142appleboy merged 1 commit intogin-contrib:masterfrom
appleboy merged 1 commit intogin-contrib:masterfrom
Conversation
|
@appleboy do you think this can be merged? Any suggestion from your side on this? |
appleboy
approved these changes
Dec 21, 2021
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR changes the behavior of the Options() method.
Currently, updating session options does set the
writtenflag totrue. This causes an issue when expiring/destroying a session, for example, because changes to session options will not be updated unless a key/value update has been made. If a developer wants to expire a session, they must set MaxAge to -1 and then make a trivial call to a method like Set() to ensure the options change will persist:Documentation from the session stores, like this snippet from the memstore source, indicate that setting MaxAge to -1 should immediately expire a session:
https://github.com/quasoft/memstore/blob/2bce066d2b0b885eab067015d658dfd8ec1880e0/memstore.go#L103
To make this library more usable, I've updated the
Options()method to mark the session as written when session options have been updated, saving the additional call:Passing tests, including a case to test this behavior, can be found here.