Top Description Inners Fields Methods
org.eclipse.jetty.http

public Interface HttpCookie

Known Direct Implementers
org.eclipse.jetty.http.HttpCookie.Wrapper, org.eclipse.jetty.http.HttpCookie.Immutable, org.eclipse.jetty.http.HttpCookie.JavaNetHttpCookie
Imports
java.time.Instant, .ZoneOffset, .ZonedDateTime, java.time.format.DateTimeFormatter, java.util.Collections, .Locale, .Map, .Objects, .TreeMap, org.eclipse.jetty.util.Index

Implementation of RFC6265 HTTP Cookies (with fallback support for RFC2965).

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
HttpCookie.Builder

A builder for HttpCookie instances.

public static class
HttpCookie.Immutable

Immutable implementation of HttpCookie.

public static class
public static enum
HttpCookie.SameSite

The possible values for the SameSite attribute, defined in the follow-up of RFC 6265, at the time of this writing defined at RFC 6265bis.

public static class
HttpCookie.Wrapper

A wrapper for HttpCookie instances.

Field Summary

Modifier and TypeField and Description
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String

Method Summary

Modifier and TypeMethod and Description
public static HttpCookie

Returns:

a new java.net.HttpCookie
asJavaNetHttpCookie
(HttpCookie
the cookie to convert
httpCookie
)

Converts a HttpCookie to a java.net.HttpCookie.

private static String
asString(HttpCookie httpCookie)

public static HttpCookie.Builder

Returns:

a new Builder initialized with the given values
build
(String
the cookie name
name
,
String
the cookie value
value
)

Creates a Builder to build a HttpCookie.

public static HttpCookie.Builder

Returns:

a new Builder initialized with the given values
build
(String
the cookie name
name
,
String
the cookie value
value
,
int
the cookie version
version
)

Creates a Builder to build a HttpCookie.

public static HttpCookie.Builder

Returns:

a new Builder initialized with the given cookie
build
(HttpCookie
the cookie to copy
httpCookie
)

Creates a Builder to build a HttpCookie.

public static HttpCookie.Builder

Returns:

a new Builder initialized with the given cookie
build
(HttpCookie httpCookie)

Creates a Builder to build a HttpCookie.

public boolean
equals(Object
the object to test for equality
obj
)

Returns: whether this cookie is equal to the given object

public static boolean

Returns:

whether the cookies are equal
equals
(HttpCookie
the first cookie to equal
cookie1
,
Object
the second cookie to equal
obj
)

Implementation of Object#equals(Object) compatible with RFC 6265.

private static boolean
public static String

Returns:

the instant formatted as an RFC 1123 string
formatExpires
(Instant
the expiration instant
expires
)

Formats the Instant associated with the Expires attribute into a RFC 1123 string.

public static HttpCookie
from(String
the name of the cookie
name
,
String
the value of the cookie
value
)

Creates a new HttpCookie from the given name and value.

public static HttpCookie
from(String
the name of the cookie
name
,
String
the value of the cookie
value
,
Map<String, String>
the map of attributes to use with this cookie (this map is used for field values such as getDomain(), getPath(), getMaxAge(), isHttpOnly(), isSecure(), isPartitioned(), getComment(), plus any newly defined attributes unknown to this code base.
attributes
)

Creates a new HttpCookie from the given name, value and attributes.

public static HttpCookie
from(String
the name of the cookie
name
,
String
the value of the cookie
value
,
int
the version of the cookie (only used in RFC2965 mode)
version
,
Map<String, String>
the map of attributes to use with this cookie (this map is used for field values such as getDomain(), getPath(), getMaxAge(), isHttpOnly(), isSecure(), isPartitioned(), getComment(), plus any newly defined attributes unknown to this code base.
attributes
)

Creates a new HttpCookie from the given name, value, version and attributes.

public static HttpCookie
from(HttpCookie
A cookie to base the new cookie on.
cookie
,
String...
Additional name value pairs of strings to use as additional attributes
additionalAttributes
)

Returns: A new cookie based on the passed cookie plus additional attributes.

public static HttpCookie

Returns:

a new HttpCookie copied from the java.net.HttpCookie
from
(HttpCookie
the java.net.HttpCookie instance to copy
httpCookie
)

Creates a new HttpCookie copied from the given java.net.HttpCookie.

public Map<String, String>
getAttributes()

Returns: the attributes associated with this cookie

public default String

Returns:

the value of the Comment attribute
getComment
()

Equivalent to getAttributes().get(COMMENT_ATTRIBUTE).

public default String

Returns:

the value of the Domain attribute
getDomain
()

Equivalent to getAttributes().get(DOMAIN_ATTRIBUTE).

public default Instant
getExpires()

Returns: the value of the Expires attribute, or null if not present

public default long
getMaxAge()

Returns: the value of the Max-Age attribute, in seconds, or -1 if not present

public String
getName()

Returns: the cookie name

public default String

Returns:

the value of the Path attribute
getPath
()

Equivalent to getAttributes().get(PATH_ATTRIBUTE).

public default HttpCookie.SameSite
getSameSite()

Returns: the value of the SameSite attribute

public String
getValue()

Returns: the cookie value

public int
getVersion()

Returns: the value of the Version attribute

public int
hashCode()

Returns: the cookie hash code

public static int

Returns:

the hash code of the cookie
hashCode
(HttpCookie
the cookie to be hashed
httpCookie
)

Implementation of Object#hashCode() compatible with RFC 6265.

public default boolean
isExpired()

Returns: whether the cookie is expired

public default boolean
isHttpOnly()

Returns: whether the HttpOnly attribute is present

public default boolean
isPartitioned()

Returns: whether the Partitioned attribute is present

public default boolean
isSecure()

Returns: whether the Secure attribute is present

private static Map<String, String>
lazyAttributePut(Map<String, String> attributes, String key, String value)

private static Map<String, String>
private static Map<String, String>
public static Instant

Returns:

an Instant parsed from the given string
parseExpires
(String
an instant in the RFC 1123 string format
expires
)

Parses the Expires attribute value (in RFC 1123 format) into an Instant.

public static String

Returns:

a logging string representation of the cookie
toString
(HttpCookie
the cookie to format
httpCookie
)

Formats this cookie into a string suitable to be used for logging.