Next: <SoupHSTSPolicy>, Up: Structures   [Index]


3.1 <SoupCookie> ¶

Structure: <SoupCookie> ¶

Implements HTTP cookies, as described by RFC 6265.

To have a Session handle cookies for your appliction automatically, use a CookieJar.

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-#f if the cookie uses either the original "expires" attribute, or the newer "max-age" attribute. If expires is #f, it indicates that neither "expires" nor "max-age" was specified, and the cookie expires at the end of the session.

If http-only 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.

Procedures ¶

Method: cookie:applies-to-uri? self uri ⇒ %return ¶
Method: applies-to-uri? self uri ⇒ %return ¶

Tests if self should be sent to uri.

(At the moment, this does not check that self’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.)

self

Passed: a <SoupCookie>.

a <SoupCookie>

uri

Passed: a <GUri>.

a <GUri>

%return

Returned: a boolean.

#t if self should be sent to uri, #f if not

Method: cookie:copy self ⇒ %return ¶
Method: copy self ⇒ %return ¶

Copies self.

self

Passed: a <SoupCookie>.

a <SoupCookie>

%return

Returned: a <SoupCookie>.

a copy of self

Method: cookie:domain-matches? self host ⇒ %return ¶
Method: domain-matches? self host ⇒ %return ¶

Checks if the self’s domain and host match.

The domains match if self should be sent when making a request to host, or that self should be accepted when receiving a response from host.

self

Passed: a <SoupCookie>.

a <SoupCookie>

host

Passed: a string.

a URI

%return

Returned: a boolean.

#t if the domains match, #f otherwise

Method: cookie:equal? self cookie2 ⇒ %return ¶
Method: equal? self cookie2 ⇒ %return ¶

Tests if self and cookie2 are equal.

Note that currently, this does not check that the cookie domains match. This may change in the future.

self

Passed: a <SoupCookie>.

a <SoupCookie>

cookie2

Passed: a <SoupCookie>.

a <SoupCookie>

%return

Returned: a boolean.

whether the cookies are equal.

Method: cookie:free self ¶
Method: free self ¶

Frees self.

self

Passed: a <SoupCookie>.

a <SoupCookie>

Method: cookie:get-domain self ⇒ %return ¶
Method: get-domain self ⇒ %return ¶

Gets self’s domain.

self

Passed: a <SoupCookie>.

a <SoupCookie>

%return

Returned: a string.

self’s domain

Method: cookie:get-expires self ⇒ %return ¶
Method: get-expires self ⇒ %return ¶

Gets self’s expiration time.

self

Passed: a <SoupCookie>.

a <GDateTime>

%return

Returned: a <GDateTime>, or #f.

self’s expiration time, which is owned by self and should not be modified or freed.

Method: cookie:get-http-only? self ⇒ %return ¶
Method: get-http-only? self ⇒ %return ¶

Gets self’s HttpOnly attribute.

self

Passed: a <SoupCookie>.

a <SoupCookie>

%return

Returned: a boolean.

self’s HttpOnly attribute

Method: cookie:get-name self ⇒ %return ¶
Method: get-name self ⇒ %return ¶

Gets self’s name.

self

Passed: a <SoupCookie>.

a <SoupCookie>

%return

Returned: a string.

self’s name

Method: cookie:get-path self ⇒ %return ¶
Method: get-path self ⇒ %return ¶

Gets self’s path.

self

Passed: a <SoupCookie>.

a <SoupCookie>

%return

Returned: a string.

self’s path

Method: cookie:get-same-site-policy self ⇒ %return ¶
Method: get-same-site-policy self ⇒ %return ¶

Returns the same-site policy for this cookie.

self

Passed: a <SoupCookie>.

a <SoupCookie>

%return

Returned: a <SoupSameSitePolicy>.

a <SoupSameSitePolicy>

Method: cookie:get-secure? self ⇒ %return ¶
Method: get-secure? self ⇒ %return ¶

Gets self’s secure attribute.

self

Passed: a <SoupCookie>.

a <SoupCookie>

%return

Returned: a boolean.

self’s secure attribute

Method: cookie:get-value self ⇒ %return ¶
Method: get-value self ⇒ %return ¶

Gets self’s value.

self

Passed: a <SoupCookie>.

a <SoupCookie>

%return

Returned: a string.

self’s value

Procedure: cookie:new name value domain path max-age ⇒ %return ¶

Creates a new Cookie with the given attributes.

Use Cookie.set_secure and Cookie.set_http_only 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.

max-age 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 SOUP_COOKIE_MAX_AGE_ONE_HOUR, SOUP_COOKIE_MAX_AGE_ONE_DAY, SOUP_COOKIE_MAX_AGE_ONE_WEEK and SOUP_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 Cookie.set_expires.)

As of version 3.4.0 the default value of a cookie’s same-site-policy is lax.

name

Passed: a string.

cookie name

value

Passed: a string.

cookie value

domain

Passed: a string.

cookie domain or hostname

path

Passed: a string.

cookie path, or #f

max-age

Passed: a 32-bit integer.

max age of the cookie, or -1 for a session cookie

%return

Returned: a <SoupCookie>.

a new <SoupCookie>.

Procedure: cookie:parse header [origin] ⇒ %return ¶

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 #f, path will default to "/", but domain will be left as #f. 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.

As of version 3.4.0 the default value of a cookie’s same-site-policy is lax.

header

Passed: a string.

a cookie string (eg, the value of a Set-Cookie header)

origin

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

origin of the cookie

%return

Returned: a <SoupCookie>, or #f.

a new <SoupCookie>, or #f if it could not be parsed, or contained an illegal "domain" attribute for a cookie originating from origin.

Method: cookie:set-domain self domain ¶
Method: set-domain self domain ¶

Sets self’s domain to domain.

self

Passed: a <SoupCookie>.

a <SoupCookie>

domain

Passed: a string.

the new domain

Method: cookie:set-expires self expires ¶
Method: set-expires self expires ¶

Sets self’s expiration time to expires.

If expires is #f, self will be a session cookie and will expire at the end of the client’s session.

(This sets the same property as Cookie.set_max_age.)

self

Passed: a <SoupCookie>.

a <SoupCookie>

expires

Passed: a <GDateTime>.

the new expiration time, or #f

Method: cookie:set-http-only self http-only ¶
Method: set-http-only self http-only ¶

Sets self’s HttpOnly attribute to http-only.

If #t, self will be marked as "http only", meaning it should not be exposed to web page scripts or other untrusted code.

self

Passed: a <SoupCookie>.

a <SoupCookie>

http-only

Passed: a boolean.

the new value for the HttpOnly attribute

Method: cookie:set-max-age self max-age ¶
Method: set-max-age self max-age ¶

Sets self’s max age to max-age.

If max-age 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 SOUP_COOKIE_MAX_AGE_ONE_HOUR, SOUP_COOKIE_MAX_AGE_ONE_DAY, SOUP_COOKIE_MAX_AGE_ONE_WEEK and SOUP_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 Cookie.set_expires.

self

Passed: a <SoupCookie>.

a <SoupCookie>

max-age

Passed: a 32-bit integer.

the new max age

Method: cookie:set-name self name ¶
Method: set-name self name ¶

Sets self’s name to name.

self

Passed: a <SoupCookie>.

a <SoupCookie>

name

Passed: a string.

the new name

Method: cookie:set-path self path ¶
Method: set-path self path ¶

Sets self’s path to path.

self

Passed: a <SoupCookie>.

a <SoupCookie>

path

Passed: a string.

the new path

Method: cookie:set-same-site-policy self policy ¶
Method: set-same-site-policy self policy ¶

When used in conjunction with CookieJar.get_cookie_list_with_same_site_info this sets the policy of when this cookie should be exposed.

self

Passed: a <SoupCookie>.

a <SoupCookie>

policy

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

a <SoupSameSitePolicy>

Method: cookie:set-secure self secure ¶
Method: set-secure self secure ¶

Sets self’s secure attribute to secure.

If #t, self will only be transmitted from the client to the server over secure (https) connections.

self

Passed: a <SoupCookie>.

a <SoupCookie>

secure

Passed: a boolean.

the new value for the secure attribute

Method: cookie:set-value self value ¶
Method: set-value self value ¶

Sets self’s value to value.

self

Passed: a <SoupCookie>.

a <SoupCookie>

value

Passed: a string.

the new value

Method: cookie:to-cookie-header self ⇒ %return ¶
Method: to-cookie-header self ⇒ %return ¶

Serializes self in the format used by the Cookie header (ie, for returning a cookie from a Session to a server).

self

Passed: a <SoupCookie>.

a <SoupCookie>

%return

Returned: a string.

the header

Method: cookie:to-set-cookie-header self ⇒ %return ¶
Method: to-set-cookie-header self ⇒ %return ¶

Serializes self in the format used by the Set-Cookie header.

i.e. for sending a cookie from a Server to a client.

self

Passed: a <SoupCookie>.

a <SoupCookie>

%return

Returned: a string.

the header


Next: <SoupHSTSPolicy>, Up: Structures   [Index]