Class BasicClientCookie
- java.lang.Object
-
- org.apache.hc.client5.http.impl.cookie.BasicClientCookie
-
public final class BasicClientCookie extends java.lang.Object implements SetCookie, java.lang.Cloneable, java.io.Serializable
Default implementation ofSetCookie
.- Since:
- 4.0
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.lang.String>
attribs
Cookie attributes as specified by the origin serverprivate java.lang.String
cookieDomain
Domain attribute.private java.time.Instant
cookieExpiryDate
ExpirationInstant
.private java.lang.String
cookiePath
Path attribute.private java.time.Instant
creationDate
private boolean
httpOnly
ThehttpOnly
flag.private boolean
isSecure
My secure flag.private java.lang.String
name
Cookie nameprivate static long
serialVersionUID
private java.lang.String
value
Cookie value-
Fields inherited from interface org.apache.hc.client5.http.cookie.Cookie
DOMAIN_ATTR, EXPIRES_ATTR, HTTP_ONLY_ATTR, MAX_AGE_ATTR, PATH_ATTR, SECURE_ATTR
-
-
Constructor Summary
Constructors Constructor Description BasicClientCookie(java.lang.String name, java.lang.String value)
Default Constructor taking a name and a value.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.Object
clone()
boolean
containsAttribute(java.lang.String name)
java.lang.String
getAttribute(java.lang.String name)
java.util.Date
getCreationDate()
Deprecated.UsegetCreationInstant()
.java.time.Instant
getCreationInstant()
Returns creation time of the cookie.java.lang.String
getDomain()
Returns domain attribute of the cookie.java.util.Date
getExpiryDate()
Deprecated.java.time.Instant
getExpiryInstant()
Returns the expirationInstant
of the cookie, ornull
if none exists.java.lang.String
getName()
Returns the name.java.lang.String
getPath()
Returns the path attribute of the cookiejava.lang.String
getValue()
Returns the value.boolean
isExpired(java.time.Instant instant)
Returns true if this cookie has expired.boolean
isExpired(java.util.Date date)
Deprecated.boolean
isHttpOnly()
Checks whether this Cookie has been marked ashttpOnly
.boolean
isPersistent()
Returnsfalse
if the cookie should be discarded at the end of the "session";true
otherwise.boolean
isSecure()
Indicates whether this cookie requires a secure connection.boolean
removeAttribute(java.lang.String name)
void
setAttribute(java.lang.String name, java.lang.String value)
void
setCreationDate(java.time.Instant creationDate)
void
setCreationDate(java.util.Date creationDate)
Deprecated.void
setDomain(java.lang.String domain)
Sets the domain attribute.void
setExpiryDate(java.time.Instant expiryInstant)
Sets expiration date.void
setExpiryDate(java.util.Date expiryDate)
Deprecated.Use {setExpiryDate(Instant)
}void
setHttpOnly(boolean httpOnly)
Sets the http-only attribute of the cookie.void
setPath(java.lang.String path)
Sets the path attribute.void
setSecure(boolean secure)
Sets the secure attribute of the cookie.void
setValue(java.lang.String value)
Sets the valuejava.lang.String
toString()
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
name
private final java.lang.String name
Cookie name
-
attribs
private java.util.Map<java.lang.String,java.lang.String> attribs
Cookie attributes as specified by the origin server
-
value
private java.lang.String value
Cookie value
-
cookieDomain
private java.lang.String cookieDomain
Domain attribute.
-
cookieExpiryDate
private java.time.Instant cookieExpiryDate
ExpirationInstant
.
-
cookiePath
private java.lang.String cookiePath
Path attribute.
-
isSecure
private boolean isSecure
My secure flag.
-
creationDate
private java.time.Instant creationDate
-
httpOnly
private boolean httpOnly
ThehttpOnly
flag.
-
-
Method Detail
-
getName
public java.lang.String getName()
Returns the name.
-
getValue
public java.lang.String getValue()
Returns the value.
-
setValue
public void setValue(java.lang.String value)
Sets the value
-
getExpiryDate
@Deprecated public java.util.Date getExpiryDate()
Deprecated.Returns the expirationDate
of the cookie, ornull
if none exists.Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.
- Specified by:
getExpiryDate
in interfaceCookie
- Returns:
- Expiration
Date
, ornull
. - See Also:
setExpiryDate(java.util.Date)
-
getExpiryInstant
public java.time.Instant getExpiryInstant()
Returns the expirationInstant
of the cookie, ornull
if none exists.Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.
- Specified by:
getExpiryInstant
in interfaceCookie
- Returns:
- Expiration
Instant
, ornull
.
-
setExpiryDate
@Deprecated public void setExpiryDate(java.util.Date expiryDate)
Deprecated.Use {setExpiryDate(Instant)
}Sets expiration date.Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.
- Specified by:
setExpiryDate
in interfaceSetCookie
- Parameters:
expiryDate
- theDate
after which this cookie is no longer valid.- See Also:
Cookie.getExpiryDate()
-
setExpiryDate
public void setExpiryDate(java.time.Instant expiryInstant)
Sets expiration date.Note: the object returned by this method is considered immutable. Changing it (e.g. using setTime()) could result in undefined behaviour. Do so at your peril.
- Specified by:
setExpiryDate
in interfaceSetCookie
- Parameters:
expiryInstant
- theInstant
after which this cookie is no longer valid.- Since:
- 5.2
- See Also:
getExpiryInstant()
-
isPersistent
public boolean isPersistent()
Returnsfalse
if the cookie should be discarded at the end of the "session";true
otherwise.- Specified by:
isPersistent
in interfaceCookie
- Returns:
false
if the cookie should be discarded at the end of the "session";true
otherwise
-
getDomain
public java.lang.String getDomain()
Returns domain attribute of the cookie.- Specified by:
getDomain
in interfaceCookie
- Returns:
- the value of the domain attribute
- See Also:
setDomain(java.lang.String)
-
setDomain
public void setDomain(java.lang.String domain)
Sets the domain attribute.- Specified by:
setDomain
in interfaceSetCookie
- Parameters:
domain
- The value of the domain attribute- See Also:
getDomain()
-
getPath
public java.lang.String getPath()
Returns the path attribute of the cookie- Specified by:
getPath
in interfaceCookie
- Returns:
- The value of the path attribute.
- See Also:
setPath(java.lang.String)
-
setPath
public void setPath(java.lang.String path)
Sets the path attribute.
-
isSecure
public boolean isSecure()
Description copied from interface:Cookie
Indicates whether this cookie requires a secure connection.- Specified by:
isSecure
in interfaceCookie
- Returns:
true
if this cookie should only be sent over secure connections.- See Also:
setSecure(boolean)
-
setSecure
public void setSecure(boolean secure)
Sets the secure attribute of the cookie.When
true
the cookie should only be sent using a secure protocol (https). This should only be set when the cookie's originating server used a secure protocol to set the cookie's value.- Specified by:
setSecure
in interfaceSetCookie
- Parameters:
secure
- The value of the secure attribute- See Also:
isSecure()
-
setHttpOnly
public void setHttpOnly(boolean httpOnly)
Sets the http-only attribute of the cookie.- Specified by:
setHttpOnly
in interfaceSetCookie
- Parameters:
httpOnly
- true if this cookie is to be marked ashttpOnly
, false otherwise- Since:
- 5.2
-
isExpired
@Deprecated public boolean isExpired(java.util.Date date)
Deprecated.Returns true if this cookie has expired.
-
isExpired
public boolean isExpired(java.time.Instant instant)
Returns true if this cookie has expired.
-
getCreationDate
@Deprecated public java.util.Date getCreationDate()
Deprecated.UsegetCreationInstant()
.Description copied from interface:Cookie
Returns creation time of the cookie.- Specified by:
getCreationDate
in interfaceCookie
- Since:
- 4.4
-
getCreationInstant
public java.time.Instant getCreationInstant()
Description copied from interface:Cookie
Returns creation time of the cookie.- Specified by:
getCreationInstant
in interfaceCookie
- Since:
- 5.2
-
isHttpOnly
public boolean isHttpOnly()
Description copied from interface:Cookie
Checks whether this Cookie has been marked ashttpOnly
.The default implementation returns
false
.- Specified by:
isHttpOnly
in interfaceCookie
- Returns:
- true if this Cookie has been marked as
httpOnly
, false otherwise - Since:
- 5.2
- See Also:
setHttpOnly(boolean)
-
setCreationDate
@Deprecated public void setCreationDate(java.util.Date creationDate)
Deprecated.- Since:
- 4.4
-
setCreationDate
public void setCreationDate(java.time.Instant creationDate)
- Since:
- 5.2
-
setAttribute
public void setAttribute(java.lang.String name, java.lang.String value)
-
getAttribute
public java.lang.String getAttribute(java.lang.String name)
- Specified by:
getAttribute
in interfaceCookie
-
containsAttribute
public boolean containsAttribute(java.lang.String name)
- Specified by:
containsAttribute
in interfaceCookie
-
removeAttribute
public boolean removeAttribute(java.lang.String name)
- Since:
- 4.4
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
- Overrides:
clone
in classjava.lang.Object
- Throws:
java.lang.CloneNotSupportedException
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-