-
Notifications
You must be signed in to change notification settings - Fork 23
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
Get rid of CookiedWrapperClass and Cookied altogether? #45
Comments
E.g. these errors, when we don’t specify a concrete monad:
Normally, |
Hi! Sorry for the delay. Your idea sounds great! Gotta implement :) |
Yes, so that’s wonderful. Thank you. =) But |
Hmmm, one more thought. Maybe the user shouldn’t specify Maybe Or maybe not use AuthHandler at all? 🤔 |
Hmm, things are getting complicated again... let's see. At the moment there are three types of modifiers:
And we want to simplify user-code by removing As far as I understand we cannot write a servant combinator that adds a type-level header like this: type MyAPI = "foo" :> CookiedBis :> "bar" :> ... :> Get '[JSON] Int
myHandler :: Server MyAPI
myHandler userSession = do
-- ...
-- Here compiler "knows" the header's type because of 'CookiedBis' combinator.
return (addHeader headerValue response) As you said, it's still possible to add header on lower level using 'tweakResponse'. So, I think I should:
The changes will be breaking, but they can be trivially fixed:
Are such changes alright with you? |
Yes, the way to fix them is clear!
Very! ♥ I’d do anything to get proper inference back. =) |
One more thought, which just came to me! You can almost get good inference back with a simple type-level function: type CookieProtect a
= AuthProtect "cookie-auth"
:> a
type family Unprotect (api :: k) :: k where
Unprotect (Verb a b c (Cookied d)) = Verb a b c d
Unprotect (CookieProtect api) = Unprotect api
Unprotect (a
:<|> b) = (Unprotect a
:<|> Unprotect b)
Unprotect (a
:> b) = (a
:> Unprotect b)
Unprotect a = a And now: type SearchAPI
= "search"
:> CookieProtect (QueryParam "qp1" IPv4Range
:> QueryParams "qp2" UserId
:> QueryParam "qp3" UTCTime
:> Get '[ JSON] (Cookied (SearchResults (WithId SomeId Something))))
-- instead of restating all of those types manually, let the compiler do it in `sub`,
-- and the parameters will have proper types bound to them!
serveSearch :: ServerT SearchAPI IO
serveSearch = cookied sub
where
sub :: UserSession -> ServerT (Unprotect SearchAPI) IO
sub UserSession {..} qp1 qp2 qp3 =
error "unimplemented" |
Hey,
so I’ve been thinking, given
CookiedWrapperClass
’s making type inference for endpoints more/less inconvenient, could we maybe define aCookiedBis
(cheesy name), i.e. a full combinator, used like:And then in
instance HasServer (CookiedBis :> subapi)
we could usetweakResponse
from https://hackage.haskell.org/package/servant-server-0.12/docs/Servant-Server-Internal-Router.html#v:tweakResponse to add theSet-Cookie:
headers, without changing endpoint types.I can experiment with this in our codebase and report back the results, but I’d love to hear your thoughs first, @zohl!
The text was updated successfully, but these errors were encountered: