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

Safe Haskell | None

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
  }
- data CookieLife
  - = Session
  - | MaxAge Int
  - | Expires UTCTime
  - | Expired
- 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

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

Instances

Eq Cookie |
Data Cookie |
Read Cookie |
Show Cookie |
Typeable Cookie |
MonadReader RqEnv RqData |

data CookieLife

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

Eq CookieLife |
Ord CookieLife |
Read CookieLife |
Show CookieLife |
Typeable CookieLife |

mkCookie

Arguments

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

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

see also: `addCookie`

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

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 ()

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

see also: `addCookie`

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

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

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