## com.gargoylesoftware.htmlunit
Class CookieManager

    java.lang.Object
      com.gargoylesoftware.htmlunit.CookieManager

All Implemented Interfaces:
  java.io.Serializable

    public class CookieManager

extends java.lang.Object
implements java.io.Serializable

Manages cookies for a `WebClient`. This class is thread-safe.

Version:
  $Revision: 4852 $
Author:
  Daniel Gredler, Ahmed Ashour
See Also:
  Serialized Form

Field Summary
`static java.lang.String` `HTMLUNIT_COOKIE_POLICY` HtmlUnit's cookie policy is to be browser-compatible.

Constructor Summary
`CookieManager()` Creates a new instance.

Method Summary
`void` `addCookie(org.apache.commons.httpclient.Cookie cookie)` Adds the specified cookie.
`void` `clearCookies()` Removes all cookies.
`org.apache.commons.httpclient.Cookie` `getCookie(java.lang.String name)` Returns the currently configured cookie with the specified name, or `null` if one does not exist.
`java.util.Set<org.apache.commons.httpclient.Cookie>` `getCookies()` Returns the currently configured cookies, in an unmodifiable set.
`java.util.Set<org.apache.commons.httpclient.Cookie>` `getCookies(java.lang.String domain)` Returns the currently configured cookies for the specified domain, in an unmodifiable set.
`boolean` `isCookiesEnabled()` Returns `true` if cookies are enabled.
`void` `removeCookie(org.apache.commons.httpclient.Cookie cookie)` Removes the specified cookie.
`void` `setCookiesEnabled(boolean enabled)` Enables/disables cookie support.
`protected void` `updateFromState(org.apache.commons.httpclient.HttpState state)` Updates the current cookie settings from the specified HTTP state's cookie configuration.
`protected void` `updateState(org.apache.commons.httpclient.HttpState state)` Updates the specified HTTP state's cookie configuration according to the current cookie settings.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### HTMLUNIT_COOKIE_POLICY

    public static final java.lang.String HTMLUNIT_COOKIE_POLICY

  HtmlUnit's cookie policy is to be browser-compatible. Code which requires access to HtmlUnit's cookie policy should use this constant, rather than making assumptions and using one of the HttpClient `CookiePolicy` constants directly.

  See Also:
    Constant Field Values

Constructor Detail

### CookieManager

    public CookieManager()

  Creates a new instance.

Method Detail

### 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 java.util.Set<org.apache.commons.httpclient.Cookie> getCookies()

  Returns the currently configured cookies, in an unmodifiable set.

  Returns:
    the currently configured cookies, in an unmodifiable set

### getCookies

    public java.util.Set<org.apache.commons.httpclient.Cookie> getCookies(java.lang.String domain)

  Returns the currently configured cookies for the specified domain, in an unmodifiable set.

  Parameters:
    `domain` - the domain on which to filter the returned cookies
  Returns:
    the currently configured cookies for the specified domain, in an unmodifiable set

### getCookie

    public org.apache.commons.httpclient.Cookie getCookie(java.lang.String name)

  Returns the currently configured cookie with the specified name, or `null` if one does not exist.

  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(org.apache.commons.httpclient.Cookie cookie)

  Adds the specified cookie.

  Parameters:
    `cookie` - the cookie to add

### removeCookie

    public void removeCookie(org.apache.commons.httpclient.Cookie cookie)

  Removes the specified cookie.

  Parameters:
    `cookie` - the cookie to remove

### clearCookies

    public void clearCookies()

  Removes all cookies.

### updateState

    protected void updateState(org.apache.commons.httpclient.HttpState state)

  Updates the specified HTTP state's cookie configuration according to the current cookie settings.

  Parameters:
    `state` - the HTTP state to update
  See Also:
    `updateFromState(HttpState)`

### updateFromState

    protected void updateFromState(org.apache.commons.httpclient.HttpState state)

  Updates the current cookie settings from the specified HTTP state's cookie configuration.

  Parameters:
    `state` - the HTTP state to update from
  See Also:
    `updateState(HttpState)`

Copyright © 2002-2011 Gargoyle Software Inc.. All Rights Reserved.