Copyright | Will Thompson, Iñaki García Etxebarria and Jonas Platte |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria (garetxe@gmail.com) |
Safe Haskell | None |
Language | Haskell2010 |
An HTTP cookie.
name
and value
will be set for all cookies. If the cookie is
generated from a string that appears to have no name, then name
will be the empty string.
domain
and path
give the host or domain, and path within that
host/domain, to restrict this cookie to. If domain
starts with
".", that indicates a domain (which matches the string after the
".", or any hostname that has domain
as a suffix). Otherwise, it
is a hostname and must match exactly.
expires
will be non-Nothing
if the cookie uses either the original
"expires" attribute, or the newer "max-age" attribute. If expires
is Nothing
, it indicates that neither "expires" nor "max-age" was
specified, and the cookie expires at the end of the session.
If httpOnly
is set, the cookie should not be exposed to untrusted
code (eg, javascript), so as to minimize the danger posed by
cross-site scripting attacks.
- newtype Cookie = Cookie (ManagedPtr Cookie)
- newZeroCookie :: MonadIO m => m Cookie
- noCookie :: Maybe Cookie
- data CookieAppliesToUriMethodInfo
- cookieAppliesToUri :: (HasCallStack, MonadIO m) => Cookie -> URI -> m Bool
- data CookieCopyMethodInfo
- cookieCopy :: (HasCallStack, MonadIO m) => Cookie -> m Cookie
- data CookieDomainMatchesMethodInfo
- cookieDomainMatches :: (HasCallStack, MonadIO m) => Cookie -> Text -> m Bool
- data CookieEqualMethodInfo
- cookieEqual :: (HasCallStack, MonadIO m) => Cookie -> Cookie -> m Bool
- data CookieFreeMethodInfo
- cookieFree :: (HasCallStack, MonadIO m) => Cookie -> m ()
- data CookieGetDomainMethodInfo
- cookieGetDomain :: (HasCallStack, MonadIO m) => Cookie -> m Text
- data CookieGetExpiresMethodInfo
- cookieGetExpires :: (HasCallStack, MonadIO m) => Cookie -> m Date
- data CookieGetHttpOnlyMethodInfo
- cookieGetHttpOnly :: (HasCallStack, MonadIO m) => Cookie -> m Bool
- data CookieGetNameMethodInfo
- cookieGetName :: (HasCallStack, MonadIO m) => Cookie -> m Text
- data CookieGetPathMethodInfo
- cookieGetPath :: (HasCallStack, MonadIO m) => Cookie -> m Text
- data CookieGetSecureMethodInfo
- cookieGetSecure :: (HasCallStack, MonadIO m) => Cookie -> m Bool
- data CookieGetValueMethodInfo
- cookieGetValue :: (HasCallStack, MonadIO m) => Cookie -> m Text
- cookieNew :: (HasCallStack, MonadIO m) => Text -> Text -> Text -> Text -> Int32 -> m Cookie
- cookieParse :: (HasCallStack, MonadIO m) => Text -> URI -> m (Maybe Cookie)
- data CookieSetDomainMethodInfo
- cookieSetDomain :: (HasCallStack, MonadIO m) => Cookie -> Text -> m ()
- data CookieSetExpiresMethodInfo
- cookieSetExpires :: (HasCallStack, MonadIO m) => Cookie -> Date -> m ()
- data CookieSetHttpOnlyMethodInfo
- cookieSetHttpOnly :: (HasCallStack, MonadIO m) => Cookie -> Bool -> m ()
- data CookieSetMaxAgeMethodInfo
- cookieSetMaxAge :: (HasCallStack, MonadIO m) => Cookie -> Int32 -> m ()
- data CookieSetNameMethodInfo
- cookieSetName :: (HasCallStack, MonadIO m) => Cookie -> Text -> m ()
- data CookieSetPathMethodInfo
- cookieSetPath :: (HasCallStack, MonadIO m) => Cookie -> Text -> m ()
- data CookieSetSecureMethodInfo
- cookieSetSecure :: (HasCallStack, MonadIO m) => Cookie -> Bool -> m ()
- data CookieSetValueMethodInfo
- cookieSetValue :: (HasCallStack, MonadIO m) => Cookie -> Text -> m ()
- data CookieToCookieHeaderMethodInfo
- cookieToCookieHeader :: (HasCallStack, MonadIO m) => Cookie -> m Text
- data CookieToSetCookieHeaderMethodInfo
- cookieToSetCookieHeader :: (HasCallStack, MonadIO m) => Cookie -> m Text
- clearCookieDomain :: MonadIO m => Cookie -> m ()
- cookie_domain :: AttrLabelProxy "domain"
- getCookieDomain :: MonadIO m => Cookie -> m (Maybe Text)
- setCookieDomain :: MonadIO m => Cookie -> CString -> m ()
- clearCookieExpires :: MonadIO m => Cookie -> m ()
- cookie_expires :: AttrLabelProxy "expires"
- getCookieExpires :: MonadIO m => Cookie -> m (Maybe Date)
- setCookieExpires :: MonadIO m => Cookie -> Ptr Date -> m ()
- cookie_httpOnly :: AttrLabelProxy "httpOnly"
- getCookieHttpOnly :: MonadIO m => Cookie -> m Bool
- setCookieHttpOnly :: MonadIO m => Cookie -> Bool -> m ()
- clearCookieName :: MonadIO m => Cookie -> m ()
- cookie_name :: AttrLabelProxy "name"
- getCookieName :: MonadIO m => Cookie -> m (Maybe Text)
- setCookieName :: MonadIO m => Cookie -> CString -> m ()
- clearCookiePath :: MonadIO m => Cookie -> m ()
- cookie_path :: AttrLabelProxy "path"
- getCookiePath :: MonadIO m => Cookie -> m (Maybe Text)
- setCookiePath :: MonadIO m => Cookie -> CString -> m ()
- cookie_secure :: AttrLabelProxy "secure"
- getCookieSecure :: MonadIO m => Cookie -> m Bool
- setCookieSecure :: MonadIO m => Cookie -> Bool -> m ()
- clearCookieValue :: MonadIO m => Cookie -> m ()
- cookie_value :: AttrLabelProxy "value"
- getCookieValue :: MonadIO m => Cookie -> m (Maybe Text)
- setCookieValue :: MonadIO m => Cookie -> CString -> m ()
Exported types
Methods
appliesToUri
data CookieAppliesToUriMethodInfo Source #
((~) * signature (URI -> m Bool), MonadIO m) => MethodInfo * CookieAppliesToUriMethodInfo Cookie signature Source # | |
Tests if cookie
should be sent to uri
.
(At the moment, this does not check that cookie
's domain matches
uri
, because it assumes that the caller has already done that.
But don't rely on that; it may change in the future.)
Since: 2.24
copy
data CookieCopyMethodInfo Source #
((~) * signature (m Cookie), MonadIO m) => MethodInfo * CookieCopyMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> m Cookie | Returns: a copy of |
Copies cookie
.
Since: 2.24
domainMatches
data CookieDomainMatchesMethodInfo Source #
((~) * signature (Text -> m Bool), MonadIO m) => MethodInfo * CookieDomainMatchesMethodInfo Cookie signature Source # | |
Checks if the cookie
's domain and host
match in the sense that
cookie
should be sent when making a request to host
, or that
cookie
should be accepted when receiving a response from host
.
Since: 2.30
equal
data CookieEqualMethodInfo Source #
((~) * signature (Cookie -> m Bool), MonadIO m) => MethodInfo * CookieEqualMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> Cookie |
|
-> m Bool | Returns: whether the cookies are equal. |
Tests if cookie1
and cookie2
are equal.
Note that currently, this does not check that the cookie domains match. This may change in the future.
Since: 2.24
free
data CookieFreeMethodInfo Source #
((~) * signature (m ()), MonadIO m) => MethodInfo * CookieFreeMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> m () |
Frees cookie
Since: 2.24
getDomain
data CookieGetDomainMethodInfo Source #
((~) * signature (m Text), MonadIO m) => MethodInfo * CookieGetDomainMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> m Text | Returns: |
Gets cookie
's domain
Since: 2.32
getExpires
data CookieGetExpiresMethodInfo Source #
((~) * signature (m Date), MonadIO m) => MethodInfo * CookieGetExpiresMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> m Date | Returns: |
Gets cookie
's expiration time
Since: 2.32
getHttpOnly
data CookieGetHttpOnlyMethodInfo Source #
((~) * signature (m Bool), MonadIO m) => MethodInfo * CookieGetHttpOnlyMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> m Bool | Returns: |
Gets cookie
's HttpOnly attribute
Since: 2.32
getName
data CookieGetNameMethodInfo Source #
((~) * signature (m Text), MonadIO m) => MethodInfo * CookieGetNameMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> m Text | Returns: |
Gets cookie
's name
Since: 2.32
getPath
data CookieGetPathMethodInfo Source #
((~) * signature (m Text), MonadIO m) => MethodInfo * CookieGetPathMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> m Text | Returns: |
Gets cookie
's path
Since: 2.32
getSecure
data CookieGetSecureMethodInfo Source #
((~) * signature (m Bool), MonadIO m) => MethodInfo * CookieGetSecureMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> m Bool | Returns: |
Gets cookie
's secure attribute
Since: 2.32
getValue
data CookieGetValueMethodInfo Source #
((~) * signature (m Text), MonadIO m) => MethodInfo * CookieGetValueMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> m Text | Returns: |
Gets cookie
's value
Since: 2.32
new
:: (HasCallStack, MonadIO m) | |
=> Text |
|
-> Text |
|
-> Text |
|
-> Text |
|
-> Int32 |
|
-> m Cookie | Returns: a new |
Creates a new Cookie
with the given attributes. (Use
cookieSetSecure
and cookieSetHttpOnly
if you
need to set those attributes on the returned cookie.)
If domain
starts with ".", that indicates a domain (which matches
the string after the ".", or any hostname that has domain
as a
suffix). Otherwise, it is a hostname and must match exactly.
maxAge
is used to set the "expires" attribute on the cookie; pass
-1 to not include the attribute (indicating that the cookie expires
with the current session), 0 for an already-expired cookie, or a
lifetime in seconds. You can use the constants
COOKIE_MAX_AGE_ONE_HOUR
, COOKIE_MAX_AGE_ONE_DAY
,
COOKIE_MAX_AGE_ONE_WEEK
and COOKIE_MAX_AGE_ONE_YEAR
(or
multiples thereof) to calculate this value. (If you really care
about setting the exact time that the cookie will expire, use
cookieSetExpires
.)
Since: 2.24
parse
:: (HasCallStack, MonadIO m) | |
=> Text |
|
-> URI |
|
-> m (Maybe Cookie) | Returns: a new |
Parses header
and returns a Cookie
. (If header
contains
multiple cookies, only the first one will be parsed.)
If header
does not have "path" or "domain" attributes, they will
be defaulted from origin
. If origin
is Nothing
, path will default
to "/", but domain will be left as Nothing
. Note that this is not a
valid state for a Cookie
, and you will need to fill in some
appropriate string for the domain if you want to actually make use
of the cookie.
Since: 2.24
setDomain
data CookieSetDomainMethodInfo Source #
((~) * signature (Text -> m ()), MonadIO m) => MethodInfo * CookieSetDomainMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> Text |
|
-> m () |
Sets cookie
's domain to domain
Since: 2.24
setExpires
data CookieSetExpiresMethodInfo Source #
((~) * signature (Date -> m ()), MonadIO m) => MethodInfo * CookieSetExpiresMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> Date |
|
-> m () |
Sets cookie
's expiration time to expires
. If expires
is Nothing
,
cookie
will be a session cookie and will expire at the end of the
client's session.
(This sets the same property as cookieSetMaxAge
.)
Since: 2.24
setHttpOnly
data CookieSetHttpOnlyMethodInfo Source #
((~) * signature (Bool -> m ()), MonadIO m) => MethodInfo * CookieSetHttpOnlyMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> Bool |
|
-> m () |
Sets cookie
's HttpOnly attribute to httpOnly
. If True
, cookie
will be marked as "http only", meaning it should not be exposed to
web page scripts or other untrusted code.
Since: 2.24
setMaxAge
data CookieSetMaxAgeMethodInfo Source #
((~) * signature (Int32 -> m ()), MonadIO m) => MethodInfo * CookieSetMaxAgeMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> Int32 |
|
-> m () |
Sets cookie
's max age to maxAge
. If maxAge
is -1, the cookie
is a session cookie, and will expire at the end of the client's
session. Otherwise, it is the number of seconds until the cookie
expires. You can use the constants COOKIE_MAX_AGE_ONE_HOUR
,
COOKIE_MAX_AGE_ONE_DAY
, COOKIE_MAX_AGE_ONE_WEEK
and
COOKIE_MAX_AGE_ONE_YEAR
(or multiples thereof) to calculate
this value. (A value of 0 indicates that the cookie should be
considered already-expired.)
(This sets the same property as cookieSetExpires
.)
Since: 2.24
setName
data CookieSetNameMethodInfo Source #
((~) * signature (Text -> m ()), MonadIO m) => MethodInfo * CookieSetNameMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> Text |
|
-> m () |
Sets cookie
's name to name
Since: 2.24
setPath
data CookieSetPathMethodInfo Source #
((~) * signature (Text -> m ()), MonadIO m) => MethodInfo * CookieSetPathMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> Text |
|
-> m () |
Sets cookie
's path to path
Since: 2.24
setSecure
data CookieSetSecureMethodInfo Source #
((~) * signature (Bool -> m ()), MonadIO m) => MethodInfo * CookieSetSecureMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> Bool |
|
-> m () |
Sets cookie
's secure attribute to secure
. If True
, cookie
will
only be transmitted from the client to the server over secure
(https) connections.
Since: 2.24
setValue
data CookieSetValueMethodInfo Source #
((~) * signature (Text -> m ()), MonadIO m) => MethodInfo * CookieSetValueMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> Text |
|
-> m () |
Sets cookie
's value to value
Since: 2.24
toCookieHeader
data CookieToCookieHeaderMethodInfo Source #
((~) * signature (m Text), MonadIO m) => MethodInfo * CookieToCookieHeaderMethodInfo Cookie signature Source # | |
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> m Text | Returns: the header |
Serializes cookie
in the format used by the Cookie header (ie, for
returning a cookie from a Session
to a server).
Since: 2.24
toSetCookieHeader
data CookieToSetCookieHeaderMethodInfo Source #
((~) * signature (m Text), MonadIO m) => MethodInfo * CookieToSetCookieHeaderMethodInfo Cookie signature Source # | |
cookieToSetCookieHeader Source #
:: (HasCallStack, MonadIO m) | |
=> Cookie |
|
-> m Text | Returns: the header |
Serializes cookie
in the format used by the Set-Cookie header
(ie, for sending a cookie from a Server
to a client).
Since: 2.24
Properties
domain
clearCookieDomain :: MonadIO m => Cookie -> m () Source #
cookie_domain :: AttrLabelProxy "domain" Source #
expires
clearCookieExpires :: MonadIO m => Cookie -> m () Source #
cookie_expires :: AttrLabelProxy "expires" Source #
httpOnly
cookie_httpOnly :: AttrLabelProxy "httpOnly" Source #
name
clearCookieName :: MonadIO m => Cookie -> m () Source #
cookie_name :: AttrLabelProxy "name" Source #
path
clearCookiePath :: MonadIO m => Cookie -> m () Source #
cookie_path :: AttrLabelProxy "path" Source #
secure
cookie_secure :: AttrLabelProxy "secure" Source #
value
clearCookieValue :: MonadIO m => Cookie -> m () Source #
cookie_value :: AttrLabelProxy "value" Source #