Package org.eclipse.jetty.http
Interface HttpCookie
- All Known Implementing Classes:
HttpCookie.Immutable
,HttpCookie.JavaNetHttpCookie
,HttpCookie.Wrapper
public interface HttpCookie
Implementation of RFC6265 HTTP Cookies (with fallback support for RFC2965).
-
Nested Class Summary
Modifier and TypeInterfaceDescriptionstatic class
A builder forHttpCookie
instances.static class
Immutable implementation ofHttpCookie
.static class
AHttpCookie
that wraps aHttpCookie
.static enum
The possible values for theSameSite
attribute, defined in the follow-up of RFC 6265, at the time of this writing defined at RFC 6265bis.static class
A wrapper forHttpCookie
instances. -
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic HttpCookie
asJavaNetHttpCookie
(HttpCookie httpCookie) Converts aHttpCookie
to aHttpCookie
.static HttpCookie.Builder
Creates aHttpCookie.Builder
to build aHttpCookie
.static HttpCookie.Builder
Creates aHttpCookie.Builder
to build aHttpCookie
.static HttpCookie.Builder
build
(HttpCookie httpCookie) Creates aHttpCookie.Builder
to build aHttpCookie
.static HttpCookie.Builder
build
(HttpCookie httpCookie) Creates aHttpCookie.Builder
to build aHttpCookie
.boolean
static boolean
equals
(HttpCookie cookie1, Object obj) Implementation ofObject.equals(Object)
compatible with RFC 6265.static String
formatExpires
(Instant expires) Formats theInstant
associated with theExpires
attribute into a RFC 1123 string.static HttpCookie
Creates a newHttpCookie
from the given name and value.static HttpCookie
Creates a newHttpCookie
from the given name, value, version and attributes.static HttpCookie
Creates a newHttpCookie
from the given name, value and attributes.static HttpCookie
from
(HttpCookie httpCookie) Creates a newHttpCookie
copied from the givenHttpCookie
.static HttpCookie
from
(HttpCookie cookie, String... additionalAttributes) default String
Equivalent togetAttributes().get(COMMENT_ATTRIBUTE)
.default String
Equivalent togetAttributes().get(DOMAIN_ATTRIBUTE)
.default Instant
default long
getName()
default String
getPath()
Equivalent togetAttributes().get(PATH_ATTRIBUTE)
.default HttpCookie.SameSite
getValue()
int
int
hashCode()
static int
hashCode
(HttpCookie httpCookie) Implementation ofObject.hashCode()
compatible with RFC 6265.default boolean
default boolean
default boolean
default boolean
isSecure()
static Instant
parseExpires
(String expires) Parses theExpires
Date/Time attribute value into anInstant
.static String
toString
(HttpCookie httpCookie) Formats this cookie into a string suitable to be used for logging.
-
Field Details
-
COMMENT_ATTRIBUTE
- See Also:
-
DOMAIN_ATTRIBUTE
- See Also:
-
EXPIRES_ATTRIBUTE
- See Also:
-
HTTP_ONLY_ATTRIBUTE
- See Also:
-
MAX_AGE_ATTRIBUTE
- See Also:
-
PATH_ATTRIBUTE
- See Also:
-
SAME_SITE_ATTRIBUTE
- See Also:
-
SECURE_ATTRIBUTE
- See Also:
-
PARTITIONED_ATTRIBUTE
- See Also:
-
-
Method Details
-
getName
String getName()- Returns:
- the cookie name
-
getValue
String getValue()- Returns:
- the cookie value
-
getVersion
int getVersion()- Returns:
- the value of the
Version
attribute
-
getAttributes
- Returns:
- the attributes associated with this cookie
-
getExpires
- Returns:
- the value of the
Expires
attribute, ornull
if not present - See Also:
-
getMaxAge
default long getMaxAge()- Returns:
- the value of the
Max-Age
attribute, in seconds, or-1
if not present - See Also:
-
isExpired
default boolean isExpired()- Returns:
- whether the cookie is expired
-
getComment
Equivalent to
getAttributes().get(COMMENT_ATTRIBUTE)
.- Returns:
- the value of the
Comment
attribute - See Also:
-
getDomain
Equivalent to
getAttributes().get(DOMAIN_ATTRIBUTE)
.- Returns:
- the value of the
Domain
attribute - See Also:
-
getPath
Equivalent to
getAttributes().get(PATH_ATTRIBUTE)
.- Returns:
- the value of the
Path
attribute - See Also:
-
isSecure
default boolean isSecure()- Returns:
- whether the
Secure
attribute is present - See Also:
-
getSameSite
- Returns:
- the value of the
SameSite
attribute - See Also:
-
isHttpOnly
default boolean isHttpOnly()- Returns:
- whether the
HttpOnly
attribute is present - See Also:
-
isPartitioned
default boolean isPartitioned()- Returns:
- whether the
Partitioned
attribute is present - See Also:
-
hashCode
int hashCode() -
equals
-
from
Creates a newHttpCookie
from the given name and value.- Parameters:
name
- the name of the cookievalue
- the value of the cookie
-
from
Creates a newHttpCookie
from the given name, value and attributes.- Parameters:
name
- the name of the cookievalue
- the value of the cookieattributes
- the map of attributes to use with this cookie (this map is used for field values such asgetDomain()
,getPath()
,getMaxAge()
,isHttpOnly()
,isSecure()
,isPartitioned()
,getComment()
, plus any newly defined attributes unknown to this code base.
-
from
Creates a newHttpCookie
from the given name, value, version and attributes.- Parameters:
name
- the name of the cookievalue
- the value of the cookieversion
- the version of the cookie (only used in RFC2965 mode)attributes
- the map of attributes to use with this cookie (this map is used for field values such asgetDomain()
,getPath()
,getMaxAge()
,isHttpOnly()
,isSecure()
,isPartitioned()
,getComment()
, plus any newly defined attributes unknown to this code base.
-
from
- Parameters:
cookie
- A cookie to base the new cookie on.additionalAttributes
- Additional name value pairs of strings to use as additional attributes- Returns:
- A new cookie based on the passed cookie plus additional attributes.
-
from
Creates a newHttpCookie
copied from the givenHttpCookie
.- Parameters:
httpCookie
- theHttpCookie
instance to copy- Returns:
- a new
HttpCookie
copied from theHttpCookie
- See Also:
-
build
Creates aHttpCookie.Builder
to build aHttpCookie
.- Parameters:
name
- the cookie namevalue
- the cookie value- Returns:
- a new
HttpCookie.Builder
initialized with the given values
-
build
Creates aHttpCookie.Builder
to build aHttpCookie
.- Parameters:
name
- the cookie namevalue
- the cookie valueversion
- the cookie version- Returns:
- a new
HttpCookie.Builder
initialized with the given values
-
build
Creates aHttpCookie.Builder
to build aHttpCookie
.- Parameters:
httpCookie
- the cookie to copy- Returns:
- a new
HttpCookie.Builder
initialized with the given cookie
-
build
Creates aHttpCookie.Builder
to build aHttpCookie
.- Parameters:
httpCookie
- theHttpCookie
to copy- Returns:
- a new
HttpCookie.Builder
initialized with the given cookie
-
asJavaNetHttpCookie
Converts aHttpCookie
to aHttpCookie
.- Parameters:
httpCookie
- the cookie to convert- Returns:
- a new
HttpCookie
- See Also:
-
hashCode
Implementation of
Object.hashCode()
compatible with RFC 6265.- Parameters:
httpCookie
- the cookie to be hashed- Returns:
- the hash code of the cookie
- See Also:
-
equals
Implementation of
Object.equals(Object)
compatible with RFC 6265.Two cookies are equal if they have the same name (case-sensitive), the same domain (case-insensitive) and the same path (case-sensitive).
- Parameters:
cookie1
- the first cookie to equalobj
- the second cookie to equal- Returns:
- whether the cookies are equal
- See Also:
-
toString
Formats this cookie into a string suitable to be used for logging.
- Parameters:
httpCookie
- the cookie to format- Returns:
- a logging string representation of the cookie
-
formatExpires
Formats the
Instant
associated with theExpires
attribute into a RFC 1123 string.- Parameters:
expires
- the expiration instant- Returns:
- the instant formatted as an RFC 1123 string
- See Also:
-
parseExpires
Parses the
Expires
Date/Time attribute value into anInstant
.- Parameters:
expires
- a date/time in one of the RFC6265 supported formats- Returns:
- an
Instant
parsed from the given string
-