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).

  • Field Details

  • 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

      Map<String,String> getAttributes()
      Returns:
      the attributes associated with this cookie
    • getExpires

      default Instant getExpires()
      Returns:
      the value of the Expires attribute, or null 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

      default String getComment()

      Equivalent to getAttributes().get(COMMENT_ATTRIBUTE).

      Returns:
      the value of the Comment attribute
      See Also:
    • getDomain

      default String getDomain()

      Equivalent to getAttributes().get(DOMAIN_ATTRIBUTE).

      Returns:
      the value of the Domain attribute
      See Also:
    • getPath

      default String 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

      default HttpCookie.SameSite 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()
      Overrides:
      hashCode in class Object
      Returns:
      the cookie hash code
      See Also:
    • equals

      boolean equals(Object obj)
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to test for equality
      Returns:
      whether this cookie is equal to the given object
      See Also:
    • from

      static HttpCookie from(String name, String value)
      Creates a new HttpCookie from the given name and value.
      Parameters:
      name - the name of the cookie
      value - the value of the cookie
    • from

      static HttpCookie from(String name, String value, Map<String,String> attributes)
      Creates a new HttpCookie from the given name, value and attributes.
      Parameters:
      name - the name of the cookie
      value - the value of the cookie
      attributes - 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.
    • from

      static HttpCookie from(String name, String value, int version, Map<String,String> attributes)
      Creates a new HttpCookie from the given name, value, version and attributes.
      Parameters:
      name - the name of the cookie
      value - the value of the cookie
      version - 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 as getDomain(), getPath(), getMaxAge(), isHttpOnly(), isSecure(), isPartitioned(), getComment(), plus any newly defined attributes unknown to this code base.
    • from

      static HttpCookie from(HttpCookie cookie, String... additionalAttributes)
      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

      static HttpCookie from(HttpCookie httpCookie)
      Creates a new HttpCookie copied from the given HttpCookie.
      Parameters:
      httpCookie - the HttpCookie instance to copy
      Returns:
      a new HttpCookie copied from the HttpCookie
      See Also:
    • build

      static HttpCookie.Builder build(String name, String value)
      Creates a HttpCookie.Builder to build a HttpCookie.
      Parameters:
      name - the cookie name
      value - the cookie value
      Returns:
      a new HttpCookie.Builder initialized with the given values
    • build

      static HttpCookie.Builder build(String name, String value, int version)
      Creates a HttpCookie.Builder to build a HttpCookie.
      Parameters:
      name - the cookie name
      value - the cookie value
      version - the cookie version
      Returns:
      a new HttpCookie.Builder initialized with the given values
    • build

      static HttpCookie.Builder build(HttpCookie httpCookie)
      Creates a HttpCookie.Builder to build a HttpCookie.
      Parameters:
      httpCookie - the cookie to copy
      Returns:
      a new HttpCookie.Builder initialized with the given cookie
    • build

      static HttpCookie.Builder build(HttpCookie httpCookie)
      Creates a HttpCookie.Builder to build a HttpCookie.
      Parameters:
      httpCookie - the HttpCookie to copy
      Returns:
      a new HttpCookie.Builder initialized with the given cookie
    • asJavaNetHttpCookie

      static HttpCookie asJavaNetHttpCookie(HttpCookie httpCookie)
      Converts a HttpCookie to a HttpCookie.
      Parameters:
      httpCookie - the cookie to convert
      Returns:
      a new HttpCookie
      See Also:
    • hashCode

      static int hashCode(HttpCookie httpCookie)

      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

      static boolean equals(HttpCookie cookie1, Object obj)

      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 equal
      obj - the second cookie to equal
      Returns:
      whether the cookies are equal
      See Also:
    • toString

      static String toString(HttpCookie httpCookie)

      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

      static String formatExpires(Instant expires)

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

      Parameters:
      expires - the expiration instant
      Returns:
      the instant formatted as an RFC 1123 string
      See Also:
    • parseExpires

      static Instant parseExpires(String expires)

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

      Parameters:
      expires - an instant in the RFC 1123 string format
      Returns:
      an Instant parsed from the given string