public class Cookie
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable
A formal specification of Cookies can be found in RFC 2109 ("HTTP State Management Mechanism")
Constructor and Description |
---|
Cookie(java.lang.String name,
java.lang.String value)
Creates a cookie with a name and a value.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Clones the Cookie.
|
java.lang.String |
getComment()
Gets the comment of the cookie
|
java.lang.String |
getDomain()
Gets this cookie's domain
|
int |
getMaxAge()
Gets the time-to-live for this cookie, in seconds.
If it is 0 then the client will delete the cookie. If it is -1 (which is the default) then the cookie will be a non-persistent cookie. This means that the cookie will live as long as the http client lives, and will not be saved to disk. |
java.lang.String |
getName()
Get the name
|
java.lang.String |
getPath()
Gets the path for which requests this cookie will be attached.
|
boolean |
getSecure()
Whether only secure means (https) should be used when sending this
cookie to a server.
|
java.lang.String |
getValue()
Gets the value
|
int |
getVersion()
Gets the version of this cookie.
|
boolean |
isHttpOnly()
Indicates whether this cookie has been marked as HTTP-only.
|
void |
setComment(java.lang.String comment)
Sets the comment of the cookie.
|
void |
setDomain(java.lang.String domain)
Sets the domain for which this Cookie will be used.
|
void |
setHttpOnly(boolean isHttpOnly)
Marks or unmarks this cookie as HTTP-only.
|
void |
setMaxAge(int maxAge)
Sets the maximum lifetime of the cookie in seconds.
If set to 0 then the cookie will be deleted by the client. If set to a negative value (such as -1 which is the default) then the cookie will be a non-persistent cookie. This means that the cookie will live as long as the http client lives, and will not be saved to disk. |
void |
setPath(java.lang.String path)
Set the path with which requests this cookie will be sent back to
the server.
|
void |
setSecure(boolean secure)
Whether only secure means (https) should be used when sending this
cookie to a server.
|
void |
setValue(java.lang.String value)
Sets a new value.
|
void |
setVersion(int version)
Sets the version.
|
public Cookie(java.lang.String name, java.lang.String value)
name
- The name of the cookievalue
- The value of the cookiejava.lang.IllegalArgumentException
- if name is not a valid HTTP/1.1 token
or starts with $public void setComment(java.lang.String comment)
comment
- the comment to bepublic java.lang.String getComment()
public void setDomain(java.lang.String domain)
domain
- The cookie's domainpublic java.lang.String getDomain()
public void setMaxAge(int maxAge)
maxAge
- The time-to-live for the cookie, in secondspublic int getMaxAge()
public void setPath(java.lang.String path)
path
- the pathpublic java.lang.String getPath()
public void setSecure(boolean secure)
secure
- whether this cookie should be secure or not.public boolean getSecure()
public java.lang.String getName()
public void setValue(java.lang.String value)
value
- The new valuepublic java.lang.String getValue()
public int getVersion()
public void setVersion(int version)
version
- the versionpublic java.lang.Object clone()
clone
in class java.lang.Object
public void setHttpOnly(boolean isHttpOnly)
isHttpOnly
public boolean isHttpOnly()
setHttpOnly(boolean)