Copyright | Will Thompson and Iñaki García Etxebarria |
---|---|
License | LGPL-2.1 |
Maintainer | Iñaki García Etxebarria |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Automatic cookie handling for SoupSession.
A CookieJar
stores [structcookie
]s and arrange for them to be sent with
the appropriate [classmessage
]s. CookieJar
implements
[ifacesessionFeature
], so you can add a cookie jar to a session with
[methodsession
.add_feature] or [methodsession
.add_feature_by_type].
Note that the base CookieJar
class does not support any form
of long-term cookie persistence.
Synopsis
- newtype CookieJar = CookieJar (ManagedPtr CookieJar)
- class (GObject o, IsDescendantOf CookieJar o) => IsCookieJar o
- toCookieJar :: (MonadIO m, IsCookieJar o) => o -> m CookieJar
- cookieJarAddCookie :: (HasCallStack, MonadIO m, IsCookieJar a) => a -> Cookie -> m ()
- cookieJarAddCookieFull :: (HasCallStack, MonadIO m, IsCookieJar a) => a -> Cookie -> Maybe Uri -> Maybe Uri -> m ()
- cookieJarAddCookieWithFirstParty :: (HasCallStack, MonadIO m, IsCookieJar a) => a -> Uri -> Cookie -> m ()
- cookieJarAllCookies :: (HasCallStack, MonadIO m, IsCookieJar a) => a -> m [Cookie]
- cookieJarDeleteCookie :: (HasCallStack, MonadIO m, IsCookieJar a) => a -> Cookie -> m ()
- cookieJarGetAcceptPolicy :: (HasCallStack, MonadIO m, IsCookieJar a) => a -> m CookieJarAcceptPolicy
- cookieJarGetCookieList :: (HasCallStack, MonadIO m, IsCookieJar a) => a -> Uri -> Bool -> m [Cookie]
- cookieJarGetCookieListWithSameSiteInfo :: (HasCallStack, MonadIO m, IsCookieJar a) => a -> Uri -> Maybe Uri -> Maybe Uri -> Bool -> Bool -> Bool -> m [Cookie]
- cookieJarGetCookies :: (HasCallStack, MonadIO m, IsCookieJar a) => a -> Uri -> Bool -> m (Maybe Text)
- cookieJarIsPersistent :: (HasCallStack, MonadIO m, IsCookieJar a) => a -> m Bool
- cookieJarNew :: (HasCallStack, MonadIO m) => m CookieJar
- cookieJarSetAcceptPolicy :: (HasCallStack, MonadIO m, IsCookieJar a) => a -> CookieJarAcceptPolicy -> m ()
- cookieJarSetCookie :: (HasCallStack, MonadIO m, IsCookieJar a) => a -> Uri -> Text -> m ()
- cookieJarSetCookieWithFirstParty :: (HasCallStack, MonadIO m, IsCookieJar a) => a -> Uri -> Uri -> Text -> m ()
- constructCookieJarAcceptPolicy :: (IsCookieJar o, MonadIO m) => CookieJarAcceptPolicy -> m (GValueConstruct o)
- getCookieJarAcceptPolicy :: (MonadIO m, IsCookieJar o) => o -> m CookieJarAcceptPolicy
- setCookieJarAcceptPolicy :: (MonadIO m, IsCookieJar o) => o -> CookieJarAcceptPolicy -> m ()
- constructCookieJarReadOnly :: (IsCookieJar o, MonadIO m) => Bool -> m (GValueConstruct o)
- getCookieJarReadOnly :: (MonadIO m, IsCookieJar o) => o -> m Bool
- type CookieJarChangedCallback = Cookie -> Cookie -> IO ()
- afterCookieJarChanged :: (IsCookieJar a, MonadIO m) => a -> ((?self :: a) => CookieJarChangedCallback) -> m SignalHandlerId
- onCookieJarChanged :: (IsCookieJar a, MonadIO m) => a -> ((?self :: a) => CookieJarChangedCallback) -> m SignalHandlerId
Exported types
Memory-managed wrapper type.
Instances
Eq CookieJar Source # | |
GObject CookieJar Source # | |
Defined in GI.Soup.Objects.CookieJar | |
ManagedPtrNewtype CookieJar Source # | |
Defined in GI.Soup.Objects.CookieJar toManagedPtr :: CookieJar -> ManagedPtr CookieJar | |
TypedObject CookieJar Source # | |
Defined in GI.Soup.Objects.CookieJar | |
HasParentTypes CookieJar Source # | |
Defined in GI.Soup.Objects.CookieJar | |
IsGValue (Maybe CookieJar) Source # | Convert |
Defined in GI.Soup.Objects.CookieJar gvalueGType_ :: IO GType gvalueSet_ :: Ptr GValue -> Maybe CookieJar -> IO () gvalueGet_ :: Ptr GValue -> IO (Maybe CookieJar) | |
type ParentTypes CookieJar Source # | |
Defined in GI.Soup.Objects.CookieJar |
class (GObject o, IsDescendantOf CookieJar o) => IsCookieJar o Source #
Type class for types which can be safely cast to CookieJar
, for instance with toCookieJar
.
Instances
(GObject o, IsDescendantOf CookieJar o) => IsCookieJar o Source # | |
Defined in GI.Soup.Objects.CookieJar |
toCookieJar :: (MonadIO m, IsCookieJar o) => o -> m CookieJar Source #
Methods
Click to display all available methods, including inherited ones
Methods
addCookie, addCookieFull, addCookieWithFirstParty, allCookies, bindProperty, bindPropertyFull, deleteCookie, forceFloating, freezeNotify, getv, isFloating, isPersistent, notify, notifyByPspec, ref, refSink, runDispose, stealData, stealQdata, thawNotify, unref, watchClosure.
Getters
getAcceptPolicy, getCookieList, getCookieListWithSameSiteInfo, getCookies, getData, getProperty, getQdata.
Setters
setAcceptPolicy, setCookie, setCookieWithFirstParty, setData, setDataFull, setProperty.
addCookie
:: (HasCallStack, MonadIO m, IsCookieJar a) | |
=> a |
|
-> Cookie |
|
-> m () |
Adds cookie
to jar
.
Emits the signalcookieJar
[changed] signal if we are modifying
an existing cookie or adding a valid new cookie ('valid' means
that the cookie's expire date is not in the past).
cookie
will be 'stolen' by the jar, so don't free it afterwards.
addCookieFull
cookieJarAddCookieFull Source #
:: (HasCallStack, MonadIO m, IsCookieJar a) | |
=> a |
|
-> Cookie |
|
-> Maybe Uri |
|
-> Maybe Uri |
|
-> m () |
Adds cookie
to jar
.
Emits the signalcookieJar
[changed] signal if we are modifying an existing
cookie or adding a valid new cookie ('valid' means that the cookie's expire
date is not in the past).
firstParty
will be used to reject cookies coming from third party
resources in case such a security policy is set in the jar
.
uri
will be used to reject setting or overwriting secure cookies
from insecure origins. Nothing
is treated as secure.
cookie
will be 'stolen' by the jar, so don't free it afterwards.
addCookieWithFirstParty
cookieJarAddCookieWithFirstParty Source #
:: (HasCallStack, MonadIO m, IsCookieJar a) | |
=> a |
|
-> Uri |
|
-> Cookie |
|
-> m () |
Adds cookie
to jar
.
Emits the signalcookieJar
[changed] signal if we are modifying
an existing cookie or adding a valid new cookie ('valid' means
that the cookie's expire date is not in the past).
firstParty
will be used to reject cookies coming from third party
resources in case such a security policy is set in the jar
.
cookie
will be 'stolen' by the jar, so don't free it afterwards.
For secure cookies to work properly you may want to use
[methodcookieJar
.add_cookie_full].
allCookies
:: (HasCallStack, MonadIO m, IsCookieJar a) | |
=> a |
|
-> m [Cookie] | Returns: a |
Constructs a [structgLib
.List] with every cookie inside the jar
.
The cookies in the list are a copy of the original, so you have to free them when you are done with them.
deleteCookie
cookieJarDeleteCookie Source #
:: (HasCallStack, MonadIO m, IsCookieJar a) | |
=> a |
|
-> Cookie |
|
-> m () |
Deletes cookie
from jar
.
Emits the signalcookieJar
[changed] signal.
getAcceptPolicy
cookieJarGetAcceptPolicy Source #
:: (HasCallStack, MonadIO m, IsCookieJar a) | |
=> a |
|
-> m CookieJarAcceptPolicy | Returns: the |
Gets jar
's [enumcookieJarAcceptPolicy
].
getCookieList
cookieJarGetCookieList Source #
:: (HasCallStack, MonadIO m, IsCookieJar a) | |
=> a |
|
-> Uri |
|
-> Bool |
|
-> m [Cookie] | Returns: a |
Retrieves the list of cookies that would be sent with a request to uri
as a [structgLib
.List] of Cookie
objects.
If forHttp
is True
, the return value will include cookies marked
"HttpOnly" (that is, cookies that the server wishes to keep hidden
from client-side scripting operations such as the JavaScript
document.cookies property). Since CookieJar
sets the Cookie
header itself when making the actual HTTP request, you should
almost certainly be setting forHttp
to False
if you are calling
this.
getCookieListWithSameSiteInfo
cookieJarGetCookieListWithSameSiteInfo Source #
:: (HasCallStack, MonadIO m, IsCookieJar a) | |
=> a |
|
-> Uri |
|
-> Maybe Uri |
|
-> Maybe Uri |
|
-> Bool |
|
-> Bool |
|
-> Bool |
|
-> m [Cookie] | Returns: a |
This is an extended version of [methodcookieJar
.get_cookie_list] that
provides more information required to use SameSite cookies.
See the <https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00 SameSite cookies spec> for more detailed information.
getCookies
:: (HasCallStack, MonadIO m, IsCookieJar a) | |
=> a |
|
-> Uri |
|
-> Bool |
|
-> m (Maybe Text) | Returns: the cookies, in string form, or |
Retrieves (in Cookie-header form) the list of cookies that would
be sent with a request to uri
.
If forHttp
is True
, the return value will include cookies marked
"HttpOnly" (that is, cookies that the server wishes to keep hidden
from client-side scripting operations such as the JavaScript
document.cookies property). Since CookieJar
sets the Cookie
header itself when making the actual HTTP request, you should
almost certainly be setting forHttp
to False
if you are calling
this.
isPersistent
cookieJarIsPersistent Source #
:: (HasCallStack, MonadIO m, IsCookieJar a) | |
=> a |
|
-> m Bool | Returns: |
Gets whether jar
stores cookies persistenly.
new
:: (HasCallStack, MonadIO m) | |
=> m CookieJar | Returns: a new |
setAcceptPolicy
cookieJarSetAcceptPolicy Source #
:: (HasCallStack, MonadIO m, IsCookieJar a) | |
=> a |
|
-> CookieJarAcceptPolicy |
|
-> m () |
Sets policy
as the cookie acceptance policy for jar
.
setCookie
:: (HasCallStack, MonadIO m, IsCookieJar a) | |
=> a |
|
-> Uri |
|
-> Text |
|
-> m () |
Adds cookie
to jar
, exactly as though it had appeared in a
Set-Cookie header returned from a request to uri
.
Keep in mind that if the [enumcookieJarAcceptPolicy
] set is either
CookieJarAcceptPolicyNoThirdParty
or
CookieJarAcceptPolicyGrandfatheredThirdParty
you'll need to use
[methodcookieJar
.set_cookie_with_first_party], otherwise the jar
will have no way of knowing if the cookie is being set by a third
party or not.
setCookieWithFirstParty
cookieJarSetCookieWithFirstParty Source #
:: (HasCallStack, MonadIO m, IsCookieJar a) | |
=> a |
|
-> Uri |
|
-> Uri |
|
-> Text |
|
-> m () |
Adds cookie
to jar
, exactly as though it had appeared in a
Set-Cookie header returned from a request to uri
.
firstParty
will be used to reject cookies coming from third party resources
in case such a security policy is set in the jar
.
Properties
acceptPolicy
The policy the jar should follow to accept or reject cookies.
constructCookieJarAcceptPolicy :: (IsCookieJar o, MonadIO m) => CookieJarAcceptPolicy -> m (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “accept-policy
” property. This is rarely needed directly, but it is used by new
.
getCookieJarAcceptPolicy :: (MonadIO m, IsCookieJar o) => o -> m CookieJarAcceptPolicy Source #
Get the value of the “accept-policy
” property.
When overloading is enabled, this is equivalent to
get
cookieJar #acceptPolicy
setCookieJarAcceptPolicy :: (MonadIO m, IsCookieJar o) => o -> CookieJarAcceptPolicy -> m () Source #
Set the value of the “accept-policy
” property.
When overloading is enabled, this is equivalent to
set
cookieJar [ #acceptPolicy:=
value ]
readOnly
Whether or not the cookie jar is read-only.
constructCookieJarReadOnly :: (IsCookieJar o, MonadIO m) => Bool -> m (GValueConstruct o) Source #
Construct a GValueConstruct
with valid value for the “read-only
” property. This is rarely needed directly, but it is used by new
.
getCookieJarReadOnly :: (MonadIO m, IsCookieJar o) => o -> m Bool Source #
Get the value of the “read-only
” property.
When overloading is enabled, this is equivalent to
get
cookieJar #readOnly
Signals
changed
type CookieJarChangedCallback Source #
Emitted when jar
changes.
If a cookie has been added,
newCookie
will contain the newly-added cookie and
oldCookie
will be Nothing
. If a cookie has been deleted,
oldCookie
will contain the to-be-deleted cookie and
newCookie
will be Nothing
. If a cookie has been changed,
oldCookie
will contain its old value, and newCookie
its
new value.
afterCookieJarChanged :: (IsCookieJar a, MonadIO m) => a -> ((?self :: a) => CookieJarChangedCallback) -> m SignalHandlerId Source #
Connect a signal handler for the changed signal, to be run after the default handler. When overloading is enabled, this is equivalent to
after
cookieJar #changed callback
By default the object invoking the signal is not passed to the callback.
If you need to access it, you can use the implit ?self
parameter.
Note that this requires activating the ImplicitParams
GHC extension.
onCookieJarChanged :: (IsCookieJar a, MonadIO m) => a -> ((?self :: a) => CookieJarChangedCallback) -> m SignalHandlerId Source #
Connect a signal handler for the changed signal, to be run before the default handler. When overloading is enabled, this is equivalent to
on
cookieJar #changed callback