1
votes

I've browsed the Scotty documentation but I only see the ability to set an HTTP header which seem a bit low level.

Is there a more elegant way to achieve this? Third party libraries?

From what I can find, a solution would be to use mapHeader from Network.Wai.Util. But like mentioned this seems quite low level.

There is also the cookie package but it appears to return a fully rendered cookie 'string' only rather then being able to retrieve the key/value.

There is also: https://hackage.haskell.org/package/HTTP-4000.3.9/docs/Network-HTTP-Cookie.html but there seems to be no Expiry parameter?

1

1 Answers

1
votes

https://hackage.haskell.org/package/scotty-cookie-0.1.0.3/docs/Web-Scotty-Cookie.html https://hackage.haskell.org/package/cookie-0.4.3/docs/Web-Cookie.html

import Web.Cookie
import Web.Scotty.Cookie

setCookie $ defaultSetCookie { setCookieName = "example", setCookieValue = "cookieValue" }

The function is actually surprisingly simple:

setCookie :: (Monad m, ScottyError e)
          => SetCookie
          -> ActionT e m ()
setCookie c = addHeader "Set-Cookie" (TL.decodeUtf8 . toLazyByteString $ renderSetCookie c)