Class ResponseCookie
java.lang.Object
com.soklet.core.ResponseCookie
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
Builder used to copy instances ofResponseCookie
viacopy()
.static enum
Values which control whether or not a response cookie is sent with cross-site requests, providing some protection against cross-site request forgery attacks (CSRF). -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Vends a mutable copier seeded with this instance's data, suitable for building new instances.boolean
static Optional
<ResponseCookie> fromSetCookieHeaderRepresentation
(String setCookieHeaderRepresentation) Given aSet-Cookie
header representation, provide aResponseCookie
that matches it.Gets the cookie'sDomain
value, if present.Gets the cookie'sHttpOnly
flag, if present.Gets the cookie'sMax-Age
value expressed as aDuration
, if present.getName()
Gets the cookie's name.getPath()
Gets the cookie'sPath
value, if present.Gets the cookie'sSameSite
value, if present.Gets the cookie'sSecure
flag, if present.getValue()
Gets the cookie's value, if present.int
hashCode()
Generates aSet-Cookie
header representation of this response cookie, for exampleSet-Cookie: <cookie-name>=<cookie-value>; Domain=<domain-value>; Secure; HttpOnly
toString()
static ResponseCookie.Builder
Acquires a builder forResponseCookie
instances.static ResponseCookie.Builder
Acquires a builder forResponseCookie
instances without specifying the cookie's value.
-
Method Details
-
with
Acquires a builder forResponseCookie
instances.- Parameters:
name
- the cookie namevalue
- the cookie value- Returns:
- the builder
-
withName
Acquires a builder forResponseCookie
instances without specifying the cookie's value.- Parameters:
name
- the cookie name- Returns:
- the builder
-
copy
Vends a mutable copier seeded with this instance's data, suitable for building new instances.- Returns:
- a copier for this instance
-
fromSetCookieHeaderRepresentation
@Nonnull public static Optional<ResponseCookie> fromSetCookieHeaderRepresentation(@Nullable String setCookieHeaderRepresentation) Given aSet-Cookie
header representation, provide aResponseCookie
that matches it.An example of a
Set-Cookie
header representation isSet-Cookie: <cookie-name>=<cookie-value>; Domain=<domain-value>; Secure; HttpOnly
Note: while the spec does not forbid multiple cookie name/value pairs to be specified in the same
Set-Cookie
header, this format is unusual - Soklet does not currently support parsing these kinds of cookies.See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie for details.
- Parameters:
setCookieHeaderRepresentation
- aSet-Cookie
header representation- Returns:
- a
ResponseCookie
representation of theSet-Cookie
header, orOptional.empty()
if the header is null, empty, or does not include cookie data - Throws:
IllegalArgumentException
- if theSet-Cookie
header representation is malformed
-
toSetCookieHeaderRepresentation
Generates aSet-Cookie
header representation of this response cookie, for exampleSet-Cookie: <cookie-name>=<cookie-value>; Domain=<domain-value>; Secure; HttpOnly
See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie for details.
- Returns:
- this response cookie in
Set-Cookie
header format
-
hashCode
-
equals
-
toString
-
getName
-
getValue
Gets the cookie's value, if present.- Returns:
- the value of the cookie, or
Optional.empty()
if there is none
-
getMaxAge
-
getDomain
Gets the cookie'sDomain
value, if present.- Returns:
- the
Domain
value of the cookie, orOptional.empty()
if there is none
-
getPath
Gets the cookie'sPath
value, if present.- Returns:
- the
Path
value of the cookie, orOptional.empty()
if there is none
-
getSecure
-
getHttpOnly
Gets the cookie'sHttpOnly
flag, if present.- Returns:
true
if theHttpOnly
flag of the cookie is present,false
otherwise
-
getSameSite
Gets the cookie'sSameSite
value, if present.- Returns:
- the
SameSite
value of the cookie, orOptional.empty()
if there is none
-