Modifier and Type | Method and Description |
---|---|
Cookie |
build()
Instantiates a new immutable
Cookie based on the values set in this builder. |
Cookie.Builder |
setComment(String comment)
Specifies a comment that describes a cookie’s purpose.
|
Cookie.Builder |
setDomain(String domain)
Specifies the domain within which this cookie should be presented.
|
Cookie.Builder |
setHttpOnly(boolean httpOnly)
Marks or unmarks this Cookie as HttpOnly.
|
Cookie.Builder |
setMaxAge(int maxAge)
Sets the maximum age in seconds for this Cookie.
|
Cookie.Builder |
setPath(String uri)
Specifies a path for the cookie to which the client should return the cookie.
|
Cookie.Builder |
setSecure(boolean flag)
Indicates to the browser whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL.
|
Cookie.Builder |
setVersion(int version)
Sets the version of the cookie protocol that this Cookie complies with.
|
public Cookie.Builder setPath(String uri)
Specifies a path for the cookie to which the client should return the cookie.
The cookie is visible to all the pages in the directory you specify, and all the pages in that directory’s subdirectories. A cookie’s path must include the servlet that set the cookie, for example, /catalog, which makes the cookie visible to all directories on the server under /catalog.
Consult RFC 2109 (available on the Internet) for more information on setting path names for cookies.
uri
- a String
specifying a pathCookie.getPath()
public Cookie.Builder setDomain(String domain)
Specifies the domain within which this cookie should be presented.
The form of the domain name is specified by RFC 2109. A domain name begins with a dot (.foo.com
) and means that the cookie is visible to servers in a specified Domain Name System (DNS) zone (for example, www.foo.com
, but not a.b.foo.com
). By default, cookies are only returned to the server that sent them.
domain
- the domain name within which this cookie is visible; form is according to RFC 2109Cookie.getDomain()
public Cookie.Builder setMaxAge(int maxAge)
Sets the maximum age in seconds for this Cookie.
A positive value indicates that the cookie will expire after that many seconds have passed. Note that the value is the maximum age when the cookie will expire, not the cookie’s current age.
A negative value means that the cookie is not stored persistently and will be deleted when the Web browser exits. A zero value causes the cookie to be deleted.
maxAge
- an integer specifying the maximum age of the cookie in seconds; if negative, means the cookie is not stored; if zero, deletes the cookieCookie.getMaxAge()
public Cookie.Builder setComment(String comment)
Specifies a comment that describes a cookie’s purpose. The comment is useful if the browser presents the cookie to the user. Comments are not supported by Netscape Version 0 cookies.
comment
- a String
specifying the comment to display to the userCookie.getComment()
public Cookie.Builder setVersion(int version)
Sets the version of the cookie protocol that this Cookie complies with.
Version 0 complies with the original Netscape cookie specification. Version 1 complies with RFC 2109.
Since RFC 2109 is still somewhat new, consider version 1 as experimental; do not use it yet on production sites.
version
- 0 if the cookie should comply with the original Netscape specification; 1 if the cookie should comply with RFC 2109Cookie.getVersion()
public Cookie.Builder setHttpOnly(boolean httpOnly)
Marks or unmarks this Cookie as HttpOnly.
If httpOnly
is set to true
, this cookie is marked as HttpOnly, by adding the HttpOnly
attribute to it.
HttpOnly cookies are not supposed to be exposed to client-side scripting code, and may therefore help mitigate certain kinds of cross-site scripting attacks.
httpOnly
- true
if this cookie is to be marked as HttpOnly, false
otherwiseCookie.isHttpOnly()
public Cookie.Builder setSecure(boolean flag)
Indicates to the browser whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL.
The default value is false
.
flag
- if true
, sends the cookie from the browser to the server only when using a secure protocol; if false
, sent on any protocolCookie.isSecure()