- 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.
-
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()Checks 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.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.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.
-
name
String name()Returns the name of this cookie.- Returns:
- The name of the cookie.
-
value
String value()Returns the value stored in this cookie.- Returns:
- The value of the cookie.
-
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.
-
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.
-
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.
-
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.
-
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
-
httpOnly
boolean httpOnly()Checks 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
-
toString
String toString()Returns content of the cookie as a 'Set-Cookie:' header value specified by RFC6265.
-