Interface Cookie
public interface Cookie
Represents an HTTP Cookie.
All cookies must have a name and a value and can optionally have other fields set such as path, domain, etc.
-
Method Summary
Modifier and TypeMethodDescriptionstatic CookieCreate a new cookieencode()Encode the cookie to a string.longgetName()getPath()getValue()booleanbooleanisSecure()Sets the domain of this cookiesetHttpOnly(boolean httpOnly) Determines if this cookie is HTTP only.setMaxAge(long maxAge) Sets the maximum age of this cookie in seconds.Sets the path of this cookie.setSameSite(CookieSameSite policy) Sets the same site of this cookie.setSecure(boolean secure) Sets the security getStatus of this cookieSets the value of this cookie
-
Method Details
-
cookie
-
getName
String getName()- Returns:
- the name of this cookie
-
getValue
String getValue()- Returns:
- the value of this cookie
-
setValue
-
setDomain
-
getDomain
String getDomain()- Returns:
- the domain for the cookie
-
setPath
-
getPath
String getPath()- Returns:
- the path for this cookie
-
setMaxAge
Sets the maximum age of this cookie in seconds. If an age of0is specified, this cookie will be automatically removed by browser because it will expire immediately. IfLong.MIN_VALUEis specified, this cookie will be removed when the browser is closed. If you don't set this the cookie will be a session cookie and be removed when the browser is closed.- Parameters:
maxAge- The maximum age of this cookie in seconds
-
getMaxAge
long getMaxAge()- Returns:
- the maxAge of this cookie
-
setSecure
Sets the security getStatus of this cookie- Parameters:
secure- True if this cookie is to be secure, otherwise false- Returns:
- a reference to this, so the API can be used fluently
-
isSecure
boolean isSecure()- Returns:
- the security status of this cookie
-
setHttpOnly
Determines if this cookie is HTTP only. If set to true, this cookie cannot be accessed by a client side script. However, this works only if the browser supports it. For for information, please look here.- Parameters:
httpOnly- True if the cookie is HTTP only, otherwise false.
-
isHttpOnly
boolean isHttpOnly()- Returns:
- the http only status of this cookie
-
setSameSite
Sets the same site of this cookie.- Parameters:
policy- The policy should be one ofCookieSameSite.- Returns:
- a reference to this, so the API can be used fluently
-
getSameSite
CookieSameSite getSameSite()- Returns:
- the SameSite policy of this cookie
-
encode
String encode()Encode the cookie to a string. This is what is used in the Set-Cookie header- Returns:
- the encoded cookie
-