Package org.htmlunit

Class CookieManager

java.lang.Object
org.htmlunit.CookieManager
All Implemented Interfaces:
Serializable

public class CookieManager extends Object implements Serializable
Manages cookies for a WebClient. This class is thread-safe. You can disable Cookies by calling setCookiesEnabled(false). The CookieManager itself takes care of this and ignores all cookie request if disabled. If you override this your methods have to do the same.
See Also:
  • Constructor Details

    • CookieManager

      public CookieManager()
      Creates a new instance.
  • Method Details

    • setCookiesEnabled

      public void setCookiesEnabled(boolean enabled)
      Enables/disables cookie support. Cookies are enabled by default.
      Parameters:
      enabled - true to enable cookie support, false otherwise
    • isCookiesEnabled

      public boolean isCookiesEnabled()
      Returns true if cookies are enabled. Cookies are enabled by default.
      Returns:
      true if cookies are enabled, false otherwise
    • getCookies

      public Set<Cookie> getCookies()
      Returns the currently configured cookies, in an unmodifiable set. If disabled, this returns an empty set.
      Returns:
      the currently configured cookies, in an unmodifiable set
    • clearExpired

      public boolean clearExpired(Date date)
      Clears all cookies that have expired before supplied date. If disabled, this returns false.
      Parameters:
      date - the date to use for comparison when clearing expired cookies
      Returns:
      whether any cookies were found expired, and were cleared
    • getCookie

      public Cookie getCookie(String name)
      Returns the currently configured cookie with the specified name, or null if one does not exist. If disabled, this returns null.
      Parameters:
      name - the name of the cookie to return
      Returns:
      the currently configured cookie with the specified name, or null if one does not exist
    • addCookie

      public void addCookie(Cookie cookie)
      Adds the specified cookie. If disabled, this does nothing.
      Parameters:
      cookie - the cookie to add
    • removeCookie

      public void removeCookie(Cookie cookie)
      Removes the specified cookie. If disabled, this does nothing.
      Parameters:
      cookie - the cookie to remove
    • clearCookies

      public void clearCookies()
      Removes all cookies. If disabled, this does nothing.