Skip to content

Commit

Permalink
Merge pull request #81 from kubek2k/partitioned-cookies
Browse files Browse the repository at this point in the history
Adding support to Partitioned parameter to cookies
  • Loading branch information
stepcut committed Dec 14, 2023
2 parents 4c2148c + 9a2e0df commit 165770b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Happstack/Server/Internal/Cookie.hs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ data Cookie = Cookie
, secure :: Bool
, httpOnly :: Bool
, sameSite :: SameSite
, partitioned :: Bool
} deriving(Show,Eq,Read,Typeable,Data)

-- | Specify the lifetime of a cookie.
Expand Down Expand Up @@ -102,13 +103,13 @@ calcLife Expired =

-- | Creates a cookie with a default version of 1, empty domain, a
-- path of "/", secure == False, httpOnly == False and
-- sameSite == SameSiteNoValue
-- sameSite == SameSiteNoValue and partitioned = False
--
-- see also: 'addCookie'
mkCookie :: String -- ^ cookie name
-> String -- ^ cookie value
-> Cookie
mkCookie key val = Cookie "1" "/" "" key val False False SameSiteNoValue
mkCookie key val = Cookie "1" "/" "" key val False False SameSiteNoValue False

-- | Set a Cookie in the Result.
-- The values are escaped as per RFC 2109, but some browsers may
Expand Down Expand Up @@ -147,6 +148,7 @@ mkCookieHeader mLife cookie =
++ (if httpOnly cookie then ["HttpOnly"] else [])
++ (if sameSite cookie /= SameSiteNoValue
then [displaySameSite . sameSite $ cookie] else [])
++ (if partitioned cookie then ["Partitioned"] else [])

-- | Not an supported api. Takes a cookie header and returns
-- either a String error message or an array of parsed cookies
Expand All @@ -170,7 +172,7 @@ cookiesParser = cookies
val<-value
path<-option "" $ try (cookieSep >> cookie_path)
domain<-option "" $ try (cookieSep >> cookie_domain)
return $ Cookie ver path domain (low name) val False False SameSiteNoValue
return $ Cookie ver path domain (low name) val False False SameSiteNoValue False
cookie_version = cookie_special "$Version"
cookie_path = cookie_special "$Path"
cookie_domain = cookie_special "$Domain"
Expand Down

0 comments on commit 165770b

Please sign in to comment.