SuaveIO / suave

Suave is a simple web development F# library providing a lightweight web server and a set of combinators to manipulate route flow and task composition.
https://suave.io
Other
1.32k stars 198 forks source link

Removing keys from session state #757

Closed Rich-F-G-Mills closed 2 years ago

Rich-F-G-Mills commented 2 years ago

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.

ademar commented 2 years ago

@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.

Rich-F-G-Mills commented 2 years ago

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

Rich-F-G-Mills commented 2 years ago

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

It can be found: https://github.com/Rich-F-G-Mills/suave/commit/34834ddc298aa9c3288a7607c3e46bdc46471b9d

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

ademar commented 2 years ago

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.

Rich-F-G-Mills commented 2 years ago

@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.