Interface Context.Cookie
- Enclosing interface:
Context
public static interface Context.Cookie
This interface represents a cookie used in HTTP communication. Cookies are small pieces of data
sent from a server to a web browser and stored on the user's computer. They can be used to
store information about a user's session, preferences, or other data.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic enumCookie SameSite options. -
Method Summary
Modifier and TypeMethodDescriptiondomain()Returns the domain for which this cookie is valid.Sets the domain for which this cookie is valid.static Context.CookieCreates and returns a new expired cookie with the given name.expires()Returns the date and time when this cookie expires.expires(ZonedDateTime expires) Sets the date and time when this cookie expires.booleanhttpOnly()Indicates if the HttpOnly attribute is enabled for this cookie.httpOnly(boolean httpOnly) Sets the HttpOnly attribute for this cookie.maxAge()Returns the maximum age (in seconds) of this cookie.Sets the maximum age (in seconds) of this cookie.name()Returns the name of this cookie.static Context.CookieCreates and returns a new cookie with the given name and value.booleanIndicates if the Partitioned attribute is enabled for this cookie.partitioned(boolean partitioned) Set the Partitioned attribute for this cookie.path()Returns the path on the server for which this cookie is valid.Sets the path on the server for which this cookie is valid.sameSite()Return the SameSite setting.sameSite(Context.Cookie.SameSite sameSite) Set the SameSite setting for this cookie.booleansecure()Indicates whether this cookie should only be sent over secure connections (HTTPS).secure(boolean secure) Sets the secure attribute for this cookie.toString()Returns content of the cookie as a 'Set-Cookie:' header value specified by RFC6265.value()Returns the value stored in this cookie.
-
Method Details
-
expired
Creates and returns a new expired cookie with the given name. This cookie will be sent to the browser but will be immediately discarded. It's useful for removing existing cookies.- Parameters:
name- The name of the cookie.- Returns:
- A new expired cookie with the given name.
-
of
Creates and returns a new cookie with the given name and value.- Parameters:
name- The name of the cookie.value- The value to store in the cookie.- Returns:
- A new cookie with the given name and value.
-
domain
String domain()Returns the domain for which this cookie is valid.- Returns:
- The domain associated with the cookie, or null if not set.
-
domain
Sets the domain for which this cookie is valid.- Parameters:
domain- The domain for which the cookie should be valid.- Returns:
- A new cookie instance with the updated domain.
-
expires
ZonedDateTime expires()Returns the date and time when this cookie expires.- Returns:
- The expiration date and time of the cookie, or null if not set.
-
expires
Sets the date and time when this cookie expires.- Parameters:
expires- The date and time when the cookie should expire.- Returns:
- A new cookie instance with the updated expires value.
-
httpOnly
boolean httpOnly()Indicates if the HttpOnly attribute is enabled for this cookie.The HttpOnly attribute ensures that the cookie is inaccessible to JavaScript, helping to mitigate cross-site scripting (XSS) attacks.
- Returns:
trueif the cookie has the HttpOnly attribute enabled,falseotherwise
-
httpOnly
Sets the HttpOnly attribute for this cookie.When enabled, the cookie will not be accessible via client-side scripts, providing additional security against XSS attacks.
- Parameters:
httpOnly-trueto enable the HttpOnly attribute,falseto disable it- Returns:
- this cookie instance with the updated HttpOnly attribute
-
maxAge
Duration maxAge()Returns the maximum age (in seconds) of this cookie. An expired cookie (maxAge of 0) will be deleted immediately by the browser.- Returns:
- The maximum age of the cookie in seconds, or null if not set.
-
maxAge
Sets the maximum age (in seconds) of this cookie. An expired cookie (maxAge of 0) will be deleted immediately by the browser.- Parameters:
maxAge- The maximum age of the cookie in seconds.- Returns:
- A new cookie instance with the updated maxAge.
-
name
-
partitioned
boolean partitioned()Indicates if the Partitioned attribute is enabled for this cookie. -
partitioned
Set the Partitioned attribute for this cookie. -
path
String path()Returns the path on the server for which this cookie is valid. Cookies are only sent to the browser if the URL path starts with this value.- Returns:
- The path associated with the cookie, or null if not set.
-
path
Sets the path on the server for which this cookie is valid. Cookies are only sent to the browser if the URL path starts with this value.- Parameters:
path- The path on the server for which the cookie should be valid.- Returns:
- A new cookie instance with the updated path.
-
sameSite
Context.Cookie.SameSite sameSite()Return the SameSite setting. -
sameSite
Set the SameSite setting for this cookie. -
secure
boolean secure()Indicates whether this cookie should only be sent over secure connections (HTTPS).- Returns:
- True if the cookie should only be sent over secure connections, false otherwise.
-
secure
Sets the secure attribute for this cookie.When enabled, the cookie will only be sent over secure HTTPS connections.
- Parameters:
secure-trueto enable the secure attribute,falseto disable it- Returns:
- this cookie instance with the updated secure attribute
-
toString
-
value
-