Class CookieStore

java.lang.Object
io.undertow.server.CookieStore
All Implemented Interfaces:
Iterable<Cookie>

public class CookieStore extends Object implements Iterable<Cookie>
A store for cookies indexed by the cookie name, allowing multiple cookies with the same name, but different path/domain combinations (RFC-2109 support).

Thread Safety: This class is NOT thread-safe by design. The HttpServerExchange guarantees only one thread accesses the exchange at a time.

Since:
2.4.0
Author:
James R. Perkins
  • Constructor Details

    • CookieStore

      public CookieStore()
      Creates a new cookie store.
  • Method Details

    • size

      public int size()
      Returns the size of the cookie store.
      Returns:
      the number of cookies in the store
    • isEmpty

      public boolean isEmpty()
      Checks if the store is empty.
      Returns:
      true if the store is empty, otherwise false
    • get

      public List<Cookie> get(String name)
      Returns an immutable list of all the cookies in this store with the given name.
      Parameters:
      name - the name of the cookie
      Returns:
      an immutable list of cookies or an empty list if no cookies were associated with the name
    • remove

      public boolean remove(Cookie cookie)
      Removes the cookie from the store if it exists.
      Parameters:
      cookie - the cookie to remove
      Returns:
      true if the cookie was removed, false if the cookie was not found and therefore not removed
    • add

      public CookieStore add(Cookie cookie)
      Adds a cookie to the store.
      Parameters:
      cookie - the cookie to add, passing null does nothing
      Returns:
      this cookie store
    • asLegacyMap

      @Deprecated(forRemoval=true, since="2.4.0") public Map<String,Cookie> asLegacyMap()
      Deprecated, for removal: This API element is subject to removal in a future version.
      This method exists for backward compatibility with the deprecated HttpServerExchange.getRequestCookies() and HttpServerExchange.getResponseCookies() methods. Use iterator() or get(String) instead.
      Returns the cookie store as a flat map, providing a single-valued view of the cookies.

      For cookies with identical name, path, and domain, only the most recently added cookie is included (duplicates are automatically replaced).

      For cookies with the same name but different path/domain combinations, only one arbitrary cookie with that name is returned. To access all cookies with the same name, use get(String) instead.

      Returns:
      a map where each cookie name maps to a single Cookie instance
    • iterator

      public Iterator<Cookie> iterator()
      The iterator returned is immutable.
      Specified by:
      iterator in interface Iterable<Cookie>
    • toString

      public String toString()
      Overrides:
      toString in class Object