NanoHttpd / nanohttpd

Tiny, easily embeddable HTTP server in Java.
http://nanohttpd.org
BSD 3-Clause "New" or "Revised" License
6.92k stars 1.69k forks source link

Cookies not working for complex path #495

Open donnadulcinea opened 6 years ago

donnadulcinea commented 6 years ago

While serving a page

(given a global _int counter;_)

if (uri.startsWith("/cookie_set")) {
    String c_name = "token";
    String c_value = "pippo" + counter++;
    session.getCookies().set(c_name, c_value, 1000);
    return newFixedLengthResponse("Cookie SET:" + c_name + "=" + c_value + ";");
}

if (uri.startsWith("/cookie_get/")) {
    String cookies[] = uri.split("/");
    String c_name = cookies[2];
    String c_value = session.getCookies().read(c_name);
    return newFixedLengthResponse("Cookie GET:" + c_name + "=" + c_value + ";");
}

While the /cookie_get/ works as expected, reading the parameter passed as a path element (e.g., /cookie_get/token read the cookie named token)

If the /cookie_set has a subpath, it doesn't work anymore. (e.g., /cookie_set correctly updated the token value, to pippo1, pippo2, ... /cookie_set/something doesn't work anymore, i.e., doesn't set the cookie.

I don't know where to look, seems like a bug to me.