happstack-server-7.9.3: Web related tools and services.

Safe Haskell | None
Language | Haskell2010

Happstack.Server.Cookie

Description

Functions for creating, adding, and expiring cookies. To lookup cookie values see Happstack.Server.RqData.

Synopsis

- data Cookie = Cookie {
  - cookieVersion :: String
  - cookiePath :: String
  - cookieDomain :: String
  - cookieName :: String
  - cookieValue :: String
  - secure :: Bool
  - httpOnly :: Bool
  - sameSite :: SameSite
  - partitioned :: Bool
  }
- data CookieLife
  - = Session
  - | MaxAge Int
  - | Expires UTCTime
  - | Expired
- data SameSite
  - = SameSiteLax
  - | SameSiteStrict
  - | SameSiteNone
  - | SameSiteNoValue
- mkCookie :: String -> String -> Cookie
- addCookie :: (MonadIO m, FilterMonad Response m) => CookieLife -> Cookie -> m ()
- addCookies :: (MonadIO m, FilterMonad Response m) => [(CookieLife, Cookie)] -> m ()
- expireCookie :: (MonadIO m, FilterMonad Response m) => String -> m ()

# Documentation

data Cookie Source #

a type for HTTP cookies. Usually created using `mkCookie`.

Constructors

Cookie |

Fields

- cookieVersion :: String
- cookiePath :: String
- cookieDomain :: String
- cookieName :: String
- cookieValue :: String
- secure :: Bool
- httpOnly :: Bool
- sameSite :: SameSite
- partitioned :: Bool

#### Instances

Instances details

Data Cookie Source # |

Instance details

Defined in Happstack.Server.Internal.Cookie

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Cookie -> c Cookie Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Cookie Source #

toConstr :: Cookie -> Constr Source #

dataTypeOf :: Cookie -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Cookie) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Cookie) Source #

gmapT :: (forall b. Data b => b -> b) -> Cookie -> Cookie Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Cookie -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Cookie -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Cookie -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Cookie -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Cookie -> m Cookie Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Cookie -> m Cookie Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Cookie -> m Cookie Source #

Read Cookie Source # |
Instance details Defined in Happstack.Server.Internal.Cookie Methods readsPrec :: Int -> ReadS Cookie Source # readList :: ReadS [Cookie] Source # readPrec :: ReadPrec Cookie Source # readListPrec :: ReadPrec [Cookie] Source #
Show Cookie Source # |
Instance details Defined in Happstack.Server.Internal.Cookie Methods showsPrec :: Int -> Cookie -> ShowS Source # show :: Cookie -> String Source # showList :: [Cookie] -> ShowS Source #
Eq Cookie Source # |
Instance details Defined in Happstack.Server.Internal.Cookie Methods (==) :: Cookie -> Cookie -> Bool Source # (/=) :: Cookie -> Cookie -> Bool Source #
MonadReader RqEnv RqData Source # |
Instance details Defined in Happstack.Server.RqData Methods ask :: RqData RqEnv Source # local :: (RqEnv -> RqEnv) -> RqData a -> RqData a Source # reader :: (RqEnv -> a) -> RqData a Source #

data CookieLife Source #

Specify the lifetime of a cookie.

Note that we always set the max-age and expires headers because internet explorer does not honor max-age. You can specific `MaxAge` or `Expires` and the other will be calculated for you. Choose which ever one makes your life easiest.

Constructors

Session | session cookie - expires when browser is closed
MaxAge Int | life time of cookie in seconds
Expires UTCTime | cookie expiration date
Expired | cookie already expired

#### Instances

Instances details

Read CookieLife Source # |
Instance details Defined in Happstack.Server.Internal.Cookie Methods readsPrec :: Int -> ReadS CookieLife Source # readList :: ReadS [CookieLife] Source # readPrec :: ReadPrec CookieLife Source # readListPrec :: ReadPrec [CookieLife] Source #
Show CookieLife Source # |
Instance details Defined in Happstack.Server.Internal.Cookie Methods showsPrec :: Int -> CookieLife -> ShowS Source # show :: CookieLife -> String Source # showList :: [CookieLife] -> ShowS Source #
Eq CookieLife Source # |
Instance details Defined in Happstack.Server.Internal.Cookie Methods (==) :: CookieLife -> CookieLife -> Bool Source # (/=) :: CookieLife -> CookieLife -> Bool Source #
Ord CookieLife Source # |

Instance details

Defined in Happstack.Server.Internal.Cookie

Methods

compare :: CookieLife -> CookieLife -> Ordering Source #

(<) :: CookieLife -> CookieLife -> Bool Source #

(<=) :: CookieLife -> CookieLife -> Bool Source #

(>) :: CookieLife -> CookieLife -> Bool Source #

(>=) :: CookieLife -> CookieLife -> Bool Source #

max :: CookieLife -> CookieLife -> CookieLife Source #

min :: CookieLife -> CookieLife -> CookieLife Source #

data SameSite Source #

Options for specifying third party cookie behaviour.

Note that most or all web clients require the cookie to be secure if "none" is specified.

Constructors

SameSiteLax | The cookie is sent in first party contexts as well as linked requests initiated from other contexts.
SameSiteStrict | The cookie is sent in first party contexts only.
SameSiteNone | The cookie is sent in first as well as third party contexts if the cookie is secure.
SameSiteNoValue | The default; used if you do not wish a SameSite attribute present at all.

#### Instances

Instances details

Data SameSite Source # |

Instance details

Defined in Happstack.Server.Internal.Cookie

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> SameSite -> c SameSite Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c SameSite Source #

toConstr :: SameSite -> Constr Source #

dataTypeOf :: SameSite -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c SameSite) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c SameSite) Source #

gmapT :: (forall b. Data b => b -> b) -> SameSite -> SameSite Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> SameSite -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> SameSite -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> SameSite -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> SameSite -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> SameSite -> m SameSite Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> SameSite -> m SameSite Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> SameSite -> m SameSite Source #

Read SameSite Source # |
Instance details Defined in Happstack.Server.Internal.Cookie Methods readsPrec :: Int -> ReadS SameSite Source # readList :: ReadS [SameSite] Source # readPrec :: ReadPrec SameSite Source # readListPrec :: ReadPrec [SameSite] Source #
Show SameSite Source # |
Instance details Defined in Happstack.Server.Internal.Cookie Methods showsPrec :: Int -> SameSite -> ShowS Source # show :: SameSite -> String Source # showList :: [SameSite] -> ShowS Source #
Eq SameSite Source # |
Instance details Defined in Happstack.Server.Internal.Cookie Methods (==) :: SameSite -> SameSite -> Bool Source # (/=) :: SameSite -> SameSite -> Bool Source #
Ord SameSite Source # |

Instance details

Defined in Happstack.Server.Internal.Cookie

Methods

compare :: SameSite -> SameSite -> Ordering Source #

(<) :: SameSite -> SameSite -> Bool Source #

(<=) :: SameSite -> SameSite -> Bool Source #

(>) :: SameSite -> SameSite -> Bool Source #

(>=) :: SameSite -> SameSite -> Bool Source #

max :: SameSite -> SameSite -> SameSite Source #

min :: SameSite -> SameSite -> SameSite Source #

mkCookie Source #

Arguments

:: String | cookie name
-> String | cookie value
-> Cookie |

Creates a cookie with a default version of 1, empty domain, a path of "/", secure == False, httpOnly == False and sameSite == SameSiteNoValue and partitioned = False

see also: `addCookie`

addCookie :: (MonadIO m, FilterMonad Response m) => CookieLife -> Cookie -> m () Source #

Add the `Cookie` to `Response`.

example

    main = simpleHTTP nullConf $
      do addCookie Session (mkCookie "name" "value")
         ok $ "You now have a session cookie."

see also: `addCookies`

addCookies :: (MonadIO m, FilterMonad Response m) => [(CookieLife, Cookie)] -> m () Source #

Add the list `Cookie` to the `Response`.

see also: `addCookie`

expireCookie :: (MonadIO m, FilterMonad Response m) => String -> m () Source #

Expire the named cookie immediately and set the cookie value to `""`

    main = simpleHTTP nullConf $
      do expireCookie "name"
         ok $ "The cookie has been expired."