Package rife.engine

Class SiteCookieJar

java.lang.Object
rife.engine.SiteCookieJar

public class SiteCookieJar extends Object
Acts as the browser for the cookies of a SiteRunner. It keeps the cookies that the responses set and sends them back with the requests they apply to, by host, domain, path, expiry and secure flag.

When the web view of your application keeps the cookies of the origin itself, you don't need a jar. With a SiteCookieStore, the cookies that have an expiry also survive a restart of your application, which is useful for a remembered login for instance.

Cookies that are set for a domain are also sent to its subdomains. Since the list of public suffixes isn't known here, a jar shouldn't be shared by origins that don't trust each other.

A jar can be used from several threads at the same time.

Since:
1.11.0
See Also:
  • Constructor Details

    • SiteCookieJar

      public SiteCookieJar()
      Creates a jar that keeps its cookies in memory only.
      Since:
      1.11.0
    • SiteCookieJar

      public SiteCookieJar(SiteCookieStore store)
      Creates a jar that restores its cookies from a store and saves the ones that last there each time they change.
      Parameters:
      store - the store of the cookies, or null to keep them in memory only
      Since:
      1.11.0
  • Method Details

    • getCookies

      public List<SiteCookie> getCookies()
      Retrieves all the cookies that haven't expired.
      Returns:
      the cookies of this jar
      Since:
      1.11.0
    • getCookies

      public List<SiteCookie> getCookies(String host, String path, boolean secure)
      Retrieves the cookies that would be sent with a request, ordered with the longest path first.
      Parameters:
      host - the host of the request
      path - the path of the request
      secure - whether the request is secure
      Returns:
      the matching cookies
      Since:
      1.11.0
    • clear

      public void clear()
      Removes all the cookies.
      Since:
      1.11.0