Skip to content

Instantly share code, notes, and snippets.

@Woody88
Created March 26, 2018 17:14
Show Gist options
  • Save Woody88/3d24adabf011f7706d7f0afdecee7cc5 to your computer and use it in GitHub Desktop.
Save Woody88/3d24adabf011f7706d7f0afdecee7cc5 to your computer and use it in GitHub Desktop.
import Web.Cookie (SetCookie,parseSetCookie,renderSetCookie)
-- |
-- >>> let Right c = parseUrlPiece "SESSID=r2t5uvjq435r4q7ib3vtdjq120" :: Either Text SetCookie
-- >>> toUrlPiece c
-- "\"SESSID=r2t5uvjq435r4q7ib3vtdjq120\""
instance ToHttpApiData SetCookie where
toUrlPiece = showt . BS.toLazyByteString . renderSetCookie
toEncodedUrlPiece = renderSetCookie
-- |
-- >> parseUrlPiece "SESSID=r2t5uvjq435r4q7ib3vtdjq120" :: Either Text SetCookie
-- Right (SetCookie {setCookieName = "SESSID", setCookieValue = "r2t5uvjq435r4q7ib3vtdjq120", setCookiePath = Nothing, setCookieExpires = Nothing,
-- setCookieMaxAge = Nothing, setCookieDomain = Nothing, setCookieHttpOnly = False, setCookieSecure = False, setCookieSameSite = Nothing})
instance FromHttpApiData SetCookie where
parseUrlPiece = parseHeader . encodeUtf8
parseHeader = Right . parseSetCookie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment