sclass ServeHttp_CookieHandler { // TODO: path, domain int days = 365; S cookieName = "cookie"; bool verbose; S cookieValue; // returns cookie (may be empty if client doesn't accept cookies) S handle() { NanoHTTPD.IHTTPSession session = NanoHTTPD.currentSession.get(); if (session == null) null; NanoHTTPD.CookieHandler cookies = session.getCookies(); if (empty(cookieValue)) cookieValue = cookies.read("cookie"); if (empty(cookieValue) && empty((S) mapGet(getHttpdHeaders(), "x-no-cookies"))) { cookieValue = randomID(20); if (verbose) print("New cookie."); } if (verbose) print("Cookie: " + cookieValue); if (nempty(cookieValue)) cookies.set("cookie", cookieValue, days); ret cookieValue; } }