Package org.htmlunit.util
Class Cookie
java.lang.Object
org.htmlunit.util.Cookie
- All Implemented Interfaces:
Serializable
A cookie. This class is immutable.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new cookie with the specified name and value which applies to the specified domain.Creates a new cookie with the specified name and value which applies to the specified domain, the specified path, and expires after the specified amount of time.Creates a new cookie with the specified name and value which applies to the specified domain, the specified path, and expires on the specified date.Cookie
(String domain, String name, String value, String path, Date expires, boolean secure, boolean httpOnly) Creates a new cookie with the specified name and value which applies to the specified domain, the specified path, and expires on the specified date.Cookie
(String domain, String name, String value, String path, Date expires, boolean secure, boolean httpOnly, String sameSite) Creates a new cookie with the specified name and value which applies to the specified domain, the specified path, and expires on the specified date.Cookie
(org.apache.http.cookie.ClientCookie clientCookie) Creates a new HtmlUnit cookie from the HttpClient cookie provided. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returns the domain to which this cookie applies (null
for all domains).Returns the date on which this cookie expires (null
if it never expires).getName()
Returns the cookie name.getPath()
Returns the path to which this cookie applies (null
for all paths).getValue()
Returns the cookie value.int
hashCode()
boolean
Returns whether or not this cookie is HttpOnly (i.e. not available in JS).boolean
isSecure()
Returns whether or not this cookie is secure (i.e.org.apache.http.cookie.Cookie
Converts this cookie to an HttpClient cookie.toString()
-
Constructor Details
-
Cookie
Creates a new cookie with the specified name and value which applies to the specified domain. The new cookie applies to all paths, never expires and is not secure.- Parameters:
domain
- the domain to which this cookie appliesname
- the cookie namevalue
- the cookie name
-
Cookie
Creates a new cookie with the specified name and value which applies to the specified domain, the specified path, and expires on the specified date.- Parameters:
domain
- the domain to which this cookie appliesname
- the cookie namevalue
- the cookie namepath
- the path to which this cookie appliesexpires
- the date on which this cookie expiressecure
- whether or not this cookie is secure (i.e. HTTPS vs HTTP)
-
Cookie
public Cookie(String domain, String name, String value, String path, Date expires, boolean secure, boolean httpOnly) Creates a new cookie with the specified name and value which applies to the specified domain, the specified path, and expires on the specified date.- Parameters:
domain
- the domain to which this cookie appliesname
- the cookie namevalue
- the cookie namepath
- the path to which this cookie appliesexpires
- the date on which this cookie expiressecure
- whether or not this cookie is secure (i.e. HTTPS vs HTTP)httpOnly
- whether or not this cookie should be only used for HTTP(S) headers
-
Cookie
public Cookie(String domain, String name, String value, String path, Date expires, boolean secure, boolean httpOnly, String sameSite) Creates a new cookie with the specified name and value which applies to the specified domain, the specified path, and expires on the specified date.- Parameters:
domain
- the domain to which this cookie appliesname
- the cookie namevalue
- the cookie namepath
- the path to which this cookie appliesexpires
- the date on which this cookie expiressecure
- whether or not this cookie is secure (i.e. HTTPS vs HTTP)httpOnly
- whether or not this cookie should be only used for HTTP(S) headerssameSite
- the sameSite attribute
-
Cookie
public Cookie(org.apache.http.cookie.ClientCookie clientCookie) Creates a new HtmlUnit cookie from the HttpClient cookie provided.- Parameters:
clientCookie
- the HttpClient cookie
-
Cookie
Creates a new cookie with the specified name and value which applies to the specified domain, the specified path, and expires after the specified amount of time.- Parameters:
domain
- the domain to which this cookie appliesname
- the cookie namevalue
- the cookie namepath
- the path to which this cookie appliesmaxAge
- the number of seconds for which this cookie is valid;-1
indicates that the cookie should never expire; other negative numbers are not allowedsecure
- whether or not this cookie is secure (i.e. HTTPS vs HTTP)
-
-
Method Details
-
getName
Returns the cookie name.- Returns:
- the cookie name
-
getValue
Returns the cookie value.- Returns:
- the cookie value
-
getDomain
Returns the domain to which this cookie applies (null
for all domains).- Returns:
- the domain to which this cookie applies (
null
for all domains)
-
getPath
Returns the path to which this cookie applies (null
for all paths).- Returns:
- the path to which this cookie applies (
null
for all paths)
-
getExpires
Returns the date on which this cookie expires (null
if it never expires).- Returns:
- the date on which this cookie expires (
null
if it never expires)
-
isSecure
public boolean isSecure()Returns whether or not this cookie is secure (i.e. HTTPS vs HTTP).- Returns:
- whether or not this cookie is secure (i.e. HTTPS vs HTTP)
-
isHttpOnly
public boolean isHttpOnly()Returns whether or not this cookie is HttpOnly (i.e. not available in JS).- Returns:
- whether or not this cookie is HttpOnly (i.e. not available in JS).
- See Also:
-
getSameSite
- Returns:
- the SameSite value or
null
if not set.
-
toString
-
equals
-
hashCode
public int hashCode() -
toHttpClient
public org.apache.http.cookie.Cookie toHttpClient()Converts this cookie to an HttpClient cookie.- Returns:
- an HttpClient version of this cookie
-