1.13 <SoupCookieJar>

Class: <SoupCookieJar>

It derives from <GObject>.

Automatic cookie handling for SoupSession.

A CookieJar stores Cookies and arrange for them to be sent with the appropriate Messages. CookieJar implements SessionFeature, so you can add a cookie jar to a session with Session.add_feature or Session.add_feature_by_type.

Note that the base CookieJar class does not support any form of long-term cookie persistence.

Fields

parent-instance

Properties

The policy the jar should follow to accept or reject cookies.

Its value is a <SoupCookieJarAcceptPolicy> (or, to set it, one of its symbols).

Set it with (set! (cookie-jar:accept-policy self) value).

Whether or not the cookie jar is read-only.

Its value is a boolean.

It can only be set when the object is made, with #:read-only.

Procedures

Method: add-cookie self cookie

Adds cookie to self.

Emits the "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.

self

Passed: a <SoupCookieJar>.

a <SoupCookieJar>

cookie

Passed: a <SoupCookie>.

a <SoupCookie>

Method: add-cookie-full self cookie [uri] [first-party]

Adds cookie to self.

Emits the "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).

first-party will be used to reject cookies coming from third party resources in case such a security policy is set in the self.

uri will be used to reject setting or overwriting secure cookies from insecure origins. #f is treated as secure.

cookie will be ’stolen’ by the jar, so don’t free it afterwards.

self

Passed: a <SoupCookieJar>.

a <SoupCookieJar>

cookie

Passed: a <SoupCookie>.

a <SoupCookie>

uri

Passed, or left out: a <GUri>, or #f.

the URI setting the cookie

first-party

Passed, or left out: a <GUri>, or #f.

the URI for the main document

Method: add-cookie-with-first-party self first-party cookie

Adds cookie to self.

Emits the "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).

first-party will be used to reject cookies coming from third party resources in case such a security policy is set in the self.

cookie will be ’stolen’ by the jar, so don’t free it afterwards.

For secure cookies to work properly you may want to use CookieJar.add_cookie_full.

self

Passed: a <SoupCookieJar>.

a <SoupCookieJar>

first-party

Passed: a <GUri>.

the URI for the main document

cookie

Passed: a <SoupCookie>.

a <SoupCookie>

Method: all-cookies self ⇒ %return

Constructs a <GList> with every cookie inside the self.

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.

self

Passed: a <SoupCookieJar>.

a <SoupCookieJar>

%return

Returned: a list, each a <SoupCookie>.

a GSList with all the cookies in the self.

Method: delete-cookie self cookie

Deletes cookie from self.

Emits the "changed" signal.

self

Passed: a <SoupCookieJar>.

a <SoupCookieJar>

cookie

Passed: a <SoupCookie>.

a <SoupCookie>

Method: get-accept-policy self ⇒ %return

Gets self’s CookieJarAcceptPolicy.

self

Passed: a <SoupCookieJar>.

a <SoupCookieJar>

%return

Returned: a <SoupCookieJarAcceptPolicy>.

the <SoupCookieJarAcceptPolicy> set in the self

Method: get-cookie-list self uri for-http ⇒ %return

Retrieves the list of cookies that would be sent with a request to uri as a <GList> of Cookie objects.

If for-http is #t, 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 for-http to #f if you are calling this.

self

Passed: a <SoupCookieJar>.

a <SoupCookieJar>

uri

Passed: a <GUri>.

a <GUri>

for-http

Passed: a boolean.

whether or not the return value is being passed directly to an HTTP operation

%return

Returned: a list, each a <SoupCookie>.

a GSList with the cookies in the self that would be sent with a request to uri.

Method: get-cookie-list-with-same-site-info self uri top-level site-for-cookies for-http is-safe-method is-top-level-navigation ⇒ %return

This is an extended version of CookieJar.get_cookie_list 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.

self

Passed: a <SoupCookieJar>.

a <SoupCookieJar>

uri

Passed: a <GUri>.

a <GUri>

top-level

Passed: a <GUri>, or #f.

a <GUri> for the top level document

site-for-cookies

Passed: a <GUri>, or #f.

a <GUri> indicating the origin to get cookies for

for-http

Passed: a boolean.

whether or not the return value is being passed directly to an HTTP operation

is-safe-method

Passed: a boolean.

if the HTTP method is safe, as defined by RFC 7231, ignored when for-http is #f

is-top-level-navigation

Passed: a boolean.

whether or not the HTTP request is part of top level navigation

%return

Returned: a list, each a <SoupCookie>.

a GSList with the cookies in the self that would be sent with a request to uri.

Method: get-cookies self uri for-http ⇒ %return

Retrieves (in Cookie-header form) the list of cookies that would be sent with a request to uri.

If for-http is #t, 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 for-http to #f if you are calling this.

self

Passed: a <SoupCookieJar>.

a <SoupCookieJar>

uri

Passed: a <GUri>.

a <GUri>

for-http

Passed: a boolean.

whether or not the return value is being passed directly to an HTTP operation

%return

Returned: a string, or #f.

the cookies, in string form, or #f if there are no cookies for uri.

Method: is-persistent? self ⇒ %return

Gets whether self stores cookies persistenly.

self

Passed: a <SoupCookieJar>.

a <SoupCookieJar>

%return

Returned: a boolean.

#t if self storage is persistent or #f otherwise.

Creates a new CookieJar.

The base CookieJar class does not support persistent storage of cookies; use a subclass for that.

%return

Returned: a <SoupCookieJar>.

a new <SoupCookieJar>

Method: set-accept-policy self policy

Sets policy as the cookie acceptance policy for self.

self

Passed: a <SoupCookieJar>.

a <SoupCookieJar>

policy

Passed: a <SoupCookieJarAcceptPolicy>, or one of its symbols.

a <SoupCookieJarAcceptPolicy>

Method: set-cookie self uri cookie

Adds cookie to self, exactly as though it had appeared in a Set-Cookie header returned from a request to uri.

Keep in mind that if the CookieJarAcceptPolicy set is either no-third-party or grandfathered-third-party you’ll need to use CookieJar.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.

self

Passed: a <SoupCookieJar>.

a <SoupCookieJar>

uri

Passed: a <GUri>.

the URI setting the cookie

cookie

Passed: a string.

the stringified cookie to set

Method: set-cookie-with-first-party self uri first-party cookie

Adds cookie to self, exactly as though it had appeared in a Set-Cookie header returned from a request to uri.

first-party will be used to reject cookies coming from third party resources in case such a security policy is set in the self.

self

Passed: a <SoupCookieJar>.

a <SoupCookieJar>

uri

Passed: a <GUri>.

the URI setting the cookie

first-party

Passed: a <GUri>.

the URI for the main document

cookie

Passed: a string.

the stringified cookie to set

Signals

Connect a handler with (connect object cookie-jar:changed handler). It is called as (handler self old-cookie new-cookie).

Emitted when jar changes.

If a cookie has been added, new-cookie will contain the newly-added cookie and old-cookie will be #f. If a cookie has been deleted, old-cookie will contain the to-be-deleted cookie and new-cookie will be #f. If a cookie has been changed, old-cookie will contain its old value, and new-cookie its new value.

self

Passed: a <SoupCookieJar>.

old-cookie

Passed: a <SoupCookie>, or #f.

the old <SoupCookie> value

new-cookie

Passed: a <SoupCookie>, or #f.

the new <SoupCookie> value

Virtual methods

To override it in a new class, give register-type #:vfuncs `((changed . ,procedure)). The procedure is called as (procedure self old-cookie new-cookie).

implementor

Passed: the class whose implementation to call: <SoupCookieJar>, or a class that derives from it, or its GType number.

self

Passed: a <SoupCookieJar>.

old-cookie

Passed: a <SoupCookie>.

new-cookie

Passed: a <SoupCookie>.

Gets whether self stores cookies persistenly.

To override it in a new class, give register-type #:vfuncs `((is-persistent . ,procedure)). The procedure is called as (procedure self) ⇒ %return.

implementor

Passed: the class whose implementation to call: <SoupCookieJar>, or a class that derives from it, or its GType number.

self

Passed: a <SoupCookieJar>.

a <SoupCookieJar>

%return

Returned: a boolean.

#t if self storage is persistent or #f otherwise.

To override it in a new class, give register-type #:vfuncs `((save . ,procedure)). The procedure is called as (procedure self).

implementor

Passed: the class whose implementation to call: <SoupCookieJar>, or a class that derives from it, or its GType number.

self

Passed: a <SoupCookieJar>.