Package org.htmlunit.util
Class Cookie
- java.lang.Object
-
- org.htmlunit.util.Cookie
-
- All Implemented Interfaces:
java.io.Serializable
public class Cookie extends java.lang.Object implements java.io.SerializableA cookie. This class is immutable.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Cookie(java.lang.String domain, java.lang.String name, java.lang.String value)Creates a new cookie with the specified name and value which applies to the specified domain.Cookie(java.lang.String domain, java.lang.String name, java.lang.String value, java.lang.String path, int maxAge, boolean secure)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.Cookie(java.lang.String domain, java.lang.String name, java.lang.String value, java.lang.String path, java.util.Date expires, boolean secure)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(java.lang.String domain, java.lang.String name, java.lang.String value, java.lang.String path, java.util.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(java.lang.String domain, java.lang.String name, java.lang.String value, java.lang.String path, java.util.Date expires, boolean secure, boolean httpOnly, java.lang.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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)static java.util.List<Cookie>fromHttpClient(java.util.List<org.apache.http.cookie.Cookie> cookies)Converts the specified array of HttpClient cookies into a list of cookies.java.lang.StringgetDomain()Returns the domain to which this cookie applies (nullfor all domains).java.util.DategetExpires()Returns the date on which this cookie expires (nullif it never expires).java.lang.StringgetName()Returns the cookie name.java.lang.StringgetPath()Returns the path to which this cookie applies (nullfor all paths).java.lang.StringgetSameSite()java.lang.StringgetValue()Returns the cookie value.inthashCode()booleanisHttpOnly()Returns whether or not this cookie is HttpOnly (i.e. not available in JS).booleanisSecure()Returns whether or not this cookie is secure (i.e.org.apache.http.cookie.CookietoHttpClient()Converts this cookie to an HttpClient cookie.static java.util.List<org.apache.http.cookie.Cookie>toHttpClient(java.util.Collection<Cookie> cookies)Converts the specified collection of cookies into a collection of HttpClient cookies.java.lang.StringtoString()
-
-
-
Constructor Detail
-
Cookie
public Cookie(java.lang.String domain, java.lang.String name, java.lang.String value)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
public Cookie(java.lang.String domain, java.lang.String name, java.lang.String value, java.lang.String path, java.util.Date expires, boolean secure)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(java.lang.String domain, java.lang.String name, java.lang.String value, java.lang.String path, java.util.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(java.lang.String domain, java.lang.String name, java.lang.String value, java.lang.String path, java.util.Date expires, boolean secure, boolean httpOnly, java.lang.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
public Cookie(java.lang.String domain, java.lang.String name, java.lang.String value, java.lang.String path, int maxAge, boolean secure)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;-1indicates 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 Detail
-
getName
public java.lang.String getName()
Returns the cookie name.- Returns:
- the cookie name
-
getValue
public java.lang.String getValue()
Returns the cookie value.- Returns:
- the cookie value
-
getDomain
public java.lang.String getDomain()
Returns the domain to which this cookie applies (nullfor all domains).- Returns:
- the domain to which this cookie applies (
nullfor all domains)
-
getPath
public java.lang.String getPath()
Returns the path to which this cookie applies (nullfor all paths).- Returns:
- the path to which this cookie applies (
nullfor all paths)
-
getExpires
public java.util.Date getExpires()
Returns the date on which this cookie expires (nullif it never expires).- Returns:
- the date on which this cookie expires (
nullif 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:
- Wikipedia
-
getSameSite
public java.lang.String getSameSite()
- Returns:
- the SameSite value or
nullif not set.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toHttpClient
public org.apache.http.cookie.Cookie toHttpClient()
Converts this cookie to an HttpClient cookie.- Returns:
- an HttpClient version of this cookie
-
toHttpClient
public static java.util.List<org.apache.http.cookie.Cookie> toHttpClient(java.util.Collection<Cookie> cookies)
Converts the specified collection of cookies into a collection of HttpClient cookies.- Parameters:
cookies- the cookies to be converted- Returns:
- the specified cookies, as HttpClient cookies
-
fromHttpClient
public static java.util.List<Cookie> fromHttpClient(java.util.List<org.apache.http.cookie.Cookie> cookies)
Converts the specified array of HttpClient cookies into a list of cookies.- Parameters:
cookies- the cookies to be converted- Returns:
- the specified HttpClient cookies, as cookies
-
-