SuaveIO/suave

Removing keys from session state

Rich-F-G-Mills opened this issue · 5 comments

The Suave documentation on sessions shows an example of how a key can be added/fetched from the session state (via StateStore)

The current implementation of StateStore provides methods for get and set.

Would there be any appetite to extend this for an unset method?

This is related to a question I asked on StackOverflow where another user has provided a work around.

@Rich-F-G-Mills Definitely unset would be a welcome addition. I find myself often setting key values to an empty string as a workaround.

@ademar Thank you for confirming... My initial concern was that I was just missing the point!

I have made a proposed code change (heavily inspired by the response to my SO question).

It can be found: Rich-F-G-Mills@34834dd

This is my first time contributing to OSS so I'm bracing for harsh feedback!

It looks good, the only change I would ask is to pass the cookie lifetime as a parameter to remove the same way set does when it calls write; otherwise calling unset may change the lifetime of the session cookie.

Then send a pull request over.

@ademar Thank you for looking it over.

This has now been done and a PR created. Note that I have also added another try block to capture any exception raised when re-serialising the new map.