Class CookieUtils


  • public final class CookieUtils
    extends Object
    A utility class for cookies.
    Author:
    Rob Spoor
    • Method Detail

      • findCookie

        public static Optional<Cookie> findCookie​(HttpServletRequest request,
                                                  String name)
        Tries to find a specific cookie in a request.
        Parameters:
        request - The request to find the cookie in.
        name - The name of the cookie to find. This is case sensitive.
        Returns:
        An Optional describing the cookie with the given name, or Optional.empty() if the request does not have such a cookie.
        Throws:
        NullPointerException - If the given request is null.
      • cookieStream

        public static Stream<Cookie> cookieStream​(HttpServletRequest request)
        Returns all cookies in a request as a stream.
        Parameters:
        request - The request to return all cookies of.
        Returns:
        A stream with all cookies in the given request; never null but possibly empty.
        Throws:
        NullPointerException - If the given request is null.