Class CookieJar
- All Implemented Interfaces:
SessionFeature,Proxy
- Direct Known Subclasses:
CookieJarDB,CookieJarText
A SoupCookieJar stores Cookies and arrange for them to be sent with
the appropriate Messages. 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
Nested ClassesModifier and TypeClassDescriptionstatic classCookieJar.Builder<B extends CookieJar.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static interfaceFunctional interface declaration of theChangedCallbackcallback.static classNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface org.gnome.soup.SessionFeature
SessionFeature.SessionFeature$Impl, SessionFeature.SessionFeatureInterface -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new CookieJar.CookieJar(MemorySegment address) Create a CookieJar proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionvoidAddscookietojar.voidaddCookieFull(Cookie cookie, @Nullable Uri uri, @Nullable Uri firstParty) Addscookietojar.voidaddCookieWithFirstParty(Uri firstParty, Cookie cookie) Addscookietojar.Constructs aGLib.Listwith every cookie inside thejar.protected CookieJarasParent()Returns this instance as if it were its parent type.static CookieJar.Builder<? extends CookieJar.Builder> builder()ACookieJar.Builderobject constructs aCookieJarwith the specified properties.protected voidvoiddeleteCookie(Cookie cookie) Deletescookiefromjar.voidemitChanged(@Nullable Cookie oldCookie, @Nullable Cookie newCookie) Emits the "changed" signal.Getsjar'sCookieJarAcceptPolicy.getCookieList(Uri uri, boolean forHttp) Retrieves the list of cookies that would be sent with a request tourias aGLib.ListofSoupCookieobjects.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.@Nullable StringgetCookies(Uri uri, boolean forHttp) Retrieves (in Cookie-header form) the list of cookies that would be sent with a request touri.static MemoryLayoutThe memory layout of the native struct.static @Nullable TypegetType()Get the GType of the CookieJar classbooleanGets whether this CookieJar stores cookies persistenly.onChanged(CookieJar.ChangedCallback handler) Emitted whenjarchanges.protected voidsave()voidsetAcceptPolicy(CookieJarAcceptPolicy policy) Setspolicyas the cookie acceptance policy forjar.voidAddscookietojar,exactly as though it had appeared in a Set-Cookie header returned from a request touri.voidsetCookieWithFirstParty(Uri uri, Uri firstParty, String cookie) Addscookietojar,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, 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, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.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
public CookieJar()Creates a new CookieJar.
-
-
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 Javasuperkeyword, 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
Addscookietojar.Emits the
CookieJar::changedsignal 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).cookiewill be 'stolen' by the jar, so don't free it afterwards.- Parameters:
cookie- aSoupCookie
-
addCookieFull
Addscookietojar.Emits the
CookieJar::changedsignal 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).firstPartywill be used to reject cookies coming from third party resources in case such a security policy is set in thejar.uriwill be used to reject setting or overwriting secure cookies from insecure origins.nullis treated as secure.cookiewill be 'stolen' by the jar, so don't free it afterwards.- Parameters:
cookie- aSoupCookieuri- the URI setting the cookiefirstParty- the URI for the main document
-
addCookieWithFirstParty
Addscookietojar.Emits the
CookieJar::changedsignal 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).firstPartywill be used to reject cookies coming from third party resources in case such a security policy is set in thejar.cookiewill 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
Constructs aGLib.Listwith every cookie inside thejar.The cookies in the list are a copy of the original, so you have to free them when you are done with them.
For historical reasons this list is in reverse order.
- Returns:
- a
GSListwith all the cookies in thejar.
-
deleteCookie
Deletescookiefromjar.Emits the
CookieJar::changedsignal.- Parameters:
cookie- aSoupCookie
-
getAcceptPolicy
Getsjar'sCookieJarAcceptPolicy.- Returns:
- the
SoupCookieJarAcceptPolicyset in the this CookieJar
-
getCookieList
Retrieves the list of cookies that would be sent with a request tourias aGLib.ListofSoupCookieobjects.If
forHttpistrue, 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). SinceSoupCookieJarsets the Cookie header itself when making the actual HTTP request, you should almost certainly be settingforHttptofalseif you are calling this.- Parameters:
uri- aGUriforHttp- whether or not the return value is being passed directly to an HTTP operation- Returns:
- a
GSListwith the cookies in the this CookieJar that would be sent with a request touri.
-
getCookieListWithSameSiteInfo
public SList<Cookie> 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.See the SameSite cookies spec for more detailed information.
- Parameters:
uri- aGUritopLevel- aGUrifor the top level documentsiteForCookies- aGUriindicating 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 whenforHttpisfalseisTopLevelNavigation- whether or not the HTTP request is part of top level navigation- Returns:
- a
GSListwith 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
forHttpistrue, 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). SinceSoupCookieJarsets the Cookie header itself when making the actual HTTP request, you should almost certainly be settingforHttptofalseif you are calling this.- Parameters:
uri- aGUriforHttp- whether or not the return value is being passed directly to an HTTP operation- Returns:
- the cookies, in string form, or
nullif there are no cookies foruri.
-
isPersistent
public boolean isPersistent()Gets whether this CookieJar stores cookies persistenly.- Returns:
trueif this CookieJar storage is persistent orfalseotherwise.
-
setAcceptPolicy
Setspolicyas the cookie acceptance policy forjar.- Parameters:
policy- aSoupCookieJarAcceptPolicy
-
setCookie
Addscookietojar,exactly as though it had appeared in a Set-Cookie header returned from a request touri.Keep in mind that if the
CookieJarAcceptPolicyset is eitherCookieJarAcceptPolicy.NO_THIRD_PARTYorCookieJarAcceptPolicy.GRANDFATHERED_THIRD_PARTYyou'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
Addscookietojar,exactly as though it had appeared in a Set-Cookie header returned from a request touri.firstPartywill be used to reject cookies coming from third party resources in case such a security policy is set in thejar.- 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 whenjarchanges.If a cookie has been added,
newCookiewill contain the newly-added cookie andoldCookiewill benull. If a cookie has been deleted,oldCookiewill contain the to-be-deleted cookie andnewCookiewill benull. If a cookie has been changed,oldCookiewill contain its old value, andnewCookieits 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.Builderobject constructs aCookieJarwith the specified properties. Use the variousset...()methods to set properties, and finish construction withCookieJar.Builder.build().- Returns:
- the builder object
-