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

Adding support to Partitioned parameter to cookies #81

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading