Class ResponseCookie
java.lang.Object
com.soklet.ResponseCookie
HTTP "response" Cookie representation which supports
Set-Cookie header encoding.
Threadsafe instances can be acquired via these builder factory methods:
with(String, String)(builder primed with name and value)withName(String)(builder primed with name only)
- Author:
- Mark Allen
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classstatic final classBuilder used to copy instances ofResponseCookieviacopy().static enumValues which control whether 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.booleanstatic Optional<ResponseCookie> fromSetCookieHeaderRepresentation(String setCookieHeaderRepresentation) Given aSet-Cookieheader representation, provide aResponseCookiethat matches it.Gets the cookie'sDomainvalue, if present.Gets the cookie'sHttpOnlyflag, if present.Gets the cookie'sMax-Agevalue expressed as aDuration, if present.getName()Gets the cookie's name.getPath()Gets the cookie'sPathvalue, if present.Gets the cookie'sSameSitevalue, if present.Gets the cookie'sSecureflag, if present.getValue()Gets the cookie's value, if present.inthashCode()Generates aSet-Cookieheader representation of this response cookie, for exampleSet-Cookie: <cookie-name>=<cookie-value>; Domain=<domain-value>; Secure; HttpOnlytoString()static ResponseCookie.BuilderAcquires a builder forResponseCookieinstances.static ResponseCookie.BuilderAcquires a builder forResponseCookieinstances without specifying the cookie's value.
-
Method Details
-
with
Acquires a builder forResponseCookieinstances.- Parameters:
name- the cookie namevalue- the cookie value- Returns:
- the builder
-
withName
Acquires a builder forResponseCookieinstances 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-Cookieheader representation, provide aResponseCookiethat matches it.An example of a
Set-Cookieheader representation isSet-Cookie: <cookie-name>=<cookie-value>; Domain=<domain-value>; Secure; HttpOnlyNote: while the spec does not forbid multiple cookie name/value pairs to be specified in the same
Set-Cookieheader, 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-Cookieheader representation- Returns:
- a
ResponseCookierepresentation of theSet-Cookieheader, orOptional.empty()if the header is null, empty, or does not include cookie data - Throws:
IllegalArgumentException- if theSet-Cookieheader representation is malformed
-
toSetCookieHeaderRepresentation
Generates aSet-Cookieheader representation of this response cookie, for exampleSet-Cookie: <cookie-name>=<cookie-value>; Domain=<domain-value>; Secure; HttpOnlySee https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie for details.
- Returns:
- this response cookie in
Set-Cookieheader 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'sDomainvalue, if present.- Returns:
- the
Domainvalue of the cookie, orOptional.empty()if there is none
-
getPath
Gets the cookie'sPathvalue, if present.- Returns:
- the
Pathvalue of the cookie, orOptional.empty()if there is none
-
getSecure
-
getHttpOnly
Gets the cookie'sHttpOnlyflag, if present.- Returns:
trueif theHttpOnlyflag of the cookie is present,falseotherwise
-
getSameSite
Gets the cookie'sSameSitevalue, if present.- Returns:
- the
SameSitevalue of the cookie, orOptional.empty()if there is none
-