cookie-0.5.1: HTTP cookie parsing and rendering

Safe Haskell | Safe-Inferred
Language | Haskell2010

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
- setCookieSameSite :: SetCookie -> Maybe SameSiteOption
- setCookiePartitioned :: SetCookie -> Bool
- data SameSiteOption
- sameSiteLax :: SameSiteOption
- sameSiteStrict :: SameSiteOption
- sameSiteNone :: SameSiteOption
- parseSetCookie :: ByteString -> SetCookie
- renderSetCookie :: SetCookie -> Builder
- renderSetCookieBS :: SetCookie -> ByteString
- defaultSetCookie :: SetCookie
- def :: Default a => a
- type Cookies = [(ByteString, ByteString)]
- parseCookies :: ByteString -> Cookies
- renderCookies :: Cookies -> Builder
- renderCookiesBS :: Cookies -> ByteString
- 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 `defaultSetCookie` and override values (see http://www.yesodweb.com/book/settings-types for details):

    import Web.Cookie
    :set -XOverloadedStrings
    let cookie = defaultSetCookie { 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

Instances details

Default SetCookie Source #

    def = defaultSetCookie

Instance details Defined in Web.Cookie Methods def :: SetCookie #
NFData SetCookie Source # |
Instance details Defined in Web.Cookie Methods rnf :: SetCookie -> () Source #
Show SetCookie Source # |
Instance details Defined in Web.Cookie Methods showsPrec :: Int -> SetCookie -> ShowS Source # show :: SetCookie -> String Source # showList :: [SetCookie] -> ShowS Source #
Eq SetCookie Source # |
Instance details Defined in Web.Cookie Methods (==) :: SetCookie -> SetCookie -> Bool Source # (/=) :: SetCookie -> SetCookie -> Bool 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`

setCookieSameSite :: SetCookie -> Maybe SameSiteOption Source #

The "same site" policy of the cookie, i.e. whether it should be sent with cross-site requests. Default value: `Nothing`

setCookiePartitioned :: SetCookie -> Bool Source #

Cookies marked Partitioned are double-keyed: by the origin that sets them and the origin of the top-level page. Default value: `False`

data SameSiteOption Source #

Data type representing the options for a SameSite cookie

#### Instances

Instances details

NFData SameSiteOption Source # |
Instance details Defined in Web.Cookie Methods rnf :: SameSiteOption -> () Source #
Show SameSiteOption Source # |
Instance details Defined in Web.Cookie Methods showsPrec :: Int -> SameSiteOption -> ShowS Source # show :: SameSiteOption -> String Source # showList :: [SameSiteOption] -> ShowS Source #
Eq SameSiteOption Source # |
Instance details Defined in Web.Cookie Methods (==) :: SameSiteOption -> SameSiteOption -> Bool Source # (/=) :: SameSiteOption -> SameSiteOption -> Bool Source #

sameSiteLax :: SameSiteOption Source #

Directs the browser to send the cookie for safe requests (e.g. `GET`), but not for unsafe ones (e.g. `POST`)

sameSiteStrict :: SameSiteOption Source #

Directs the browser to not send the cookie for any cross-site request, including e.g. a user clicking a link in their email to open a page on your site.

sameSiteNone :: SameSiteOption Source #

Directs the browser to send the cookie for cross-site requests.

Since: 0.4.5

## Functions

parseSetCookie :: ByteString -> SetCookie Source #

renderSetCookie :: SetCookie -> Builder Source #

renderSetCookieBS :: SetCookie -> ByteString Source #

Since: 0.4.6

defaultSetCookie :: SetCookie Source #

A minimal `SetCookie`. All fields are `Nothing` or `False` except ``setCookieName` = "name"` and ``setCookieValue` = "value"`. You need this to construct a `SetCookie`, because it does not export a constructor. Equivalently, you may use `def`.

Since: 0.4.2.2

def :: Default a => a #

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

renderCookiesBS :: Cookies -> ByteString Source #

Since: 0.4.6

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