elixir-plug / plug

Compose web applications with functions
https://hex.pm/packages/plug
Other
2.84k stars 582 forks source link

Add `get_session/3` to allow providing default value #1144

Closed zolrath closed 1 year ago

zolrath commented 1 year ago

Hello!

While pairing on a project we found a need to set a default value for a session option and realized that get_session/3 doesn't exist. This allows us to set a default value when attempting to get_session when the value is nil.

Alternatives

Currently this returns the default value even if the key exists but contains nil. An alternative implementation would check if the key exists in the session and only return nil if the key does not exist.

Let us know what you think, thanks!

josevalim commented 1 year ago

:green_heart: :blue_heart: :purple_heart: :yellow_heart: :heart: