Class HttpCookieStore.Default

java.lang.Object
org.eclipse.jetty.http.HttpCookieStore.Default
All Implemented Interfaces:
HttpCookieStore
Enclosing interface:
HttpCookieStore

public static class HttpCookieStore.Default extends Object implements HttpCookieStore

A default implementation of HttpCookieStore.

RFC 6265, section 5.2.2, states that negative values of the Max-Age attribute should be treated like `0`, which indicates that the cookie is expired. However, the de-facto standard for implementations (browsers and java.net.http.HttpClient) is that negative values are treated as "session cookie": a cookie that is not expired, but won't be persisted and will be removed when the browser or client is closed or stopped. This is in line with the javadocs of java.net.HttpCookie as well as jakarta.servlet.http.Cookie.

  • Constructor Details

    • Default

      public Default()
  • Method Details

    • add

      public boolean add(URI uri, HttpCookie cookie)
      Description copied from interface: HttpCookieStore

      Adds a cookie to this store, if possible.

      The cookie may not be added for various reasons; for example, it may be already expired, or its domain attribute does not match that of the URI, etc.

      The cookie is associated with the given URI, so that a call to HttpCookieStore.match(URI) returns the cookie only if the URIs match.

      Specified by:
      add in interface HttpCookieStore
      Parameters:
      uri - the URI associated with the cookie
      cookie - the cookie to add
      Returns:
      whether the cookie has been added
    • allowDomain

      protected boolean allowDomain(String domain)

      Returns whether the given domain should be allowed to associate cookies to.

      Currently rejects "top-level" domains such as "com" or "org", so that it will not be possible to associate cookies to those domains.

      Unfortunately, it allows for "top-level" domains that have multiple labels such as "co.uk" or "gov.au".

      RFC 6265 prohibits domains that are IP addresses, but this method supports them (both IPv4 and IPv6, the latter must be bracketed) for testing purposes.

      Parameters:
      domain - the domain to test
      Returns:
      whether the domain should be allowed to associate cookies to
    • all

      public List<HttpCookie> all()
      Specified by:
      all in interface HttpCookieStore
      Returns:
      all the cookies
    • match

      public List<HttpCookie> match(URI uri)
      Description copied from interface: HttpCookieStore

      Returns the cookies that match the given URI.

      Specified by:
      match in interface HttpCookieStore
      Parameters:
      uri - the URI to match against
      Returns:
      a list of cookies that match the given URI
    • remove

      public boolean remove(URI uri, HttpCookie cookie)
      Description copied from interface: HttpCookieStore

      Removes the cookie associated with the given URI.

      Specified by:
      remove in interface HttpCookieStore
      Parameters:
      uri - the URI associated with the cookie to remove
      cookie - the cookie to remove
      Returns:
      whether the cookie has been removed
    • clear

      public boolean clear()
      Description copied from interface: HttpCookieStore

      Removes all the cookies from this store.

      Specified by:
      clear in interface HttpCookieStore
      Returns:
      whether the store modified by this call