cookie-0.4.1.6: HTTP cookie parsing and rendering

Safe Haskell | None
Language | Haskell98

Web.Cookie

Contents

- Server to client
  - Data type
  - Functions
- Client to server
  - UTF8 Version
- Expires field

Synopsis

- data SetCookie
- setCookieName :: SetCookie -> ByteString
- setCookieValue :: SetCookie -> ByteString
- setCookiePath :: SetCookie -> Maybe ByteString
- setCookieExpires :: SetCookie -> Maybe UTCTime
- setCookieMaxAge :: SetCookie -> Maybe DiffTime
- setCookieDomain :: SetCookie -> Maybe ByteString
- setCookieHttpOnly :: SetCookie -> Bool
- setCookieSecure :: SetCookie -> Bool
- parseSetCookie :: ByteString -> SetCookie
- renderSetCookie :: SetCookie -> Builder
- def :: Default a => a
- type Cookies = [(ByteString, ByteString)]
- parseCookies :: ByteString -> Cookies
- renderCookies :: Cookies -> Builder
- type CookiesText = [(Text, Text)]
- parseCookiesText :: ByteString -> CookiesText
- renderCookiesText :: CookiesText -> Builder
- expiresFormat :: String
- formatCookieExpires :: UTCTime -> ByteString
- parseCookieExpires :: ByteString -> Maybe UTCTime

# Server to client

## Data type

data SetCookie Source

Data type representing the key-value pair to use for a cookie, as well as configuration options for it.

#### Creating a SetCookie

`SetCookie` does not export a constructor; instead, use the `Default` instance to create one and override values (see http://www.yesodweb.com/book/settings-types for details):

    import Web.Cookie
    :set -XOverloadedStrings
    let cookie = def { setCookieName = "cookieName", setCookieValue = "cookieValue" }

#### Cookie Configuration

Cookies have several configuration options; a brief summary of each option is given below. For more information, see RFC 6265 or Wikipedia.

Instances

Eq SetCookie Source |
Show SetCookie Source |
Default SetCookie Source |
NFData SetCookie Source |

setCookieName :: SetCookie -> ByteString Source

The name of the cookie. Default value: `"name"`

setCookieValue :: SetCookie -> ByteString Source

The value of the cookie. Default value: `"value"`

setCookiePath :: SetCookie -> Maybe ByteString Source

The URL path for which the cookie should be sent. Default value: `Nothing` (The browser defaults to the path of the request that sets the cookie).

setCookieExpires :: SetCookie -> Maybe UTCTime Source

The time at which to expire the cookie. Default value: `Nothing` (The browser will default to expiring a cookie when the browser is closed).

setCookieMaxAge :: SetCookie -> Maybe DiffTime Source

The maximum time to keep the cookie, in seconds. Default value: `Nothing` (The browser defaults to expiring a cookie when the browser is closed).

setCookieDomain :: SetCookie -> Maybe ByteString Source

The domain for which the cookie should be sent. Default value: `Nothing` (The browser defaults to the current domain).

setCookieHttpOnly :: SetCookie -> Bool Source

Marks the cookie as "HTTP only", i.e. not accessible from Javascript. Default value: `False`

setCookieSecure :: SetCookie -> Bool Source

Instructs the browser to only send the cookie over HTTPS. Default value: `False`

## Functions

parseSetCookie :: ByteString -> SetCookie Source

renderSetCookie :: SetCookie -> Builder Source

def :: Default a => a

The default value for this type.

# Client to server

type Cookies = [(ByteString, ByteString)] Source

parseCookies :: ByteString -> Cookies Source

Decode the value of a "Cookie" request header into key/value pairs.

renderCookies :: Cookies -> Builder Source

## UTF8 Version

type CookiesText = [(Text, Text)] Source

Textual cookies. Functions assume UTF8 encoding.

parseCookiesText :: ByteString -> CookiesText Source

renderCookiesText :: CookiesText -> Builder Source

# Expires field

expiresFormat :: String Source

formatCookieExpires :: UTCTime -> ByteString Source

Format a `UTCTime` for a cookie.

parseCookieExpires :: ByteString -> Maybe UTCTime Source