Package com.linecorp.armeria.common
Interface Cookie
- All Superinterfaces:
Comparable<Cookie>
An interface defining an
HTTP cookie.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
Constant for undefined MaxAge attribute value. -
Method Summary
Modifier and TypeMethodDescriptionstatic CookieBuilder
Deprecated.default int
domain()
Returns the domain of thisCookie
.static Cookies
fromCookieHeader
(boolean strict, String cookieHeader) Decodes the specified"Cookie"
header value into a set ofCookie
s.static Cookies
fromCookieHeader
(String cookieHeader) Decodes the specified"Cookie"
header value into a set ofCookie
s.static Cookies
fromCookieHeaders
(boolean strict, Iterable<String> cookieHeaders) Decodes the specified"Cookie"
header values into a set ofCookie
s.static Cookies
fromCookieHeaders
(boolean strict, String... cookieHeaders) Decodes the specified"Cookie"
header values into a set ofCookie
s.static Cookies
fromCookieHeaders
(Iterable<String> cookieHeaders) Decodes the specified"Cookie"
header values into a set ofCookie
s.static Cookies
fromCookieHeaders
(String... cookieHeaders) Decodes the specified"Cookie"
header values into a set ofCookie
s.fromSetCookieHeader
(boolean strict, String setCookieHeader) Decodes the specified"Set-Cookie"
header value into aCookie
.fromSetCookieHeader
(String setCookieHeader) Decodes the specified"Set-Cookie"
header value into aCookie
.static Cookies
fromSetCookieHeaders
(boolean strict, Iterable<String> setCookieHeaders) Decodes the specified"Set-Cookie"
header values intoCookie
s.static Cookies
fromSetCookieHeaders
(boolean strict, String... setCookieHeaders) Decodes the specified"Set-Cookie"
header values intoCookie
s.static Cookies
fromSetCookieHeaders
(boolean strict, Collection<String> setCookieHeaders) Decodes the specified"Set-Cookie"
header values intoCookie
s.static Cookies
fromSetCookieHeaders
(Iterable<String> setCookieHeaders) Decodes the specified"Set-Cookie"
header values intoCookie
s.static Cookies
fromSetCookieHeaders
(String... setCookieHeaders) Decodes the specified"Set-Cookie"
header values intoCookie
s.static Cookies
fromSetCookieHeaders
(Collection<String> setCookieHeaders) Decodes the specified"Set-Cookie"
header values intoCookie
s.boolean
Returns whether thisCookie
should only match its original host in domain matching.boolean
Returns whether thisCookie
can only be accessed via HTTP.boolean
isSecure()
Returns whether thisCookie
is secure.boolean
Returns whether the raw value of thisCookie
was wrapped with double quotes in the original"Set-Cookie"
header.long
maxAge()
Returns the maximum age of thisCookie
in seconds.name()
Returns the name of thisCookie
.static Cookie
Deprecated.UseofSecure(String, String)
instead to create a secureCookie
.static Cookie
Returns a newly createdCookie
with secure settings.path()
Returns the path of thisCookie
.sameSite()
Returns the"SameSite"
attribute of thisCookie
.static CookieBuilder
secureBuilder
(String name, String value) Returns a newly createdCookieBuilder
which builds aCookie
with secure settings.default CookieBuilder
Returns a newCookieBuilder
created from thisCookie
.default String
Encodes thisCookie
into a single"Cookie"
header value.default String
toCookieHeader
(boolean strict) Encodes thisCookie
into a single"Cookie"
header value.static String
toCookieHeader
(boolean strict, Cookie... cookies) Encodes the specifiedCookie
s into a"Cookie"
header value.static String
toCookieHeader
(boolean strict, Iterable<? extends Cookie> cookies) Encodes the specifiedCookie
s into a"Cookie"
header value.static String
toCookieHeader
(boolean strict, Collection<? extends Cookie> cookies) Encodes the specifiedCookie
s into a"Cookie"
header value.static String
toCookieHeader
(Cookie... cookies) Encodes the specifiedCookie
s into a"Cookie"
header value.static String
toCookieHeader
(Iterable<? extends Cookie> cookies) Encodes the specifiedCookie
s into a"Cookie"
header value.static String
toCookieHeader
(Collection<? extends Cookie> cookies) Encodes the specifiedCookie
s into a"Cookie"
header value.default String
Encodes thisCookie
into a single"Set-Cookie"
header value.default String
toSetCookieHeader
(boolean strict) Encodes thisCookie
into a single"Set-Cookie"
header value.toSetCookieHeaders
(boolean strict, Cookie... cookies) Encodes the specifiedCookie
s into"Set-Cookie"
header values.toSetCookieHeaders
(boolean strict, Iterable<? extends Cookie> cookies) Encodes the specifiedCookie
s into"Set-Cookie"
header values.toSetCookieHeaders
(boolean strict, Collection<? extends Cookie> cookies) Encodes the specifiedCookie
s into"Set-Cookie"
header values.toSetCookieHeaders
(Cookie... cookies) Encodes the specifiedCookie
s into"Set-Cookie"
header values.toSetCookieHeaders
(Iterable<? extends Cookie> cookies) Encodes the specifiedCookie
s into"Set-Cookie"
header values.toSetCookieHeaders
(Collection<? extends Cookie> cookies) Encodes the specifiedCookie
s into"Set-Cookie"
header values.value()
Returns the value of thisCookie
.default Cookie
withMutations
(Consumer<CookieBuilder> mutator)
-
Field Details
-
UNDEFINED_MAX_AGE
static final long UNDEFINED_MAX_AGEConstant for undefined MaxAge attribute value.- See Also:
-
-
Method Details
-
of
Deprecated.UseofSecure(String, String)
instead to create a secureCookie
.Returns a newly createdCookie
. -
ofSecure
Returns a newly createdCookie
with secure settings."Secure"
,"HttpOnly"
, and"SameSite=Strict"
are enabled. -
builder
Deprecated.UsesecureBuilder(String, String)
instead to create a secureCookie
.Returns a newly createdCookieBuilder
which builds aCookie
. -
secureBuilder
Returns a newly createdCookieBuilder
which builds aCookie
with secure settings."Secure"
,"HttpOnly"
, and"SameSite=Strict"
are enabled by default. -
fromCookieHeader
Decodes the specified"Cookie"
header value into a set ofCookie
s.- Parameters:
cookieHeader
- the"Cookie"
header value.- Returns:
- the decoded
Cookie
s.
-
fromCookieHeader
Decodes the specified"Cookie"
header value into a set ofCookie
s.- Parameters:
strict
- whether to validate that the cookie names and values are in the valid scope defined in RFC 6265.cookieHeader
- the"Cookie"
header value.- Returns:
- the decoded
Cookie
s.
-
fromCookieHeaders
Decodes the specified"Cookie"
header values into a set ofCookie
s.- Parameters:
cookieHeaders
- the"Cookie"
header values.- Returns:
- the decoded
Cookie
s.
-
fromCookieHeaders
Decodes the specified"Cookie"
header values into a set ofCookie
s.- Parameters:
cookieHeaders
- the"Cookie"
header values.- Returns:
- the decoded
Cookie
s.
-
fromCookieHeaders
Decodes the specified"Cookie"
header values into a set ofCookie
s.- Parameters:
strict
- whether to validate that the cookie names and values are in the valid scope defined in RFC 6265.cookieHeaders
- the"Cookie"
header values.- Returns:
- the decoded
Cookie
s.
-
fromCookieHeaders
Decodes the specified"Cookie"
header values into a set ofCookie
s.- Parameters:
strict
- whether to validate that the cookie names and values are in the valid scope defined in RFC 6265.cookieHeaders
- the"Cookie"
header values.- Returns:
- the decoded
Cookie
s.
-
toCookieHeader
Encodes the specifiedCookie
s into a"Cookie"
header value.- Parameters:
cookies
- theCookie
s to encode.- Returns:
- the encoded
"Cookie"
header value.
-
toCookieHeader
Encodes the specifiedCookie
s into a"Cookie"
header value.- Parameters:
cookies
- theCookie
s to encode.- Returns:
- the encoded
"Cookie"
header value. - Throws:
IllegalArgumentException
- ifcookies
is empty.
-
toCookieHeader
Encodes the specifiedCookie
s into a"Cookie"
header value.- Parameters:
cookies
- theCookie
s to encode.- Returns:
- the encoded
"Cookie"
header value. - Throws:
IllegalArgumentException
- ifcookies
is empty.
-
toCookieHeader
Encodes the specifiedCookie
s into a"Cookie"
header value.- Parameters:
strict
- whether to validate that cookie names and values are in the valid scope defined in RFC 6265 and to sort theCookie
s into order of decreasing path length, as specified in RFC 6265. Iffalse
, theCookie
s are encoded in the order in which they are given.cookies
- theCookie
s to encode.- Returns:
- the encoded
"Cookie"
header value.
-
toCookieHeader
Encodes the specifiedCookie
s into a"Cookie"
header value.- Parameters:
strict
- whether to validate that cookie names and values are in the valid scope defined in RFC 6265 and to sort theCookie
s into order of decreasing path length, as specified in RFC 6265. Iffalse
, theCookie
s are encoded in the order in which they are given.cookies
- theCookie
s to encode.- Returns:
- the encoded
"Cookie"
header value. - Throws:
IllegalArgumentException
- ifcookies
is empty.
-
toCookieHeader
Encodes the specifiedCookie
s into a"Cookie"
header value.- Parameters:
strict
- whether to validate that cookie names and values are in the valid scope defined in RFC 6265 and to sort theCookie
s into order of decreasing path length, as specified in RFC 6265. Iffalse
, theCookie
s are encoded in the order in which they are given.cookies
- theCookie
s to encode.- Returns:
- the encoded
"Cookie"
header value. - Throws:
IllegalArgumentException
- ifcookies
is empty.
-
fromSetCookieHeader
Decodes the specified"Set-Cookie"
header value into aCookie
.- Parameters:
setCookieHeader
- the"Set-Cookie"
header value.- Returns:
- the decoded
Cookie
if decoded successfully, ornull
otherwise.
-
fromSetCookieHeader
Decodes the specified"Set-Cookie"
header value into aCookie
.- Parameters:
strict
- whether to validate the cookie names and values are in the valid scope defined in RFC 6265.setCookieHeader
- the"Set-Cookie"
header value.- Returns:
- the decoded
Cookie
if decoded successfully, ornull
otherwise.
-
fromSetCookieHeaders
Decodes the specified"Set-Cookie"
header values intoCookie
s.- Parameters:
setCookieHeaders
- the"Set-Cookie"
header values.- Returns:
- the decoded
Cookie
s.
-
fromSetCookieHeaders
Decodes the specified"Set-Cookie"
header values intoCookie
s.- Parameters:
setCookieHeaders
- the"Set-Cookie"
header values.- Returns:
- the decoded
Cookie
s.
-
fromSetCookieHeaders
Decodes the specified"Set-Cookie"
header values intoCookie
s.- Parameters:
setCookieHeaders
- the"Set-Cookie"
header values.- Returns:
- the decoded
Cookie
s.
-
fromSetCookieHeaders
Decodes the specified"Set-Cookie"
header values intoCookie
s.- Parameters:
strict
- whether to validate the cookie names and values are in the valid scope defined in RFC 6265.setCookieHeaders
- the"Set-Cookie"
header values.- Returns:
- the decoded
Cookie
s.
-
fromSetCookieHeaders
Decodes the specified"Set-Cookie"
header values intoCookie
s.- Parameters:
strict
- whether to validate the cookie names and values are in the valid scope defined in RFC 6265.setCookieHeaders
- the"Set-Cookie"
header values.- Returns:
- the decoded
Cookie
s.
-
fromSetCookieHeaders
Decodes the specified"Set-Cookie"
header values intoCookie
s.- Parameters:
strict
- whether to validate the cookie names and values are in the valid scope defined in RFC 6265.setCookieHeaders
- the"Set-Cookie"
header values.- Returns:
- the decoded
Cookie
s.
-
toSetCookieHeaders
Encodes the specifiedCookie
s into"Set-Cookie"
header values.- Parameters:
cookies
- theCookie
s to encode.- Returns:
- the encoded
"Set-Cookie"
header values.
-
toSetCookieHeaders
Encodes the specifiedCookie
s into"Set-Cookie"
header values.- Parameters:
cookies
- theCookie
s to encode.- Returns:
- the encoded
"Set-Cookie"
header values.
-
toSetCookieHeaders
Encodes the specifiedCookie
s into"Set-Cookie"
header values.- Parameters:
cookies
- theCookie
s to encode.- Returns:
- the encoded
"Set-Cookie"
header values.
-
toSetCookieHeaders
Encodes the specifiedCookie
s into"Set-Cookie"
header values.- Parameters:
strict
- whether to validate that the cookie names and values are in the valid scope defined in RFC 6265.cookies
- theCookie
s to encode.- Returns:
- the encoded
"Set-Cookie"
header values.
-
toSetCookieHeaders
Encodes the specifiedCookie
s into"Set-Cookie"
header values.- Parameters:
strict
- whether to validate that the cookie names and values are in the valid scope defined in RFC 6265.cookies
- theCookie
s to encode.- Returns:
- the encoded
"Set-Cookie"
header values.
-
toSetCookieHeaders
Encodes the specifiedCookie
s into"Set-Cookie"
header values.- Parameters:
strict
- whether to validate that the cookie names and values are in the valid scope defined in RFC 6265.cookies
- theCookie
s to encode.- Returns:
- the encoded
"Set-Cookie"
header values.
-
name
String name()Returns the name of thisCookie
. -
value
String value()Returns the value of thisCookie
. -
isValueQuoted
boolean isValueQuoted()Returns whether the raw value of thisCookie
was wrapped with double quotes in the original"Set-Cookie"
header. -
domain
Returns the domain of thisCookie
.- Returns:
- the domain, or
null
.
-
path
Returns the path of thisCookie
.- Returns:
- the path, or
null
.
-
maxAge
long maxAge()Returns the maximum age of thisCookie
in seconds.- Returns:
- the maximum age, or
UNDEFINED_MAX_AGE
if unspecified.
-
isSecure
boolean isSecure()Returns whether thisCookie
is secure. -
isHttpOnly
boolean isHttpOnly() -
sameSite
Returns the"SameSite"
attribute of thisCookie
.- Returns:
- the
"SameSite"
attribute, ornull
.
-
isHostOnly
boolean isHostOnly() -
toCookieHeader
Encodes thisCookie
into a single"Cookie"
header value. Note that you must usetoCookieHeader(Collection)
when encoding more than oneCookie
, because it is prohibited to send multiple"Cookie"
headers in an HTTP request, according to RFC 6265.- Returns:
- a single RFC 6265-style
"Cookie"
header value.
-
toCookieHeader
Encodes thisCookie
into a single"Cookie"
header value. Note that you must usetoCookieHeader(boolean, Collection)
when encoding more than oneCookie
, because it is prohibited to send multiple"Cookie"
headers in an HTTP request, according to RFC 6265.- Parameters:
strict
- whether to validate that the cookie name and value are in the valid scope defined in RFC 6265.- Returns:
- a single RFC 6265-style
"Cookie"
header value.
-
toSetCookieHeader
Encodes thisCookie
into a single"Set-Cookie"
header value.- Returns:
- a single
"Set-Cookie"
header value.
-
toSetCookieHeader
Encodes thisCookie
into a single"Set-Cookie"
header value.- Parameters:
strict
- whether to validate that the cookie name and value are in the valid scope defined in RFC 6265.- Returns:
- a single
"Set-Cookie"
header value.
-
toBuilder
Returns a newCookieBuilder
created from thisCookie
.- See Also:
-
withMutations
Returns a newCookie
which is the result from the mutation by the specifiedConsumer
. This method is a shortcut for:builder = toBuilder(); mutator.accept(builder); return builder.build();
- See Also:
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Cookie>
-
secureBuilder(String, String)
instead to create a secureCookie
.