cookie-0.4.2.1: HTTP cookie parsing and rendering

Safe HaskellNone
LanguageHaskell98

Web.Cookie

Contents

Synopsis

Server to client

Data type

data SetCookie

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.

setCookieName :: SetCookie -> ByteString

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

setCookieValue :: SetCookie -> ByteString

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

setCookiePath :: SetCookie -> Maybe ByteString

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

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

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

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

setCookieHttpOnly :: SetCookie -> Bool

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

setCookieSecure :: SetCookie -> Bool

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

setCookieSameSite :: SetCookie -> Maybe SameSiteOption

Marks the cookie as "same site", i.e. should not be sent with cross-site requests. Default value: Nothing

data SameSiteOption

Data type representing the options for a SameSite cookie

Functions

def :: Default a => a

The default value for this type.

Client to server

parseCookies :: ByteString -> Cookies

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

UTF8 Version

type CookiesText = [(Text, Text)]

Textual cookies. Functions assume UTF8 encoding.

Expires field

formatCookieExpires :: UTCTime -> ByteString

Format a UTCTime for a cookie.