Package io.micronaut.http.cookie
Interface Cookie
-
- All Superinterfaces:
java.lang.Comparable<Cookie>,java.io.Serializable
- All Known Implementing Classes:
SimpleCookie
public interface Cookie extends java.lang.Comparable<Cookie>, java.io.Serializable
An interface representing a Cookie. See https://tools.ietf.org/html/rfc6265.- Since:
- 1.0
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Cookieconfigure(CookieConfiguration configuration)Configure the Cookie with the given configuration.default Cookieconfigure(CookieConfiguration configuration, boolean isSecure)Configure the Cookie with the given configuration.Cookiedomain(java.lang.String domain)Sets the domain of the cookie.java.lang.StringgetDomain()Gets the domain name of this Cookie.longgetMaxAge()java.lang.StringgetName()java.lang.StringgetPath()The path of the cookie.default java.util.Optional<SameSite>getSameSite()Checks to see if thisCookiecan be sent along cross-site requests.java.lang.StringgetValue()CookiehttpOnly(boolean httpOnly)Sets whether the cookie is HTTP-Only.booleanisHttpOnly()Checks to see if thisCookiecan only be accessed via HTTP.booleanisSecure()CookiemaxAge(long maxAge)Sets the max age of the cookie in seconds.default CookiemaxAge(java.time.temporal.TemporalAmount maxAge)Sets the max age of the cookie.static Cookieof(java.lang.String name, java.lang.String value)Construct a new Cookie for the given name and value.Cookiepath(java.lang.String path)Sets the path of the cookie.default CookiesameSite(SameSite sameSite)Determines if this thisCookiecan be sent along cross-site requests.Cookiesecure(boolean secure)Sets whether the cookie is secure.Cookievalue(java.lang.String value)Sets the value.
-
-
-
Method Detail
-
getName
@NonNull java.lang.String getName()
- Returns:
- The name of the cookie
-
getValue
@NonNull java.lang.String getValue()
- Returns:
- The value of the cookie
-
getDomain
@Nullable java.lang.String getDomain()
Gets the domain name of this Cookie.Domain names are formatted according to RFC 2109.
- Returns:
- the domain name of this Cookie
-
getPath
@Nullable java.lang.String getPath()
The path of the cookie. The cookie is visible to all paths below the request path on the server.- Returns:
- The cookie path
-
isHttpOnly
boolean isHttpOnly()
Checks to see if thisCookiecan only be accessed via HTTP. If this returns true, theCookiecannot be accessed through client side script - But only if the browser supports it.See here for reference
- Returns:
- True if this
Cookieis HTTP-only or false if it isn't
-
isSecure
boolean isSecure()
- Returns:
- True if the cookie is secure
-
getMaxAge
long getMaxAge()
- Returns:
- The maximum age of the cookie in seconds
-
getSameSite
default java.util.Optional<SameSite> getSameSite()
Checks to see if thisCookiecan be sent along cross-site requests. For more information, please look here- Returns:
- The SameSite attribute of the cookie
-
sameSite
@NonNull default Cookie sameSite(@Nullable SameSite sameSite)
Determines if this thisCookiecan be sent along cross-site requests. For more information, please look here- Parameters:
sameSite- SameSite value- Returns:
- This cookie
-
maxAge
@NonNull Cookie maxAge(long maxAge)
Sets the max age of the cookie in seconds.- Parameters:
maxAge- The max age- Returns:
- This cookie
-
value
@NonNull Cookie value(@NonNull java.lang.String value)
Sets the value.- Parameters:
value- The value of the cookie- Returns:
- This cookie
-
domain
@NonNull Cookie domain(@Nullable java.lang.String domain)
Sets the domain of the cookie.- Parameters:
domain- The domain of the cookie- Returns:
- This cookie
-
path
@NonNull Cookie path(@Nullable java.lang.String path)
Sets the path of the cookie.- Parameters:
path- The path of the cookie- Returns:
- This cookie
-
secure
@NonNull Cookie secure(boolean secure)
Sets whether the cookie is secure.- Parameters:
secure- Is the cookie secure- Returns:
- This cookie
-
httpOnly
@NonNull Cookie httpOnly(boolean httpOnly)
Sets whether the cookie is HTTP-Only.- Parameters:
httpOnly- Is the cookie HTTP-Only- Returns:
- This cookie
-
configure
@NonNull default Cookie configure(@NonNull CookieConfiguration configuration)
Configure the Cookie with the given configuration.- Parameters:
configuration- The configuration- Returns:
- The cookie
-
configure
@NonNull default Cookie configure(@NonNull CookieConfiguration configuration, boolean isSecure)
Configure the Cookie with the given configuration.- Parameters:
configuration- The configurationisSecure- Is the request secure- Returns:
- The cookie
-
maxAge
@NonNull default Cookie maxAge(@NonNull java.time.temporal.TemporalAmount maxAge)
Sets the max age of the cookie.- Parameters:
maxAge- The max age- Returns:
- This cookie
-
of
@NonNull static Cookie of(@NonNull java.lang.String name, @NonNull java.lang.String value)
Construct a new Cookie for the given name and value.- Parameters:
name- The namevalue- The value- Returns:
- The Cookie
-
-