Class (GI Struct)

Soup-3.0SoupCookie

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-null if the cookie uses either the original "expires" attribute, or the newer "max-age" attribute. If expires is null, 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.

Index

Constructors

  • Parameters

    • name: string
    • value: string
    • domain: string
    • path: string
    • max_age: number

    Returns Cookie

Properties

$gtype: GType<Cookie>

Methods

  • Tests if cookie should be sent to uri.

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

    Parameters

    Returns boolean

    true if cookie should be sent to uri, false if not

  • Checks if the cookie's domain and host match.

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

    Parameters

    • host: string

      a URI

    Returns boolean

    true if the domains match, false otherwise

  • Tests if cookie1 and cookie2 are equal.

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

    Parameters

    Returns boolean

    whether the cookies are equal.

  • Gets cookie's HttpOnly attribute.

    Returns boolean

    cookie's HttpOnly attribute

  • Sets cookie's domain to domain.

    Parameters

    • domain: string

      the new domain

    Returns void

  • Sets cookie's expiration time to expires.

    If expires is null, cookie 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.)

    Parameters

    Returns void

  • Sets cookie's HttpOnly attribute to http_only.

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

    Parameters

    • http_only: boolean

      the new value for the HttpOnly attribute

    Returns void

  • Sets cookie'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.

    Parameters

    • max_age: number

      the new max age

    Returns void

  • Sets cookie's name to name.

    Parameters

    • name: string

      the new name

    Returns void

  • Sets cookie's path to path.

    Parameters

    • path: string

      the new path

    Returns void

  • Sets cookie's secure attribute to secure.

    If true, cookie will only be transmitted from the client to the server over secure (https) connections.

    Parameters

    • secure: boolean

      the new value for the secure attribute

    Returns void

  • Sets cookie's value to value.

    Parameters

    • value: string

      the new value

    Returns void

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

    Returns string

    the header

  • Serializes cookie in the format used by the Set-Cookie header.

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

    Returns string

    the header

  • Parameters

    • name: string
    • value: string
    • domain: string
    • path: string
    • max_age: number

    Returns Cookie

  • 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 null, path will default to "/", but domain will be left as null. 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 Soup.SameSitePolicy.LAX.

    Parameters

    • header: string

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

    • Optionalorigin: GLib.Uri

      origin of the cookie

    Returns Cookie