Skip to content
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

Add Snap.Cookie with a Cookie type using lenses #287

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kaol
Copy link

@kaol kaol commented Sep 4, 2019

This also implements SameSite for cookies.

The change should be mostly transparent for code using the old
Cookie type. The functions that use Cookie now use a IsCookie
typeclass instead.

This change will break code that does not actually use the Cookie value but just passes it along to isNothing or the equivalent. rqCookies is no longer a field so any use of it as a record selector breaks as well but I'm not sure if that's even a concern with user code. I'm hoping that neither is too much of an issue.

Any feedback on how I implemented Snap.Cookie? It was quite lightweight and I saw no reason to split any of it to an internal module and make re-exports.

If Snap would have a major version update with code breakage then I would suggest merging Snap.Cookie to Snap.Internal.Http.Types and make the former just offer re-exports.

Kari Pahula added 2 commits September 4, 2019 08:37
This also implements SameSite for cookies.

The change should be mostly transparent for code using the old
Cookie type. The functions that use Cookie now use a IsCookie
typeclass instead.
@tom-audm
Copy link

tom-audm commented Sep 4, 2019

No opinion on the actual feature here, but can we please not include lens as a dependency in snap-core? It's a massive set of additional transitive dependencies.

https://ro-che.info/ccc/23

@kaol
Copy link
Author

kaol commented Sep 7, 2019

The main snap package already depends on lens, does snap-core get used without it a lot?

Anyhow, it would be quite possible to drop the dependency and add some module Snap.Cookie.Lens to snap which would do the makeLenses ''Cookie call instead of having it in Snap.Cookie.

@tom-audm
Copy link

tom-audm commented Sep 8, 2019

The main snap package already depends on lens, does snap-core get used without it a lot?

Not that Hackage download numbers are super reliable (because of CDNs, etc) but according to those numbers, 20% of the usage of snap-core (76084 downloads) is without snap (61009 downloads). Anecdotally also, I know multiple people who use snap-core by itself as a more lightweight tool.

@mightybyte
Copy link
Member

Agree with @tom-audm. Depending on lens in snap-core is a no-go.

I'm not quite sure what I think about the tradeoff between two Cookie types and preserving backwards compatibility. @gregorycollins any thoughts?

Copy link
Member

@gregorycollins gregorycollins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for taking so long to get to this, I'm on pandemic paternity leave and am not even looking at computers right now.

I'm definitely in favour of adding this feature. Lens as a dep for snap-core gets a downvote from me though. I'll get to that. Here's the thing, we screwed this up: in almost all of our code we have been careful to not expose our datatype constructors in public interfaces, so that the underlying datatypes can be changed without breaking user code. Somehow we missed this for Cookie, and now there's a new-ish cookie feature, and ugh.

Can we have this as an action plan?

  • remove Default instance and dependency
  • 👍 to "remove old Cookie datatype, hide constructor, move to a new module"
  • 👎 to "lens as a snap-core dep", adding get + set functions instead of lens TH
  • this will require a major version bump :(



------------------------------------------------------------------------------
instance Default Cookie where
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love Default as part of my war against "typeclasses without laws". My argument is usually: "why is writing def preferable to emptyCookie :: Cookie"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants