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

Safe Haskell | None

Happstack.Server.Internal.Cookie

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
- calcLife :: CookieLife -> IO (Maybe (Int, UTCTime))
- mkCookie :: String -> String -> Cookie
- mkCookieHeader :: Maybe (Int, UTCTime) -> Cookie -> String
- getCookies :: Monad m => ByteString -> m [Cookie]
- getCookie :: Monad m => String -> ByteString -> m Cookie
- getCookies' :: Monad m => ByteString -> m (Either String [Cookie])
- getCookie' :: Monad m => String -> ByteString -> m (Either String Cookie)
- parseCookies :: String -> Either String [Cookie]
- cookiesParser :: GenParser Char st [Cookie]

# 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 |

calcLife :: CookieLife -> IO (Maybe (Int, UTCTime))

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`

mkCookieHeader :: Maybe (Int, UTCTime) -> Cookie -> String

Set a Cookie in the Result. The values are escaped as per RFC 2109, but some browsers may have buggy support for cookies containing e.g. `'"'` or `' '`.

Also, it seems that chrome, safari, and other webkit browsers do not like cookies which have double quotes around the domain and reject/ignore the cookie. So, we no longer quote the domain.

internet explorer does not honor the max-age directive so we set both max-age and expires.

See `CookieLife` and `calcLife` for a convenient way of calculating the first argument to this function.

getCookies :: Monad m => ByteString -> m [Cookie]

Get all cookies from the HTTP request. The cookies are ordered per RFC from the most specific to the least specific. Multiple cookies with the same name are allowed to exist.

getCookie :: Monad m => String -> ByteString -> m Cookie

Get the most specific cookie with the given name. Fails if there is no such cookie or if the browser did not escape cookies in a proper fashion. Browser support for escaping cookies properly is very diverse.

getCookies' :: Monad m => ByteString -> m (Either String [Cookie])

getCookie' :: Monad m => String -> ByteString -> m (Either String Cookie)

parseCookies :: String -> Either String [Cookie]

Not an supported api. Takes a cookie header and returns either a String error message or an array of parsed cookies

cookiesParser :: GenParser Char st [Cookie]

not a supported api. A parser for RFC 2109 cookies