Package org.htmlunit
Class CookieManager
java.lang.Object
org.htmlunit.CookieManager
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds the specified cookie.void
Removes all cookies.boolean
clearExpired
(Date date) Clears all cookies that have expired before supplied date.Returns the currently configured cookie with the specified name, ornull
if one does not exist.Returns the currently configured cookies, in an unmodifiable set.boolean
Returnstrue
if cookies are enabled.void
removeCookie
(Cookie cookie) Removes the specified cookie.void
setCookiesEnabled
(boolean enabled) Enables/disables cookie support.
-
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()Returnstrue
if cookies are enabled. Cookies are enabled by default.- Returns:
true
if cookies are enabled,false
otherwise
-
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
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
Returns the currently configured cookie with the specified name, ornull
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
Adds the specified cookie. If disabled, this does nothing.- Parameters:
cookie
- the cookie to add
-
removeCookie
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.
-