public static final class Cookie.Builder
extends java.lang.Object
Cookie
.
Builders are created by invoking Cookie.newBuilder(String)
. Each of the setter methods
modifies the state of the builder and returns the same instance. Builders are not thread-safe
and should not be used concurrently from multiple threads without external synchronization.
Modifier and Type | Method and Description |
---|---|
Cookie |
build()
Returns a new
Cookie built from the current state of this builder. |
Cookie.Builder |
creationTime(Timestamp creationTime)
Sets the cookie creation time.
|
Cookie.Builder |
expirationTime(Timestamp expirationTime)
Sets the cookie expiration time.
|
Cookie.Builder |
httpOnly(boolean httpOnly)
Specifies whether the cookie is considered HTTP only.
|
Cookie.Builder |
name(java.lang.String name)
Sets the cookie name.
|
Cookie.Builder |
path(java.lang.String path)
Sets the cookie path.
|
Cookie.Builder |
sameSite(SameSite sameSite)
Sets the SameSite cookie attribute value that allows you to declare if your cookie should
be restricted to a first-party or same-site context.
|
Cookie.Builder |
secure(boolean secure)
Specifies whether the cookie is restricted to a secure protocol (HTTPS or WSS) or it can
be sent using any protocol.
|
Cookie.Builder |
value(java.lang.String value)
Sets the cookie value.
|
public Cookie.Builder name(java.lang.String name)
name
- the cookie namepublic Cookie.Builder value(java.lang.String value)
value
- the cookie valuepublic Cookie.Builder path(java.lang.String path)
path
- the cookie pathpublic Cookie.Builder secure(boolean secure)
secure
- the flag valuepublic Cookie.Builder httpOnly(boolean httpOnly)
httpOnly
- the flag valuepublic Cookie.Builder creationTime(Timestamp creationTime)
creationTime
- the cookie creation timepublic Cookie.Builder expirationTime(Timestamp expirationTime)
expirationTime
- the cookie expiration timepublic Cookie.Builder sameSite(SameSite sameSite)
By default, the attribute value is set to SameSite.LAX_MODE
which means
cookies are only set when the domain in the URL of the browser matches the domain of the
cookie — a first-party cookie.
The SameSite.NONE
value requires that the secure(boolean)
attribute
is set to true
.
sameSite
- the SameSite cookie attribute value