public final class ResponseCookie extends HttpCookie
HttpCookie
subclass with the additional attributes allowed in
the "Set-Cookie" response header. To build an instance use the from(java.lang.String, java.lang.String)
static method.Modifier and Type | Class and Description |
---|---|
static interface |
ResponseCookie.ResponseCookieBuilder
A builder for a server-defined HttpCookie with attributes.
|
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
domain |
private boolean |
httpOnly |
private java.time.Duration |
maxAge |
private java.lang.String |
path |
private java.lang.String |
sameSite |
private boolean |
secure |
Modifier | Constructor and Description |
---|---|
private |
ResponseCookie(java.lang.String name,
java.lang.String value,
java.time.Duration maxAge,
java.lang.String domain,
java.lang.String path,
boolean secure,
boolean httpOnly,
java.lang.String sameSite)
Private constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(java.lang.Object other) |
static ResponseCookie.ResponseCookieBuilder |
from(java.lang.String name,
java.lang.String value)
Factory method to obtain a builder for a server-defined cookie that starts
with a name-value pair and may also include attributes.
|
java.lang.String |
getDomain()
Return the cookie "Domain" attribute, or
null if not set. |
java.time.Duration |
getMaxAge()
Return the cookie "Max-Age" attribute in seconds.
|
java.lang.String |
getPath()
Return the cookie "Path" attribute, or
null if not set. |
java.lang.String |
getSameSite()
Return the cookie "SameSite" attribute, or
null if not set. |
int |
hashCode() |
boolean |
isHttpOnly()
Return
true if the cookie has the "HttpOnly" attribute. |
boolean |
isSecure()
Return
true if the cookie has the "Secure" attribute. |
java.lang.String |
toString() |
getName, getValue
private final java.time.Duration maxAge
@Nullable private final java.lang.String domain
@Nullable private final java.lang.String path
private final boolean secure
private final boolean httpOnly
@Nullable private final java.lang.String sameSite
private ResponseCookie(java.lang.String name, java.lang.String value, java.time.Duration maxAge, @Nullable java.lang.String domain, @Nullable java.lang.String path, boolean secure, boolean httpOnly, @Nullable java.lang.String sameSite)
from(String, String)
.public java.time.Duration getMaxAge()
A positive value indicates when the cookie expires relative to the current time. A value of 0 means the cookie should expire immediately. A negative value means no "Max-Age" attribute in which case the cookie is removed when the browser is closed.
@Nullable public java.lang.String getDomain()
null
if not set.@Nullable public java.lang.String getPath()
null
if not set.public boolean isSecure()
true
if the cookie has the "Secure" attribute.public boolean isHttpOnly()
true
if the cookie has the "HttpOnly" attribute.@Nullable public java.lang.String getSameSite()
null
if not set.
This limits the scope of the cookie such that it will only be attached to
same site requests if "Strict"
or cross-site requests if "Lax"
.
public boolean equals(java.lang.Object other)
equals
in class HttpCookie
public int hashCode()
hashCode
in class HttpCookie
public java.lang.String toString()
toString
in class HttpCookie
public static ResponseCookie.ResponseCookieBuilder from(java.lang.String name, java.lang.String value)
name
- the cookie namevalue
- the cookie value