Package io.micronaut.http.cookie
Interface Cookie
- All Superinterfaces:
Comparable<Cookie>,Serializable
- All Known Implementing Classes:
NettyCookie,SimpleCookie
An interface representing a Cookie. See .
- Since:
- 1.0
- Author:
- Graeme Rocher
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringControls whether a cookie is sent with cross-site requests.static final Stringstatic final longConstant for undefined MaxAge attribute value. -
Method Summary
Modifier and TypeMethodDescriptiondefault @NonNull Cookieconfigure(@NonNull CookieConfiguration configuration) Configure the Cookie with the given configuration.default @NonNull Cookieconfigure(@NonNull CookieConfiguration configuration, boolean isSecure) Configure the Cookie with the given configuration.@NonNull CookieSets the domain of the cookie.@Nullable StringGets the domain name of this Cookie.longGets the maximum age of the cookie in seconds.@NonNull StringgetName()@Nullable StringgetPath()The path of the cookie.Checks to see if thisCookiecan be sent along cross-site requests.@NonNull StringgetValue()default @NonNull CookiehttpOnly()Sets this cookie as HTTP-Only.@NonNull CookiehttpOnly(boolean httpOnly) Sets whether the cookie is HTTP-Only.booleanChecks to see if thisCookiecan only be accessed via HTTP.booleanisSecure()@NonNull CookiemaxAge(long maxAge) Sets the max age of the cookie in seconds.default @NonNull CookiemaxAge(@NonNull TemporalAmount maxAge) Sets the max age of the cookie.static @NonNull CookieConstruct a new Cookie for the given name and value.@NonNull CookieSets the path of the cookie.default @NonNull CookieDetermines if thisCookiecan be sent along cross-site requests.default @NonNull Cookiesecure()Sets this cookie as secure.@NonNull Cookiesecure(boolean secure) Sets whether the cookie is secure.@NonNull CookieSets the value.Methods inherited from interface java.lang.Comparable
compareTo
-
Field Details
-
UNDEFINED_MAX_AGE
static final long UNDEFINED_MAX_AGEConstant for undefined MaxAge attribute value.- See Also:
-
ATTRIBUTE_SECURE
- See Also:
-
ATTRIBUTE_HTTP_ONLY
- See Also:
-
ATTRIBUTE_SAME_SITE
Controls whether a cookie is sent with cross-site requests.- See Also:
-
ATTRIBUTE_DOMAIN
- See Also:
-
ATTRIBUTE_PATH
- See Also:
-
ATTRIBUTE_EXPIRES
- See Also:
-
ATTRIBUTE_MAX_AGE
- See Also:
-
-
Method Details
-
getName
@NonNull String getName()- Returns:
- The name of the cookie
-
getValue
@NonNull String getValue()- Returns:
- The value of the cookie
-
getDomain
@Nullable 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 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()Gets the maximum age of the cookie in seconds. If the max age has not been explicitly set, then the value returned will beUNDEFINED_MAX_AGE, indicating that the Max-Age Attribute should not be written.- Returns:
- The maximum age of the cookie in seconds
-
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
Determines if thisCookiecan be sent along cross-site requests. For more information, please look here- Parameters:
sameSite- SameSite value- Returns:
- This cookie
-
maxAge
Sets the max age of the cookie in seconds. When not explicitly set, the max age will default toUNDEFINED_MAX_AGEand cause the Max-Age Attribute not to be encoded.- Parameters:
maxAge- The max age- Returns:
- This cookie
-
value
Sets the value.- Parameters:
value- The value of the cookie- Returns:
- This cookie
-
domain
Sets the domain of the cookie.- Parameters:
domain- The domain of the cookie- Returns:
- This cookie
-
path
Sets the path of the cookie.- Parameters:
path- The path of the cookie- Returns:
- This cookie
-
secure
Sets whether the cookie is secure.- Parameters:
secure- Is the cookie secure- Returns:
- This cookie
-
secure
Sets this cookie as secure.- Returns:
- This Cookie
- Since:
- 4.3.0
-
httpOnly
Sets whether the cookie is HTTP-Only.- Parameters:
httpOnly- Is the cookie HTTP-Only- Returns:
- This cookie
-
httpOnly
Sets this cookie as HTTP-Only.- Returns:
- This cookie
- Since:
- 4.3.0
-
configure
Configure the Cookie with the given configuration.- Parameters:
configuration- The configuration- Returns:
- The cookie
-
configure
Configure the Cookie with the given configuration.- Parameters:
configuration- The configurationisSecure- Is the request secure- Returns:
- The cookie
-
maxAge
Sets the max age of the cookie.- Parameters:
maxAge- The max age- Returns:
- This cookie
-
of
Construct a new Cookie for the given name and value.- Parameters:
name- The namevalue- The value- Returns:
- The Cookie
-