Package io.undertow.server
Class CookieStore
java.lang.Object
io.undertow.server.CookieStore
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a cookie to the store.Deprecated, for removal: This API element is subject to removal in a future version.Returns an immutable list of all the cookies in this store with the given name.booleanisEmpty()Checks if the store is empty.iterator()The iterator returned is immutable.booleanRemoves the cookie from the store if it exists.intsize()Returns the size of the cookie store.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
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:
trueif the store is empty, otherwisefalse
-
get
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
Removes the cookie from the store if it exists.- Parameters:
cookie- the cookie to remove- Returns:
trueif the cookie was removed,falseif the cookie was not found and therefore not removed
-
add
Adds a cookie to the store.- Parameters:
cookie- the cookie to add, passingnulldoes nothing- Returns:
- this cookie store
-
asLegacyMap
Deprecated, for removal: This API element is subject to removal in a future version.This method exists for backward compatibility with the deprecatedHttpServerExchange.getRequestCookies()andHttpServerExchange.getResponseCookies()methods. Useiterator()orget(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
The iterator returned is immutable. -
toString
-
HttpServerExchange.getRequestCookies()andHttpServerExchange.getResponseCookies()methods.