Class CookieJar
- All Implemented Interfaces:
Proxy
,SessionFeature
- Direct Known Subclasses:
CookieJarDB
,CookieJarText
A SoupCookieJar
stores Cookie
s and arrange for them to be sent with
the appropriate Message
s. SoupCookieJar
implements
SessionFeature
, so you can add a cookie jar to a session with
Session.addFeature(org.gnome.soup.SessionFeature)
or Session.addFeatureByType(org.gnome.glib.Type)
.
Note that the base SoupCookieJar
class does not support any form
of long-term cookie persistence.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
CookieJar.Builder<B extends CookieJar.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theChangedCallback
callback.static class
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.soup.SessionFeature
SessionFeature.SessionFeatureImpl, SessionFeature.SessionFeatureInterface
-
Constructor Summary
ConstructorDescriptionCreates a newSoupCookieJar
.CookieJar
(MemorySegment address) Create a CookieJar proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Addscookie
to this CookieJar.void
addCookieFull
(Cookie cookie, @Nullable Uri uri, @Nullable Uri firstParty) Addscookie
to this CookieJar.void
addCookieWithFirstParty
(Uri firstParty, Cookie cookie) Addscookie
to this CookieJar.Constructs aGLib.List
with every cookie inside the this CookieJar.protected CookieJar
asParent()
Returns this instance as if it were its parent type.static CookieJar.Builder
<? extends CookieJar.Builder> builder()
ACookieJar.Builder
object constructs aCookieJar
with the specified properties.protected void
void
deleteCookie
(Cookie cookie) Deletescookie
from this CookieJar.void
emitChanged
(Cookie oldCookie, Cookie newCookie) Emits the "changed" signal.Gets this CookieJar'sCookieJarAcceptPolicy
.getCookieList
(Uri uri, boolean forHttp) Retrieves the list of cookies that would be sent with a request touri
as aGLib.List
ofSoupCookie
objects.getCookieListWithSameSiteInfo
(Uri uri, @Nullable Uri topLevel, @Nullable Uri siteForCookies, boolean forHttp, boolean isSafeMethod, boolean isTopLevelNavigation) This is an extended version ofgetCookieList(org.gnome.glib.Uri, boolean)
that provides more information required to use SameSite cookies.getCookies
(Uri uri, boolean forHttp) Retrieves (in Cookie-header form) the list of cookies that would be sent with a request touri
.static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the CookieJar classboolean
Gets whether this CookieJar stores cookies persistenly.onChanged
(CookieJar.ChangedCallback handler) Emitted whenjar
changes.protected void
save()
void
setAcceptPolicy
(CookieJarAcceptPolicy policy) Setspolicy
as the cookie acceptance policy for this CookieJar.void
Addscookie
to this CookieJar, exactly as though it had appeared in a Set-Cookie header returned from a request touri
.void
setCookieWithFirstParty
(Uri uri, Uri firstParty, String cookie) Addscookie
to this CookieJar, exactly as though it had appeared in a Set-Cookie header returned from a request touri
.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
CookieJar
Create a CookieJar proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
CookieJar
Creates a newSoupCookieJar
.The base
SoupCookieJar
class does not support persistent storage of cookies; use a subclass for that.- Throws:
UnsupportedPlatformException
- when run on a platform other than linux
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
addCookie
Addscookie
to this CookieJar.Emits the
CookieJar::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.- Parameters:
cookie
- aSoupCookie
-
addCookieFull
public void addCookieFull(Cookie cookie, @Nullable @Nullable Uri uri, @Nullable @Nullable Uri firstParty) Addscookie
to this CookieJar.Emits the
CookieJar::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 this CookieJar.uri
will be used to reject setting or overwriting secure cookies from insecure origins.null
is treated as secure.cookie
will be 'stolen' by the jar, so don't free it afterwards.- Parameters:
cookie
- aSoupCookie
uri
- the URI setting the cookiefirstParty
- the URI for the main document
-
addCookieWithFirstParty
Addscookie
to this CookieJar.Emits the
CookieJar::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 this CookieJar.cookie
will be 'stolen' by the jar, so don't free it afterwards.For secure cookies to work properly you may want to use
addCookieFull(org.gnome.soup.Cookie, org.gnome.glib.Uri, org.gnome.glib.Uri)
.- Parameters:
firstParty
- the URI for the main documentcookie
- aSoupCookie
-
allCookies
-
deleteCookie
Deletescookie
from this CookieJar.Emits the
CookieJar::changed
signal.- Parameters:
cookie
- aSoupCookie
-
getAcceptPolicy
Gets this CookieJar'sCookieJarAcceptPolicy
.- Returns:
- the
SoupCookieJarAcceptPolicy
set in the this CookieJar
-
getCookieList
Retrieves the list of cookies that would be sent with a request touri
as aGLib.List
ofSoupCookie
objects.If
forHttp
istrue
, 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). SinceSoupCookieJar
sets the Cookie header itself when making the actual HTTP request, you should almost certainly be settingforHttp
tofalse
if you are calling this.- Parameters:
uri
- aGUri
forHttp
- whether or not the return value is being passed directly to an HTTP operation- Returns:
- a
GSList
with the cookies in the this CookieJar that would be sent with a request touri
.
-
getCookieListWithSameSiteInfo
public SList<Cookie> getCookieListWithSameSiteInfo(Uri uri, @Nullable @Nullable Uri topLevel, @Nullable @Nullable Uri siteForCookies, boolean forHttp, boolean isSafeMethod, boolean isTopLevelNavigation) This is an extended version ofgetCookieList(org.gnome.glib.Uri, boolean)
that provides more information required to use SameSite cookies.See the [SameSite cookies spec](https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00) for more detailed information.
- Parameters:
uri
- aGUri
topLevel
- aGUri
for the top level documentsiteForCookies
- aGUri
indicating the origin to get cookies forforHttp
- whether or not the return value is being passed directly to an HTTP operationisSafeMethod
- if the HTTP method is safe, as defined by RFC 7231, ignored whenforHttp
isfalse
isTopLevelNavigation
- whether or not the HTTP request is part of top level navigation- Returns:
- a
GSList
with the cookies in the this CookieJar that would be sent with a request touri
.
-
getCookies
Retrieves (in Cookie-header form) the list of cookies that would be sent with a request touri
.If
forHttp
istrue
, 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). SinceSoupCookieJar
sets the Cookie header itself when making the actual HTTP request, you should almost certainly be settingforHttp
tofalse
if you are calling this.- Parameters:
uri
- aGUri
forHttp
- whether or not the return value is being passed directly to an HTTP operation- Returns:
- the cookies, in string form, or
null
if there are no cookies foruri
.
-
isPersistent
public boolean isPersistent()Gets whether this CookieJar stores cookies persistenly.- Returns:
true
if this CookieJar storage is persistent orfalse
otherwise.
-
setAcceptPolicy
Setspolicy
as the cookie acceptance policy for this CookieJar.- Parameters:
policy
- aSoupCookieJarAcceptPolicy
-
setCookie
Addscookie
to this CookieJar, exactly as though it had appeared in a Set-Cookie header returned from a request touri
.Keep in mind that if the
CookieJarAcceptPolicy
set is eitherCookieJarAcceptPolicy.NO_THIRD_PARTY
orCookieJarAcceptPolicy.GRANDFATHERED_THIRD_PARTY
you'll need to usesetCookieWithFirstParty(org.gnome.glib.Uri, org.gnome.glib.Uri, java.lang.String)
, otherwise the jar will have no way of knowing if the cookie is being set by a third party or not.- Parameters:
uri
- the URI setting the cookiecookie
- the stringified cookie to set
-
setCookieWithFirstParty
Addscookie
to this CookieJar, exactly as though it had appeared in a Set-Cookie header returned from a request touri
.firstParty
will be used to reject cookies coming from third party resources in case such a security policy is set in the this CookieJar.- Parameters:
uri
- the URI setting the cookiefirstParty
- the URI for the main documentcookie
- the stringified cookie to set
-
changed
-
save
protected void save() -
onChanged
Emitted whenjar
changes.If a cookie has been added,
newCookie
will contain the newly-added cookie andoldCookie
will benull
. If a cookie has been deleted,oldCookie
will contain the to-be-deleted cookie andnewCookie
will benull
. If a cookie has been changed,oldCookie
will contain its old value, andnewCookie
its new value.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitChanged
Emits the "changed" signal. SeeonChanged(org.gnome.soup.CookieJar.ChangedCallback)
. -
builder
ACookieJar.Builder
object constructs aCookieJar
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withCookieJar.Builder.build()
.
-