javacookiesplayframework-2.1

How to list cookies in Play


Using PlayFramework (in Java), I'd like to log the list of all cookies name Play can read.

I tried to call request().cookies() but it's not a List, it's an object, and there is no List in this object.

I can call request().cookie(String name); but this expect that I know the cookie's name, which I don't.

How can I do then ?


Solution

  • Here's a solution I just made, I don't know if it's the best, but it works :

    for (String cookieStr : request.headers().get("Cookie")) {
        String name = cookieStr.substring(0, cookieStr.indexOf("="));
    
        Logger.info("Name of the cookie : " + name);
    
        Cookie cookie = request.cookie(name); // Get the instance of the cookie !
    }